Changeset 8382 for trunk/src/comctl32


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

merge with latest Wine

Location:
trunk/src/comctl32
Files:
4 added
3 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comctl32/CCBase.cpp

    r3410 r8382  
    1 /* $Id: CCBase.cpp,v 1.9 2000-04-16 18:52:38 cbratschi Exp $ */
     1/* $Id: CCBase.cpp,v 1.10 2002-05-08 11:24:58 sandervl Exp $ */
    22/*
    33 * COMCTL32 Base Functions and Macros for all Controls
     
    77 * parts from WINE code
    88 */
     9#include <winuser.h>
    910#include <string.h>
    1011#include <wcstr.h>
    1112#include "winbase.h"
    1213#include "comctl32.h"
     14#include <commctrl.h>
    1315#include "ccbase.h"
    1416
  • trunk/src/comctl32/LICENSE.TXT

    r6380 r8382  
    1 $Id: LICENSE.TXT,v 1.2 2001-07-21 09:07:16 sandervl Exp $
    2 @c This is an additional Odin license agreement.
    3 @c It supercedes the main Odin license, but is only valid in
    4 @c the source directory in which it is present.
     1$Id: LICENSE.TXT,v 1.3 2002-05-08 11:24:58 sandervl Exp $
     2This is an additional Odin license agreement.
     3It supercedes the main Odin license, but is only valid in
     4the source directory in which it is present.
    55
    6 @c This file is processed by GNU's TeXinfo
    7 @c If you modify it or move it to another location, make sure that
    8 @c TeXinfo works (type `make' in directory documentation).
    9 
    10 Copyright (c) 1993-2000 the Wine project authors (see the file AUTHORS
     6Copyright (c) 1993-2002 the Wine project authors (see the file AUTHORS
    117for a complete list)
    128
    13 Permission is hereby granted, free of charge, to any person obtaining a copy
    14 of this software and associated documentation files (the "Software"), to deal
    15 in the Software without restriction, including without limitation the rights
    16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    17 copies of the Software, and to permit persons to whom the Software is
    18 furnished to do so, subject to the following conditions:
     9Wine is free software; you can redistribute it and/or modify it under
     10the terms of the GNU Lesser General Public License as published by the
     11Free Software Foundation; either version 2.1 of the License, or (at
     12your option) any later version.
    1913
    20 The above copyright notice and this permission notice shall be included in
    21 all copies or substantial portions of the Software.
     14This program is distributed in the hope that it will be useful, but
     15WITHOUT ANY WARRANTY; without even the implied warranty of
     16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17Lesser General Public License for more details.
    2218
    23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    26 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
    27 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    28 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     19A copy of the GNU Lesser General Public License is included in the
     20Wine distribution in the file COPYING.LIB. If you did not receive this
     21copy, write to the Free Software Foundation, Inc., 59 Temple Place,
     22Suite 330, Boston, MA 02111-1307 USA.
  • trunk/src/comctl32/animate.c

    r6709 r8382  
    55 * Copyright 1998, 1999 Eric Kohl
    66 *                 1999 Eric Pouech
     7 *
     8 * This library is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * This library is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with this library; if not, write to the Free Software
     20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    721 *
    822 * NOTES
     
    2034#include "vfw.h"
    2135#include "mmsystem.h"
    22 #include "debugtools.h"
     36#include "wine/debug.h"
     37
     38WINE_DEFAULT_DEBUG_CHANNEL(animate);
     39
     40static struct {
     41    HMODULE     hModule;
    2342#ifdef __WIN32OS2__
    24 #include "ccbase.h"
     43    HIC         (* WINAPI fnICOpen)(DWORD, DWORD, UINT);
     44    LRESULT     (* WINAPI fnICClose)(HIC);
     45    LRESULT     (* WINAPI fnICSendMessage)(HIC, UINT, DWORD, DWORD);
     46    DWORD       (* WINAPIV fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
     47#else
     48    HIC         (WINAPI *fnICOpen)(DWORD, DWORD, UINT);
     49    LRESULT     (WINAPI *fnICClose)(HIC);
     50    LRESULT     (WINAPI *fnICSendMessage)(HIC, UINT, DWORD, DWORD);
     51    DWORD       (WINAPIV *fnICDecompress)(HIC,DWORD,LPBITMAPINFOHEADER,LPVOID,LPBITMAPINFOHEADER,LPVOID);
    2552#endif
    26 
    27 DEFAULT_DEBUG_CHANNEL(animate);
     53} fnIC;
    2854
    2955typedef struct
    3056{
    31 #ifdef __WIN32OS2__
    32    COMCTL32_HEADER      header;
    33 #endif
    3457   /* reference to input stream (file or resource) */
    3558   HGLOBAL              hRes;
     
    7194}
    7295
    73 #ifdef __WIN32OS2__
    74 static BOOL ANIMATE_LoadRes(ANIMATE_INFO *infoPtr,HINSTANCE hInst,LPWSTR lpName,BOOL unicode)
    75 #else
    7696static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
    77 #endif
    7897{
    7998    HRSRC       hrsrc;
     
    81100    LPVOID      lpAvi;
    82101   
    83 #ifdef __WIN32OS2__
    84     if (unicode)
    85       hrsrc = FindResourceW(hInst,lpName,(LPWSTR)L"AVI");
    86     else
    87       hrsrc = FindResourceA(hInst,(LPCSTR)lpName,"AVI");
    88 #else
    89102    hrsrc = FindResourceA(hInst, lpName, "AVI");
    90 #endif
    91103    if (!hrsrc)
    92104        return FALSE;
     
    114126
    115127
    116 #ifdef __WIN32OS2__
    117 static BOOL ANIMATE_LoadFile(ANIMATE_INFO *infoPtr,LPWSTR lpName,BOOL unicode)
    118 #else
    119128static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
    120 #endif
    121 {
    122 #ifdef __WIN32OS2__
    123     if (unicode)
    124       infoPtr->hMMio = mmioOpenW(lpName,NULL,MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
    125     else
    126       infoPtr->hMMio = mmioOpenA((LPSTR)lpName,NULL,MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
    127 #else
     129{
    128130    infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
    129131                               MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
    130 #endif
     132   
    131133    if (!infoPtr->hMMio)
    132134        return FALSE;
     
    174176        }
    175177        if (infoPtr->hic) {
    176             ICClose(infoPtr->hic);
     178            fnIC.fnICClose(infoPtr->hic);
    177179            infoPtr->hic = 0;
    178180        }
     
    348350   
    349351    if (infoPtr->hic &&
    350         ICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
     352        fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
    351353                     infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
    352354        LeaveCriticalSection(&infoPtr->cs);
     
    636638    /* check uncompressed AVI */
    637639    if ((infoPtr->ash.fccHandler == mmioFOURCC('D', 'I', 'B', ' ')) ||
    638        (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')))
     640       (infoPtr->ash.fccHandler == mmioFOURCC('R', 'L', 'E', ' ')) ||
     641       (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0)))
    639642    {
    640643        infoPtr->hic = 0;             
     
    643646
    644647    /* try to get a decompressor for that type */
    645     infoPtr->hic = ICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
     648    infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
    646649    if (!infoPtr->hic) {
    647650        WARN("Can't load codec for the file\n");
     
    649652    }
    650653   
    651     outSize = ICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
     654    outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
    652655                            (DWORD)infoPtr->inbih, 0L);
    653656
     
    658661    }
    659662
    660     if (ICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
     663    if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
    661664                      (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
    662665        WARN("Can't get output BIH\n");
     
    670673    }
    671674
    672     if (ICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
     675    if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
    673676                      (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
    674677        WARN("Can't begin decompression\n");
     
    679682}
    680683
    681 #ifdef __WIN32OS2__
    682 static LRESULT ANIMATE_Open(HWND hWnd, WPARAM wParam, LPARAM lParam,BOOL unicode)
    683 #else
    684684static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
    685 #endif
    686685{
    687686    ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
     
    689688
    690689    ANIMATE_Free(infoPtr);
     690    infoPtr->hWnd = hWnd;
    691691
    692692    if (!lParam) {
     
    698698       hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);
    699699
    700 #ifdef __WIN32OS2__
    701     if (HIWORD(lParam)) {
    702         //TRACE("(\"%s\");\n", (LPSTR)lParam);
    703 
    704         if (!ANIMATE_LoadRes(infoPtr, hInstance, (LPWSTR)lParam,unicode)) {
    705             TRACE("No AVI resource found!\n");
    706             if (!ANIMATE_LoadFile(infoPtr, (LPWSTR)lParam,unicode)) {
    707                 WARN("No AVI file found!\n");
    708                 return FALSE;
    709             }
    710         }
    711     } else {
    712         //TRACE("(%u);\n", (WORD)LOWORD(lParam));
    713 
    714         if (!ANIMATE_LoadRes(infoPtr,hInstance,unicode ? MAKEINTRESOURCEW((INT)lParam):(LPWSTR)MAKEINTRESOURCEA((INT)lParam),unicode)) {
    715             WARN("No AVI resource found!\n");
    716             return FALSE;
    717         }
    718     }
    719 #else
    720700    if (HIWORD(lParam)) {
    721701        TRACE("(\"%s\");\n", (LPSTR)lParam);
     
    737717        }
    738718    }
    739 #endif
     719
    740720    if (!ANIMATE_GetAviInfo(infoPtr)) {
    741721        WARN("Can't get AVI information\n");
     
    782762    ANIMATE_INFO*       infoPtr;
    783763
     764    if (!fnIC.hModule) /* FIXME: not thread safe */
     765    {
     766        /* since there's a circular dep between msvfw32 and comctl32, we could either:
     767         * - fix the build chain to allow this circular dep
     768         * - handle it by hand
     769         * AJ wants the latter :-(
     770         */
     771        fnIC.hModule = LoadLibraryA("msvfw32.dll");
     772        if (!fnIC.hModule) return FALSE;
     773
     774        fnIC.fnICOpen        = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
     775        fnIC.fnICClose       = (void*)GetProcAddress(fnIC.hModule, "ICClose");
     776        fnIC.fnICSendMessage = (void*)GetProcAddress(fnIC.hModule, "ICSendMessage");
     777        fnIC.fnICDecompress  = (void*)GetProcAddress(fnIC.hModule, "ICDecompress");
     778    }
     779
    784780    /* allocate memory for info structure */
    785 #ifdef __WIN32OS2__
    786     infoPtr = (ANIMATE_INFO*)initControl(hWnd,sizeof(ANIMATE_INFO));
    787 #else
    788781    infoPtr = (ANIMATE_INFO *)COMCTL32_Alloc(sizeof(ANIMATE_INFO));
    789 #endif
    790782    if (!infoPtr) {
    791783        ERR("could not allocate info memory!\n");
     
    854846    switch (uMsg)
    855847    {
    856 #ifdef __WIN32OS2__
    857     case ACM_OPENA:
    858         return ANIMATE_Open(hWnd,wParam,lParam,FALSE);
    859 
    860     case ACM_OPENW:
    861         return ANIMATE_Open(hWnd,wParam,lParam,TRUE);
    862 #else
    863848    case ACM_OPENA:
    864849        return ANIMATE_OpenA(hWnd, wParam, lParam);
     
    866851        /*      case ACM_OPEN32W: FIXME!! */
    867852        /*          return ANIMATE_Open32W(hWnd, wParam, lParam); */
    868 #endif
    869853       
    870854    case ACM_PLAY:
     
    944928            ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
    945929       
    946 #ifdef __WIN32OS2__
    947         return defComCtl32ProcA (hWnd, uMsg, wParam, lParam);
    948 #else
    949930        return DefWindowProcA(hWnd, uMsg, wParam, lParam);
    950 #endif
    951931    }
    952932    return 0;
    953933}
    954 
    955934
    956935void ANIMATE_Register(void)
  • trunk/src/comctl32/comboex.c

    r7815 r8382  
    11/*
    2  * TODO   <-------------
    3  *  1. The following extended styles need to be implemented, use will
    4  *     result in a FIXME:
    5  *           CBES_EX_NOEDITIMAGEINDENT
     2 * ComboBoxEx control
     3 *
     4 * Copyright 1998, 1999 Eric Kohl
     5 * Copyright 2000, 2001, 2002 Guy Albertelli <galberte@neo.lrun.com>
     6 * Copyright 2002 Dimitrie O. Paun
     7 *
     8 * This library is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * This library is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with this library; if not, write to the Free Software
     20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     21 *
     22 * FIXME:
     23 *  1. Implement following extended styles:
    624 *           CBES_EX_PATHWORDBREAKPROC
    725 *           CBES_EX_NOSIZELIMIT
    826 *           CBES_EX_CASESENSITIVE
    9  *  2. None of the following callback items are implemented. Therefor
    10  *     no CBEN_GETDISPINFO notifies are issued. Use in either CBEM_INSERTITEM
    11  *     or CBEM_SETITEM will result in a FIXME:
    12  *           LPSTR_TEXTCALLBACK
    13  *           I_IMAGECALLBACK
    14  *           I_INDENTCALLBACK
    15  *  3. No use is made of the iOverlay image.
    16  *  4. Notify CBEN_DRAGBEGIN is not implemented.
    17  */
    18 
    19 
    20 /*
    21  * ComboBoxEx control v2 (mod6)
    22  *
    23  * Copyright 1998, 1999 Eric Kohl
    24  *
    25  * NOTES
    26  *   This is just a dummy control. An author is needed! Any volunteers?
    27  *   I will only improve this control once in a while.
    28  *     Eric <ekohl@abo.rhein-zeitung.de>
    29  *
    30 
    31  * Changes  Guy Albertelli <galberte@neo.lrun.com>
    32  * v1  Implemented messages: CB_SETITEMHEIGHT, WM_WINDOWPOSCHANGING,
    33  *      WM_DRAWITEM, and WM_MEASUREITEM. Fixed WM_CREATE. Fixed height
    34  *      of window rect reported fixing rebar control.
    35  * v2
    36  *   1. Rewrite of WM_Create for own created EDIT control. Also try to
    37  *      generate message sequence similar to native DLL.
    38  *   2. Handle case where CBEM_SETITEM is called to display data in EDIT
    39  *      Control.
    40  *   3. Add override for WNDPROC for the EDIT control (reqed for VK_RETURN).
    41  *   4. Dump input data for things using COMBOBOXEXITEM{A|W}.
    42  *   5. Handle positioning EDIT control based on whether icon present.
    43  *   6. Make InsertItemA use InsertItemW, and store all data in ..W form.
    44  *   7. Implement CBEM_DELETEITEM, CBEM_GETITEM{A|W}, CB_SETCURSEL,
    45  *      CBEM_{GET|SET}UNICODEFORMAT.
    46  *   8. Add override for WNDPROC for the COMBO control.
    47  *   9. Support extended style CBES_EX_NOEDITIMAGE and warn others are not
    48  *      supported.
    49  *  10. Implement CB_FINDSTRINGEXACT in both the Combo and ComboEx window
    50  *      procs to match the items. This eliminates dup entries in the listbox.
    51  *
    52  *  mod 4
    53  *   1. Implemented CBN_SELCHANGE, CBN_KILLFOCUS, and CBN_SELENDOK.
    54  *   2. Fix putting text in CBEN_ENDEDIT notifies for CBN_DROPDOWN case.
    55  *   3. Lock image selected status to focus state of edit control if
    56  *      edit control exists. Mimics native actions.
    57  *   4. Implemented WM_SETFOCUS in EditWndProc to track status of
    58  *      focus for 3 above.
    59  *   5. The LBN_SELCHANGE is just for documentation purposes.
    60  *
    61  *  mod 5
    62  *   1. Add support for CB_GETITEMDATA to a Comboex. Returns the LPARAM
    63  *      passed during insert of item.
    64  *   2. Remember selected item and don't issue CB_SETCURSEL unless needed.
    65  *   3. Add initial support for WM_NCCREATE to remove unwanted window styles
    66  *      (Currently just WS_VSCROLL and WS_HSCROLL, but probably should be
    67  *       more.)
    68  *   4. Improve some traces.
    69  *   5. Add support for CB_SETITEMDATA sets LPARAM value from item.
    70  *
    71  *  mod 6
    72  *   1. Add support for WM_NOTIFYFORMAT (both incoming and outgoing) and do
    73  *      WM_NOTIFY correctly based on results.
    74  *   2. Fix memory leaks of text strings in COMBOEX_WM_DELETEITEM.
    75  *   3. Add routines to handle special cases of NMCBEENDEDIT and NMCOMBOXEX
    76  *      so translation to ANSI is done correctly.
    77  *   4. Fix some issues with COMBOEX_DrawItem.
    78  *
    79  * Test vehicals were the ControlSpy modules (rebar.exe and comboboxex.exe),
    80  *  WinRAR, and IE 4.0.
     27 *  2. Notify CBEN_DRAGBEGIN is not implemented.
    8128 *
    8229 */
     
    8532#include "winbase.h"
    8633#include "commctrl.h"
    87 #include "debugtools.h"
     34#include "wine/debug.h"
    8835#include "wine/unicode.h"
    8936
    90 DEFAULT_DEBUG_CHANNEL(comboex);
    91 /*
    92  * The following is necessary for the test done in COMBOEX_DrawItem
    93  * to determine whether to dump out the DRAWITEM structure or not.
    94  */
    95 DECLARE_DEBUG_CHANNEL(message);
     37WINE_DEFAULT_DEBUG_CHANNEL(comboex);
    9638
    9739/* Item structure */
     
    10143    UINT         mask;
    10244    LPWSTR       pszText;
     45    LPWSTR       pszTemp;
    10346    int          cchTextMax;
    10447    int          iImage;
     
    11760    HWND         hwndEdit;
    11861    WNDPROC      prevEditWndProc;  /* previous Edit WNDPROC value */
    119     WNDPROC      prevComboWndProc;   /* previous Combo WNDPROC value */
     62    WNDPROC      prevComboWndProc; /* previous Combo WNDPROC value */
    12063    DWORD        dwExtStyle;
    12164    INT          selected;         /* index of selected item */
    12265    DWORD        flags;            /* WINE internal flags */
    123     HFONT        hDefaultFont;
     66    HFONT        defaultFont;
    12467    HFONT        font;
    12568    INT          nb_items;         /* Number of items */
    126     BOOL         bUnicode;        /* TRUE if this window is Unicode   */
    127     BOOL         NtfUnicode;      /* TRUE if parent wants notify in Unicode */
     69    BOOL         unicode;          /* TRUE if this window is Unicode   */
     70    BOOL         NtfUnicode;       /* TRUE if parent wants notify in Unicode */
    12871    CBE_ITEMDATA *edit;            /* item data for edit item */
    12972    CBE_ITEMDATA *items;           /* Array of items */
     
    13174
    13275/* internal flags in the COMBOEX_INFO structure */
    133 #define  WCBE_ACTEDIT        0x00000001     /* Edit active i.e.
     76#define  WCBE_ACTEDIT           0x00000001     /* Edit active i.e.
    13477                                             * CBEN_BEGINEDIT issued
    13578                                             * but CBEN_ENDEDIT{A|W}
    13679                                             * not yet issued. */
    137 #define  WCBE_EDITCHG        0x00000002     /* Edit issued EN_CHANGE */
    138 #define  WCBE_EDITFOCUSED    0x00000004     /* Edit control has focus */
    139 
    140 
    141 #define ID_CB_EDIT    1001
     80#define  WCBE_EDITCHG           0x00000002     /* Edit issued EN_CHANGE */
     81#define  WCBE_EDITHASCHANGED    (WCBE_ACTEDIT | WCBE_EDITCHG)
     82#define  WCBE_EDITFOCUSED       0x00000004     /* Edit control has focus */
     83
     84
     85#define ID_CB_EDIT              1001
    14286
    14387
     
    15296 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
    15397 */
    154 #define ODS_COMBOEXLBOX  0x4000
     98#define ODS_COMBOEXLBOX         0x4000
    15599
    156100
    157101
    158102/* Height in pixels of control over the amount of the selected font */
    159 #define CBE_EXTRA     3
     103#define CBE_EXTRA               3
    160104
    161105/* Indent amount per MS documentation */
    162 #define CBE_INDENT    10
     106#define CBE_INDENT              10
    163107
    164108/* Offset in pixels from left side for start of image or text */
    165 #define CBE_STARTOFFSET   6
     109#define CBE_STARTOFFSET         6
    166110
    167111/* Offset between image and text */
    168 #define CBE_SEP   4
    169 
    170 #define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
     112#define CBE_SEP                 4
     113
     114#define COMBOEX_SUBCLASS_PROP   "CCComboEx32SubclassInfo"
     115#define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongW (hwnd, 0))
    171116
    172117
    173118/* Things common to the entire DLL */
    174 static ATOM ComboExInfo;
    175119static LRESULT WINAPI
    176120COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    177121static LRESULT WINAPI
    178122COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    179 
    180 static void
    181 COMBOEX_DumpItem (CBE_ITEMDATA *item)
    182 {
    183     if (TRACE_ON(comboex)){
    184       TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
    185             item, item->mask, item->pszText, item->cchTextMax,
    186             item->iImage);
    187       TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
    188             item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
    189       if ((item->mask & CBEIF_TEXT) && item->pszText)
    190           TRACE("item %p - pszText=%s\n",
    191                 item, debugstr_w((const WCHAR *)item->pszText));
    192     }
    193 }
    194 
    195 
    196 static void
    197 COMBOEX_DumpInput (COMBOBOXEXITEMA *input, BOOL true_for_w)
    198 {
    199     if (TRACE_ON(comboex)){
    200       TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
    201             input->mask, input->iItem, input->pszText, input->cchTextMax,
    202             input->iImage);
    203       if ((input->mask & CBEIF_TEXT) && input->pszText) {
    204           if (true_for_w)
    205               TRACE("input - pszText=<%s>\n",
    206                     debugstr_w((const WCHAR *)input->pszText));
    207           else
    208               TRACE("input - pszText=<%s>\n",
    209                     debugstr_a((const char *)input->pszText));
    210       }
    211       TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
    212             input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
    213     }
    214 }
    215 
    216 
    217 inline static LRESULT
    218 COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    219 {
    220     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    221 
    222     if (infoPtr->hwndCombo)   
    223         return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
    224 
    225     return 0;
    226 }
    227 
    228 
    229 static INT
    230 COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
    231 {
    232 
     123static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
     124
     125inline static BOOL is_textW(LPCWSTR str)
     126{
     127    return str && str != LPSTR_TEXTCALLBACKW;
     128}
     129
     130inline static BOOL is_textA(LPCSTR str)
     131{
     132    return str && str != LPSTR_TEXTCALLBACKA;
     133}
     134
     135inline static LPCSTR debugstr_txt(LPCWSTR str)
     136{
     137    if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
     138    return debugstr_w(str);
     139}
     140
     141static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
     142{
     143    TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
     144          item, item->mask, item->pszText, item->cchTextMax, item->iImage);
     145    TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
     146          item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
     147    if (item->mask & CBEIF_TEXT)
     148        TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
     149}
     150
     151
     152static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
     153{
     154    TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
     155          input->mask, input->iItem, input->pszText, input->cchTextMax,
     156          input->iImage);
     157    if (input->mask & CBEIF_TEXT)
     158        TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
     159    TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
     160          input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
     161}
     162
     163
     164inline static CBE_ITEMDATA *get_item_data(COMBOEX_INFO *infoPtr, INT index)
     165{
     166    return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
     167                                         (WPARAM)index, 0);
     168}
     169
     170
     171static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
     172{
    233173    hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
    234174    hdr->hwndFrom = infoPtr->hwndSelf;
     
    246186COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
    247187{
    248 
    249188    /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
    250 
    251     hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
    252     hdr->hdr.hwndFrom = infoPtr->hwndSelf;
    253     hdr->hdr.code = code;
    254189    if (infoPtr->NtfUnicode)
    255         return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
    256                              (LPARAM)hdr);
     190        return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
    257191    else {
    258         LPWSTR str, ostr = NULL;
     192        LPWSTR wstr = hdr->ceItem.pszText;
     193        LPSTR astr = 0;
    259194        INT ret, len = 0;
    260195
    261         if (hdr->ceItem.mask & CBEIF_TEXT) {
    262             ostr = hdr->ceItem.pszText;
    263             str = ostr;
    264             if (!str) str = (LPWSTR)L"";
    265             len = WideCharToMultiByte (CP_ACP, 0, str, -1, 0, 0, NULL, NULL);
     196        if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
     197            len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
    266198            if (len > 0) {
    267                 hdr->ceItem.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
    268                 WideCharToMultiByte (CP_ACP, 0, str, -1, (LPSTR)hdr->ceItem.pszText,
    269                                      len, NULL, NULL);
     199                astr = (LPSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
     200                if (!astr) return 0;
     201                WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
     202                hdr->ceItem.pszText = (LPWSTR)astr;
    270203            }
    271204        }
    272205
    273         ret = SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
    274                             (LPARAM)hdr);
    275         if (hdr->ceItem.mask & CBEIF_TEXT) {
    276             if (len > 0)
    277                 COMCTL32_Free (hdr->ceItem.pszText);
    278             hdr->ceItem.pszText = ostr;
    279         }
     206        if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
     207        else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
     208        else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
     209       
     210        ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
     211
     212        if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
     213            hdr->ceItem.pszText = wstr;
     214       
     215        if (astr) COMCTL32_Free(astr);
     216       
    280217        return ret;
    281218    }
     
    283220
    284221
    285 static INT
    286 COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *hdr, LPWSTR itemText)
    287 {
    288 
     222static INT COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
     223{
    289224    /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
    290 
    291     hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
    292     hdr->hdr.hwndFrom = infoPtr->hwndSelf;
    293     hdr->hdr.code = (infoPtr->NtfUnicode) ? CBEN_ENDEDITW : CBEN_ENDEDITA;
    294     if (infoPtr->NtfUnicode)
    295         return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
    296                              (LPARAM)hdr);
    297     else {
    298         NMCBEENDEDITA ansi;
    299 
    300         memcpy (&ansi.hdr, &hdr->hdr, sizeof(NMHDR));
    301         ansi.fChanged = hdr->fChanged;
    302         ansi.iNewSelection = hdr->iNewSelection;
    303         WideCharToMultiByte (CP_ACP, 0, itemText, -1,
    304                              (LPSTR)&ansi.szText, CBEMAXSTRLEN, NULL, NULL);
    305         ansi.iWhy = hdr->iWhy;
    306         return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
    307                              (LPARAM)&ansi);
    308     }
    309 }
    310 
    311 
    312 static void
    313 COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
     225    if (infoPtr->NtfUnicode) {
     226        lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
     227        return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
     228    } else {
     229        NMCBEENDEDITA neea;
     230       
     231        memcpy (&neea.hdr, &neew->hdr, sizeof(NMHDR));
     232        neea.fChanged = neew->fChanged;
     233        neea.iNewSelection = neew->iNewSelection;
     234        WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
     235        neea.iWhy = neew->iWhy;
     236
     237        return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
     238    }
     239}
     240
     241
     242static void COMBOEX_FreeText (CBE_ITEMDATA *item)
     243{
     244    if (is_textW(item->pszText)) COMCTL32_Free(item->pszText);
     245    item->pszText = 0;
     246    if (item->pszTemp) COMCTL32_Free(item->pszTemp);
     247    item->pszTemp = 0;
     248}
     249
     250
     251static LPCWSTR COMBOEX_GetText(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
     252{
     253    NMCOMBOBOXEXW nmce;
     254    LPWSTR text, buf;
     255    INT len;
     256   
     257    if (item->pszText != LPSTR_TEXTCALLBACKW)
     258        return item->pszText;
     259   
     260    ZeroMemory(&nmce, sizeof(nmce));
     261    nmce.ceItem.mask = CBEIF_TEXT;
     262    COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
     263
     264    if (is_textW(nmce.ceItem.pszText)) {
     265        len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
     266        buf = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
     267        if (buf)
     268            MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
     269        if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
     270            COMBOEX_FreeText(item);
     271            item->pszText = buf;
     272        } else {
     273            if (item->pszTemp) COMCTL32_Free(item->pszTemp);
     274            item->pszTemp = buf;
     275        }
     276        text = buf;
     277    } else
     278        text = nmce.ceItem.pszText;
     279   
     280    if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
     281        item->pszText = text;
     282    return text;
     283}
     284
     285
     286static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
    314287{
    315288    HFONT nfont, ofont;
     
    326299
    327300
    328 static void
    329 COMBOEX_CopyItem (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
     301static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
    330302{
    331303    if (cit->mask & CBEIF_TEXT) {
    332         cit->pszText        = item->pszText;
    333         cit->cchTextMax     = item->cchTextMax;
     304        /*
     305         * when given a text buffer actually use that buffer
     306         */
     307        if (cit->pszText) {
     308            if (is_textW(item->pszText))
     309                lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
     310            else
     311                cit->pszText[0] = 0;
     312        } else {
     313            cit->pszText        = item->pszText;
     314            cit->cchTextMax     = item->cchTextMax;
     315        }
    334316    }
    335317    if (cit->mask & CBEIF_IMAGE)
     
    343325    if (cit->mask & CBEIF_LPARAM)
    344326        cit->lParam         = item->lParam;
    345 
    346 }
    347 
    348 
    349 static void
    350 COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
     327}
     328
     329
     330static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
    351331{
    352332    SIZE mysize;
    353     IMAGEINFO iinfo;
    354     INT x, y, w, h, xoff = 0;
     333    INT x, y, w, h, xioff;
    355334    RECT rect;
    356335
    357336    if (!infoPtr->hwndEdit) return;
    358     iinfo.rcImage.left = iinfo.rcImage.right = 0;
    359     if (infoPtr->himl) {
     337
     338    if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
     339        IMAGEINFO iinfo;
     340        iinfo.rcImage.left = iinfo.rcImage.right = 0;
    360341        ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
    361         xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
    362     }
     342        xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
     343    }  else xioff = 0;
     344
    363345    GetClientRect (infoPtr->hwndCombo, &rect);
    364346    InflateRect (&rect, -2, -2);
     
    368350    COMBOEX_GetComboFontSize (infoPtr, &mysize);
    369351    TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
    370     x = xoff + CBE_STARTOFFSET + 1;
    371     y = CBE_EXTRA + 1;
     352    x = xioff + CBE_STARTOFFSET + 1;
    372353    w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
    373354    h = mysize.cy + 1;
     355    y = rect.bottom - h - 1;
    374356
    375357    TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
    376           rect.left, rect.top, rect.right, rect.bottom,
    377           x, y, x + w, y + h);
    378     SetWindowPos(infoPtr->hwndEdit, HWND_TOP,
    379                  x, y,
    380                  w, h,
     358          rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
     359    SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
    381360                 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
    382361}
    383362
    384363
    385 static void
    386 COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
     364static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
    387365{
    388366    SIZE mysize;
     
    397375        TRACE("upgraded height due to image:  height=%d\n", cy);
    398376    }
    399     SendMessageW (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
     377    SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)cy);
    400378    if (infoPtr->hwndCombo)
    401379        SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
     
    404382
    405383
    406 static void
    407 COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
     384static void COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
    408385{
    409386    if (!infoPtr->hwndEdit) return;
     
    413390    /*      EM_SETSEL32 (0,-1)      */
    414391    if (item->mask & CBEIF_TEXT) {
    415         SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
     392        SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
    416393        SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
    417394        SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
     
    420397
    421398 
    422 static CBE_ITEMDATA *
    423 COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
     399static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
    424400{
    425401    CBE_ITEMDATA *item;
     
    439415    }
    440416    if (!item || (i != index)) {
    441         FIXME("COMBOBOXEX item structures broken. Please report!\n");
     417        ERR("COMBOBOXEX item structures broken. Please report!\n");
    442418        return 0;
    443419    }
     
    446422
    447423
    448 static void
    449 COMBOEX_WarnCallBack (CBE_ITEMDATA *item)
    450 {
    451     if (item->pszText == LPSTR_TEXTCALLBACKW)
    452         FIXME("Callback not implemented yet for pszText\n");
    453     if (item->iImage == I_IMAGECALLBACK)
    454         FIXME("Callback not implemented yet for iImage\n");
    455     if (item->iSelectedImage == I_IMAGECALLBACK)
    456         FIXME("Callback not implemented yet for iSelectedImage\n");
    457     if (item->iOverlay == I_IMAGECALLBACK)
    458         FIXME("Callback not implemented yet for iOverlay\n");
    459     if (item->iIndent == I_INDENTCALLBACK)
    460         FIXME("Callback not implemented yet for iIndent\n");
    461 }
    462 
     424static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO *infoPtr)
     425{
     426    return infoPtr->hwndEdit;
     427}
     428 
    463429
    464430/* ***  CBEM_xxx message support  *** */
    465431
    466432
    467 static LRESULT
    468 COMBOEX_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
    469 {
    470     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    471     INT index = (INT) wParam;
     433static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
     434{
    472435    CBE_ITEMDATA *item;
    473436
    474     TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
     437    TRACE("(index=%d)\n", index);
    475438
    476439    /* if item number requested does not exist then return failure */
    477     if ((index > infoPtr->nb_items) || (index < 0)) {
    478         ERR("attempt to delete item that does not exist\n");
    479         return CB_ERR;
    480     }
    481 
    482     if (!(item = COMBOEX_FindItem(infoPtr, index))) {
    483         ERR("attempt to delete item that was not found!\n");
    484         return CB_ERR;
    485     }
     440    if ((index > infoPtr->nb_items) || (index < 0)) return CB_ERR;
     441    if (!(item = COMBOEX_FindItem(infoPtr, index))) return CB_ERR;
    486442
    487443    /* doing this will result in WM_DELETEITEM being issued */
     
    492448
    493449
    494 inline static LRESULT
    495 COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
    496 {
    497     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    498 
    499     TRACE("\n");
    500 
    501     return (LRESULT)infoPtr->hwndCombo;
    502 }
    503 
    504 
    505 inline static LRESULT
    506 COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
    507 {
    508     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    509 
    510     if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
    511         return 0;
    512 
    513     TRACE("-- 0x%x\n", infoPtr->hwndEdit);
    514 
    515     return (LRESULT)infoPtr->hwndEdit;
    516 }
    517 
    518 
    519 inline static LRESULT
    520 COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
    521 {
    522     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    523 
    524     TRACE("-- 0x%08lx\n", infoPtr->dwExtStyle);
    525 
    526     return (LRESULT)infoPtr->dwExtStyle;
    527 }
    528 
    529 
    530 inline static LRESULT
    531 COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
    532 {
    533     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    534 
    535     TRACE("-- %p\n", infoPtr->himl);
    536 
    537     return (LRESULT)infoPtr->himl;
    538 }
    539 
    540 
    541 static LRESULT
    542 COMBOEX_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    543 {
    544     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    545     COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
    546     INT index;
     450static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
     451{
     452    INT index = cit->iItem;
    547453    CBE_ITEMDATA *item;
    548454
    549     TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
    550 
    551     /* get real index of item to insert */
    552     index = cit->iItem;
     455    TRACE("(...)\n");
    553456
    554457    /* if item number requested does not exist then return failure */
    555     if ((index > infoPtr->nb_items) || (index < -1)) {
    556         ERR("attempt to get item that does not exist\n");
    557         return 0;
    558     }
     458    if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
    559459
    560460    /* if the item is the edit control and there is no edit control, skip */
    561     if ((index == -1) &&
    562         ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
    563             return 0;
    564 
    565     if (!(item = COMBOEX_FindItem(infoPtr, index))) {
    566         ERR("attempt to get item that was not found!\n");
    567         return 0;
    568     }
    569 
    570     COMBOEX_CopyItem (infoPtr, item, cit);
     461    if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
     462
     463    if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
     464
     465    COMBOEX_CopyItem (item, cit);
    571466
    572467    return TRUE;
     
    574469
    575470
    576 inline static LRESULT
    577 COMBOEX_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
    578 {
    579     COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
     471static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
     472{
    580473    COMBOBOXEXITEMW tmpcit;
    581     INT len;
    582 
    583     TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
     474
     475    TRACE("(...)\n");
    584476
    585477    tmpcit.mask = cit->mask;
    586478    tmpcit.iItem = cit->iItem;
    587     COMBOEX_GetItemW (hwnd, wParam, (LPARAM) &tmpcit);
    588 
    589     len = WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1, 0, 0, NULL, NULL);
    590     if (len > 0)
    591         WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
     479    tmpcit.pszText = 0;
     480    if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
     481
     482    if (is_textW(tmpcit.pszText) && cit->pszText)
     483        WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
    592484                             cit->pszText, cit->cchTextMax, NULL, NULL);
     485    else if (cit->pszText) cit->pszText[0] = 0;
     486    else cit->pszText = (LPSTR)tmpcit.pszText;
    593487
    594488    cit->iImage = tmpcit.iImage;
     
    602496
    603497
    604 inline static LRESULT
    605 COMBOEX_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
    606 {
    607     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    608 
    609     TRACE("%s hwnd=0x%x\n",
    610            infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
    611 
    612     return infoPtr->bUnicode;
    613 }
    614 
    615 
    616 inline static LRESULT
    617 COMBOEX_HasEditChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
    618 {
    619     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    620 
    621     if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
    622         return FALSE;
    623     if ((infoPtr->flags & (WCBE_ACTEDIT | WCBE_EDITCHG)) ==
    624         (WCBE_ACTEDIT | WCBE_EDITCHG))
    625         return TRUE;
    626     return FALSE;
    627 }
    628 
    629 
    630 static LRESULT
    631 COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    632 {
    633     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    634     COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
     498inline static BOOL COMBOEX_HasEditChanged (COMBOEX_INFO *infoPtr)
     499{
     500    return COMBOEX_HasEdit(infoPtr) &&
     501           (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
     502}
     503
     504
     505static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
     506{
    635507    INT index;
    636508    CBE_ITEMDATA *item;
     
    639511    TRACE("\n");
    640512
    641     COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
     513    if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
    642514
    643515    /* get real index of item to insert */
     
    646518    if (index > infoPtr->nb_items) index = infoPtr->nb_items;
    647519
    648     /* get space and chain it in */
    649     item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
    650     item->next = NULL;
    651     item->pszText = NULL;
    652 
     520    /* get zero-filled space and chain it in */
     521    if(!(item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof(*item)))) return -1;
     522   
    653523    /* locate position to insert new item in */
    654524    if (index == infoPtr->nb_items) {
     
    666536        }
    667537        if (!moving) {
    668             FIXME("COMBOBOXEX item structures broken. Please report!\n");
     538            ERR("COMBOBOXEX item structures broken. Please report!\n");
    669539            COMCTL32_Free(item);
    670540            return -1;
     
    675545
    676546    /* fill in our hidden item structure */
    677     item->mask           = cit->mask;
     547    item->mask = cit->mask;
    678548    if (item->mask & CBEIF_TEXT) {
    679         LPWSTR str;
    680         INT len;
    681 
    682         str = cit->pszText;
    683         if (!str) str = (LPWSTR) L"";
    684         len = strlenW (str);
     549        INT len = 0;
     550
     551        if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
    685552        if (len > 0) {
    686553            item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
    687             strcpyW (item->pszText, str);
    688         }
    689         else
    690             item->pszText = NULL;
    691         item->cchTextMax   = cit->cchTextMax;
     554            if (!item->pszText) {
     555                COMCTL32_Free(item);
     556                return -1;
     557            }
     558            strcpyW (item->pszText, cit->pszText);
     559        }
     560        else if (cit->pszText == LPSTR_TEXTCALLBACKW)
     561            item->pszText = LPSTR_TEXTCALLBACKW;
     562        item->cchTextMax = cit->cchTextMax;
    692563    }
    693564    if (item->mask & CBEIF_IMAGE)
    694       item->iImage        = cit->iImage;
     565        item->iImage = cit->iImage;
    695566    if (item->mask & CBEIF_SELECTEDIMAGE)
    696       item->iSelectedImage = cit->iSelectedImage;
     567        item->iSelectedImage = cit->iSelectedImage;
    697568    if (item->mask & CBEIF_OVERLAY)
    698       item->iOverlay      = cit->iOverlay;
     569        item->iOverlay = cit->iOverlay;
    699570    if (item->mask & CBEIF_INDENT)
    700       item->iIndent        = cit->iIndent;
     571        item->iIndent = cit->iIndent;
    701572    if (item->mask & CBEIF_LPARAM)
    702       item->lParam        = cit->lParam;
     573        item->lParam = cit->lParam;
    703574    infoPtr->nb_items++;
    704575
    705     COMBOEX_WarnCallBack (item);
    706 
    707     COMBOEX_DumpItem (item);
     576    if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
    708577
    709578    SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
    710579                  (WPARAM)cit->iItem, (LPARAM)item);
    711580
    712     COMBOEX_CopyItem (infoPtr, item, &nmcit.ceItem);
     581    memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
     582    COMBOEX_CopyItem (item, &nmcit.ceItem);
    713583    COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
    714584
     
    718588
    719589
    720 static LRESULT
    721 COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
    722 {
    723     COMBOBOXEXITEMA     *cit = (COMBOBOXEXITEMA *) lParam;
    724     COMBOBOXEXITEMW     citW;
    725     LRESULT             ret;
     590static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
     591{
     592    COMBOBOXEXITEMW citW;
     593    LPWSTR wstr = NULL;
     594    INT ret;
    726595
    727596    memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
    728     if (cit->mask & CBEIF_TEXT) {
    729         LPSTR str;
    730         INT len;
    731 
    732         str = cit->pszText;
    733         if (!str) str="";
    734         len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
    735         if (len > 0) {
    736             citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
    737             MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
    738         }
    739     }
    740     ret = COMBOEX_InsertItemW(hwnd,wParam,(LPARAM)&citW);;
    741 
    742     if (cit->mask & CBEIF_TEXT)
    743         COMCTL32_Free(citW.pszText);
     597    if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
     598        INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
     599        wstr = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
     600        if (!wstr) return -1;
     601        MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
     602        citW.pszText = wstr;
     603    }
     604    ret = COMBOEX_InsertItemW(infoPtr, &citW);;
     605   
     606    if (wstr) COMCTL32_Free(wstr);
     607   
    744608    return ret;
    745609}
    746610
    747611
    748 static LRESULT
    749 COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
    750 {
    751     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
     612static DWORD
     613COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
     614{
    752615    DWORD dwTemp;
    753616
    754     TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
     617    TRACE("(mask=x%08lx, style=0x%08lx)\n", mask, style);
    755618
    756619    dwTemp = infoPtr->dwExtStyle;
    757620
    758     if (lParam & (CBES_EX_NOEDITIMAGEINDENT |
    759                   CBES_EX_PATHWORDBREAKPROC |
     621    if (style &  (CBES_EX_PATHWORDBREAKPROC |
    760622                  CBES_EX_NOSIZELIMIT |
    761623                  CBES_EX_CASESENSITIVE))
    762         FIXME("Extended style not implemented %08lx\n", lParam);
    763 
    764     if ((DWORD)wParam) {
    765         infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
    766     }
     624        FIXME("Extended style not implemented %08lx\n", style);
     625
     626    if (mask)
     627        infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
    767628    else
    768         infoPtr->dwExtStyle = (DWORD)lParam;
    769 
    770     /*
    771      * native does this for CBES_EX_NOEDITIMAGE state change
    772      */
    773     if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
    774         (dwTemp & CBES_EX_NOEDITIMAGE)) {
     629        infoPtr->dwExtStyle = style;
     630
     631    /* test if the control's appearance has changed */
     632    mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
     633    if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
    775634        /* if state of EX_NOEDITIMAGE changes, invalidate all */
    776635        TRACE("EX_NOEDITIMAGE state changed to %ld\n",
    777             infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
    778         InvalidateRect (hwnd, NULL, TRUE);
     636              infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
     637        InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
    779638        COMBOEX_AdjustEditPos (infoPtr);
    780639        if (infoPtr->hwndEdit)
     
    782641    }
    783642
    784     return (LRESULT)dwTemp;
    785 }
    786 
    787 
    788 inline static LRESULT
    789 COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
    790 {
    791     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    792     HIMAGELIST himlTemp;
    793 
    794     TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
    795 
    796     himlTemp = infoPtr->himl;
    797     infoPtr->himl = (HIMAGELIST)lParam;
    798 
    799     COMBOEX_ReSize (hwnd, infoPtr);
     643    return dwTemp;
     644}
     645
     646
     647static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
     648{
     649    HIMAGELIST himlTemp = infoPtr->himl;
     650
     651    TRACE("(...)\n");
     652
     653    infoPtr->himl = himl;
     654
     655    COMBOEX_ReSize (infoPtr);
    800656    InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
    801657
    802658    /* reposition the Edit control based on whether icon exists */
    803659    COMBOEX_AdjustEditPos (infoPtr);
    804     return (LRESULT)himlTemp;
    805 }
    806 
    807 static LRESULT
    808 COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
    809 {
    810     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    811     COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
    812     INT index;
     660    return himlTemp;
     661}
     662
     663static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
     664{
     665    INT index = cit->iItem;
    813666    CBE_ITEMDATA *item;
    814667
    815     COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
    816 
    817     /* get real index of item to insert */
    818     index = cit->iItem;
     668    if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
    819669
    820670    /* if item number requested does not exist then return failure */
    821     if ((index > infoPtr->nb_items) || (index < -1)) {
    822         ERR("attempt to set item that does not exist yet!\n");
    823         return 0;
    824     }
     671    if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
    825672
    826673    /* if the item is the edit control and there is no edit control, skip */
    827     if ((index == -1) &&
    828         ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
    829             return 0;
    830 
    831     if (!(item = COMBOEX_FindItem(infoPtr, index))) {
    832         ERR("attempt to set item that was not found!\n");
    833         return 0;
    834     }
     674    if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
     675
     676    if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
    835677
    836678    /* add/change stuff to the internal item structure */
    837679    item->mask |= cit->mask;
    838680    if (cit->mask & CBEIF_TEXT) {
    839         LPWSTR str;
    840         INT len;
    841         WCHAR emptystr[1] = {0};
    842 
    843         str = cit->pszText;
    844         if (!str) str=emptystr;
    845         len = strlenW(str);
     681        INT len = 0;
     682
     683        COMBOEX_FreeText(item);
     684        if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
    846685        if (len > 0) {
    847686            item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
    848             strcpyW(item->pszText,str);
    849         }
    850         item->cchTextMax   = cit->cchTextMax;
     687            if (!item->pszText) return FALSE;
     688            strcpyW(item->pszText, cit->pszText);
     689        } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
     690            item->pszText = LPSTR_TEXTCALLBACKW;
     691        item->cchTextMax = cit->cchTextMax;
    851692    }
    852693    if (cit->mask & CBEIF_IMAGE)
    853       item->iImage        = cit->iImage;
     694        item->iImage = cit->iImage;
    854695    if (cit->mask & CBEIF_SELECTEDIMAGE)
    855       item->iSelectedImage = cit->iSelectedImage;
     696        item->iSelectedImage = cit->iSelectedImage;
    856697    if (cit->mask & CBEIF_OVERLAY)
    857       item->iOverlay      = cit->iOverlay;
     698        item->iOverlay = cit->iOverlay;
    858699    if (cit->mask & CBEIF_INDENT)
    859       item->iIndent        = cit->iIndent;
     700        item->iIndent = cit->iIndent;
    860701    if (cit->mask & CBEIF_LPARAM)
    861       cit->lParam         = cit->lParam;
    862 
    863     COMBOEX_WarnCallBack (item);
    864 
    865     COMBOEX_DumpItem (item);
     702        cit->lParam = cit->lParam;
     703
     704    if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
    866705
    867706    /* if original request was to update edit control, do some fast foot work */
     
    873712}
    874713
    875 static LRESULT
    876 COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
    877 {
    878     COMBOBOXEXITEMA     *cit = (COMBOBOXEXITEMA *) lParam;
    879     COMBOBOXEXITEMW     citW;
    880     LRESULT             ret;
    881 
    882     memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
    883     if (cit->mask & CBEIF_TEXT) {
    884         LPSTR str;
    885         INT len;
    886 
    887         str = cit->pszText;
    888         if (!str) str="";
    889         len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
    890         if (len > 0) {
    891             citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
    892             MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
    893         }
    894     }
    895     ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
    896 
    897     if (cit->mask & CBEIF_TEXT)
    898         COMCTL32_Free(citW.pszText);
     714static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
     715{
     716    COMBOBOXEXITEMW citW;
     717    LPWSTR wstr = NULL;
     718    BOOL ret;
     719
     720    memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
     721    if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
     722        INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
     723        wstr = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
     724        if (!wstr) return FALSE;
     725        MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
     726        citW.pszText = wstr;
     727    }
     728    ret = COMBOEX_SetItemW(infoPtr, &citW);;
     729
     730    if (wstr) COMCTL32_Free(wstr);
     731
    899732    return ret;
    900733}
    901734
    902735
    903 inline static LRESULT
    904 COMBOEX_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
    905 {
    906     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    907     BOOL bTemp = infoPtr->bUnicode;
    908 
    909     TRACE("to %s hwnd=0x%04x, was %s\n",
    910           ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd,
    911           (bTemp) ? "TRUE" : "FALSE");
    912 
    913     infoPtr->bUnicode = (BOOL)wParam;
     736static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
     737{
     738    BOOL bTemp = infoPtr->unicode;
     739
     740    TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
     741
     742    infoPtr->unicode = value;
    914743
    915744    return bTemp;
     
    917746
    918747
    919 
    920748/* ***  CB_xxx message support  *** */
    921749
    922 
    923 static LRESULT
    924 COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     750static INT
     751COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCSTR str)
    925752{
    926753    INT i, count;
    927754    CBE_ITEMDATA *item;
    928755    LPWSTR desired = NULL;
    929     INT start = (INT) wParam;
    930 
    931     i = MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
     756
     757    i = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
    932758    if (i > 0) {
    933759        desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
    934         MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, desired, i);
    935     }
    936 
    937     count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0 , 0);
     760        if (!desired) return CB_ERR;
     761        MultiByteToWideChar (CP_ACP, 0, str, -1, desired, i);
     762    }
     763
     764    count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
    938765
    939766    /* now search from after starting loc and wrapping back to start */
    940767    for(i=start+1; i<count; i++) {
    941         item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
    942                           CB_GETITEMDATA, (WPARAM)i, 0);
    943         TRACE("desired=%s, item=%s\n",
    944               debugstr_w(desired), debugstr_w(item->pszText));
    945         if (lstrcmpiW(item->pszText, desired) == 0) {
     768        item = get_item_data(infoPtr, i);
     769        if (lstrcmpiW(COMBOEX_GetText(infoPtr, item), desired) == 0) {
    946770            COMCTL32_Free (desired);
    947771            return i;
     
    949773    }
    950774    for(i=0; i<=start; i++) {
    951         item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
    952                           CB_GETITEMDATA, (WPARAM)i, 0);
    953         TRACE("desired=%s, item=%s\n",
    954               debugstr_w(desired), debugstr_w(item->pszText));
    955         if (lstrcmpiW(item->pszText, desired) == 0) {
     775        item = get_item_data(infoPtr, i);
     776        if (lstrcmpiW(COMBOEX_GetText(infoPtr, item), desired) == 0) {
    956777            COMCTL32_Free (desired);
    957778            return i;
     
    963784
    964785
    965 static LRESULT
    966 COMBOEX_GetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
    967 {
    968     INT index = wParam;
    969     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
     786static DWORD COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
     787{
    970788    CBE_ITEMDATA *item1, *item2;
    971     LRESULT lret = 0;
    972 
    973     item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
    974                                              wParam, lParam);
     789    DWORD ret = 0;
     790
     791    item1 = get_item_data(infoPtr, index);
    975792    if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
    976793        item2 = COMBOEX_FindItem (infoPtr, index);
     
    979796            return CB_ERR;
    980797        }
    981         if (item1->mask & CBEIF_LPARAM)
    982             lret = (LRESULT) item1->lParam;
    983         TRACE("returning 0x%08lx\n", lret);
    984         return lret;
    985     }
    986     lret = (LRESULT)item1;
    987     TRACE("non-valid result from combo, returning 0x%08lx\n", lret);
    988     return lret;
    989 }
    990 
    991 
    992 static LRESULT
    993 COMBOEX_SetCursel (HWND hwnd, WPARAM wParam, LPARAM lParam)
    994 {
    995     INT index = wParam;
    996     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
     798        if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
     799        TRACE("returning 0x%08lx\n", ret);
     800    } else {
     801        ret = (DWORD)item1;
     802        TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
     803    }
     804    return ret;
     805}
     806
     807
     808static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
     809{
    997810    CBE_ITEMDATA *item;
    998     LRESULT lret;
    999 
    1000     if (!(item = COMBOEX_FindItem(infoPtr, index))) {
    1001         /* FIXME: need to clear selection */
    1002         return CB_ERR;
    1003     }
    1004 
    1005     TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
    1006           debugstr_w(item->pszText) : "<null>");
     811    INT sel;
     812
     813    if (!(item = COMBOEX_FindItem(infoPtr, index)))
     814        return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
     815
     816    TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
    1007817    infoPtr->selected = index;
    1008818
    1009     lret = SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, wParam, lParam);
     819    sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
    1010820    COMBOEX_SetEditText (infoPtr, item);
    1011     return lret;
    1012 }
    1013 
    1014 
    1015 static LRESULT
    1016 COMBOEX_SetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1017 {
    1018     INT index = wParam;
    1019     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
     821    return sel;
     822}
     823
     824
     825static DWORD COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD data)
     826{
    1020827    CBE_ITEMDATA *item1, *item2;
    1021828
    1022     item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
    1023                                              wParam, lParam);
     829    item1 = get_item_data(infoPtr, index);
    1024830    if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
    1025831        item2 = COMBOEX_FindItem (infoPtr, index);
     
    1029835        }
    1030836        item1->mask |= CBEIF_LPARAM;
    1031         item1->lParam = lParam;
    1032         TRACE("setting lparam to 0x%08lx\n", lParam);
     837        item1->lParam = data;
     838        TRACE("setting lparam to 0x%08lx\n", data);
    1033839        return 0;
    1034840    }
     
    1038844
    1039845
    1040 static LRESULT
    1041 COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1042 {
    1043     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
     846static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
     847{
    1044848    RECT cb_wrect, cbx_wrect, cbx_crect;
    1045     LRESULT ret = 0;
    1046     UINT height;
    1047849
    1048850    /* First, lets forward the message to the normal combo control
    1049851       just like Windows.     */
    1050     if (infoPtr->hwndCombo)   
    1051        SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
     852    if (infoPtr->hwndCombo)
     853       if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
     854                         index, height) == CB_ERR) return CB_ERR;
    1052855
    1053856    GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
    1054     GetWindowRect (hwnd, &cbx_wrect);
    1055     GetClientRect (hwnd, &cbx_crect);
     857    GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
     858    GetClientRect (infoPtr->hwndSelf, &cbx_crect);
    1056859    /* the height of comboex as height of the combo + comboex border */
    1057860    height = cb_wrect.bottom-cb_wrect.top
     
    1064867          cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
    1065868          cbx_wrect.right-cbx_wrect.left, height);
    1066     SetWindowPos (hwnd, HWND_TOP, 0, 0,
    1067                   cbx_wrect.right-cbx_wrect.left,
    1068                   height,
     869    SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
     870                  cbx_wrect.right-cbx_wrect.left, height,
    1069871                  SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
    1070872
    1071     return ret;
     873    return 0;
    1072874}
    1073875
     
    1076878
    1077879
    1078 static LRESULT
    1079 COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1080 {
    1081     LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
     880static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
     881{
     882    WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
     883    WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
     884    WCHAR NIL[] = { 0 };
    1082885    COMBOEX_INFO *infoPtr;
    1083886    DWORD dwComboStyle;
    1084     LOGFONTA mylogfont;
    1085     CBE_ITEMDATA *item;
     887    LOGFONTW mylogfont;
    1086888    RECT wnrc1, clrc1, cmbwrc;
    1087     LONG test;
    1088889    INT i;
    1089890
    1090891    /* allocate memory for info structure */
    1091892    infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
    1092     if (infoPtr == NULL) {
    1093         ERR("could not allocate info memory!\n");
    1094         return 0;
    1095     }
     893    if (!infoPtr) return -1;
    1096894
    1097895    /* initialize info structure */
    1098 
    1099     infoPtr->items    = NULL;
    1100     infoPtr->nb_items = 0;
     896    /* note that infoPtr is allocated zero-filled */
     897   
    1101898    infoPtr->hwndSelf = hwnd;
    1102899    infoPtr->selected = -1;
    1103900
    1104     infoPtr->bUnicode = IsWindowUnicode (hwnd);
    1105 
    1106     i = SendMessageA(GetParent (hwnd),
    1107                      WM_NOTIFYFORMAT, hwnd, NF_QUERY);
    1108     if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
    1109         ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
    1110             i);
     901    infoPtr->unicode = IsWindowUnicode (hwnd);
     902
     903    i = SendMessageW(GetParent (hwnd), WM_NOTIFYFORMAT, hwnd, NF_QUERY);
     904    if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
     905        WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
    1111906        i = NFR_ANSI;
    1112907    }
    1113     infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
    1114 
    1115     SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
     908    infoPtr->NtfUnicode = (i == NFR_UNICODE);
     909
     910    SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
    1116911
    1117912    /* create combo box */
    1118     dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
     913    dwComboStyle = GetWindowLongW (hwnd, GWL_STYLE) &
    1119914                        (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
    1120915
     
    1136931    /* (allow space for the icons).                                     */
    1137932
    1138     infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
     933    infoPtr->hwndCombo = CreateWindowW (COMBOBOX, NIL,
    1139934                         /* following line added to match native */
    1140935                         WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
     
    1143938                         WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
    1144939                         cs->y, cs->x, cs->cx, cs->cy, hwnd,
    1145                          (HMENU) GetWindowLongA (hwnd, GWL_ID),
    1146                          GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
     940                         (HMENU) GetWindowLongW (hwnd, GWL_ID),
     941                         GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
    1147942
    1148943    /*
     
    1158953     * data structure.
    1159954     */
    1160     test = GetPropA(infoPtr->hwndCombo, (LPCSTR)(LONG)ComboExInfo);
    1161     if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
    1162         SetPropA(infoPtr->hwndCombo, "CC32SubclassInfo", (LONG)infoPtr);
    1163     }
    1164     infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndCombo,
     955    SetPropA(infoPtr->hwndCombo, COMBOEX_SUBCLASS_PROP, hwnd);
     956    infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndCombo,
    1165957                                GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
    1166958    infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
     
    1172964     */
    1173965    if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
    1174         infoPtr->hwndEdit = CreateWindowExA (0, "EDIT", "",
     966        infoPtr->hwndEdit = CreateWindowExW (0, EDIT, NIL,
    1175967                    WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
    1176968                    0, 0, 0, 0,  /* will set later */
    1177969                    infoPtr->hwndCombo,
    1178                     (HMENU) GetWindowLongA (hwnd, GWL_ID),
    1179                     GetWindowLongA (hwnd, GWL_HINSTANCE),
     970                    (HMENU) GetWindowLongW (hwnd, GWL_ID),
     971                    GetWindowLongW (hwnd, GWL_HINSTANCE),
    1180972                    NULL);
    1181973
     
    1191983         * data structure.
    1192984         */
    1193         test = GetPropA(infoPtr->hwndEdit, (LPCSTR)(LONG)ComboExInfo);
    1194         if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
    1195             SetPropA(infoPtr->hwndEdit, "CC32SubclassInfo", (LONG)infoPtr);
    1196         }
    1197         infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndEdit,
     985        SetPropA(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
     986        infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndEdit,
    1198987                                 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
    1199988        infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
    1200     }
    1201     else {
    1202         infoPtr->hwndEdit = 0;
    1203         infoPtr->font = 0;
    1204989    }
    1205990
     
    1209994     */
    1210995    if (!infoPtr->font) {
    1211         SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
     996        SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
    1212997                               &mylogfont, 0);
    1213         infoPtr->font = infoPtr->hDefaultFont = CreateFontIndirectA (&mylogfont);
     998        infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
    1214999    }
    12151000    SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
     
    12191004    }
    12201005
    1221     COMBOEX_ReSize (hwnd, infoPtr);
     1006    COMBOEX_ReSize (infoPtr);
    12221007
    12231008    /* Above is fairly certain, below is much less certain. */
     
    12451030    /*
    12461031     * Create an item structure to represent the data in the
    1247      * EDIT control.
     1032     * EDIT control. It is allocated zero-filled.
    12481033     */
    1249     item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
    1250     item->next = NULL;
    1251     item->pszText = NULL;
    1252     item->mask = 0;
    1253     infoPtr->edit = item;
     1034    infoPtr->edit = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
     1035    if (!infoPtr->edit) {
     1036        COMBOEX_Destroy(infoPtr);
     1037        return -1;
     1038    }
    12541039
    12551040    return 0;
     
    12571042
    12581043
    1259 inline static LRESULT
    1260 COMBOEX_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
     1044static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
    12611045{
    12621046    LRESULT lret;
    1263     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    12641047    INT command = HIWORD(wParam);
    12651048    CBE_ITEMDATA *item = 0;
     
    12681051    NMCBEENDEDITW cbeend;
    12691052    DWORD oldflags;
     1053    HWND parent = GetParent (infoPtr->hwndSelf);
    12701054
    12711055    TRACE("for command %d\n", command);
     
    12741058    {
    12751059    case CBN_DROPDOWN:
    1276         SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
    1277                              (LPARAM)hwnd);
     1060        SetFocus (infoPtr->hwndCombo);
     1061        ShowWindow (infoPtr->hwndEdit, SW_HIDE);
     1062        return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
     1063       
     1064    case CBN_CLOSEUP:
     1065        SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
    12781066        /*
    12791067         * from native trace of first dropdown after typing in URL in IE4
     
    12891077         * the rest is supposition 
    12901078         */
     1079        ShowWindow (infoPtr->hwndEdit, SW_SHOW);
     1080        InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
     1081        InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
    12911082        cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
    12921083        if (cursel == -1) {
     
    12951086            n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
    12961087            for (cursel = 0; cursel < n; cursel++){
    1297                 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
    1298                                                      CB_GETITEMDATA,
    1299                                                      cursel, 0);
     1088                item = get_item_data(infoPtr, cursel);
    13001089                if ((INT)item == CB_ERR) break;
    1301                 if (lstrcmpiW(item->pszText, wintext) == 0) break;
     1090                if (!lstrcmpiW(COMBOEX_GetText(infoPtr, item), wintext)) break;
    13021091            }
    13031092            if ((cursel == n) || ((INT)item == CB_ERR)) {
     
    13101099        }
    13111100        else {
    1312             item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
    1313                                                  CB_GETITEMDATA,
    1314                                                  cursel, 0);
     1101            item = get_item_data(infoPtr, cursel);
    13151102            if ((INT)item == CB_ERR) {
    13161103                TRACE("failed to find match??? item=%p cursel=%d\n",
     
    13321119            cbeend.iWhy = CBENF_DROPDOWN;
    13331120
    1334             if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, item->pszText)) {
    1335                 /* abort the change */
    1336                 TRACE("Notify requested abort of change\n");
    1337                 return 0;
    1338             }
     1121            if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
    13391122        }
    13401123
     
    13431126        if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
    13441127            infoPtr->selected = cursel;
    1345             SendMessageW (hwnd, CB_SETCURSEL, cursel, 0);
     1128            SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
    13461129            SetFocus(infoPtr->hwndCombo);
    13471130        }
     
    13691152        infoPtr->selected = oldItem;
    13701153        COMBOEX_SetEditText (infoPtr, item);
    1371         return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
    1372                              (LPARAM)hwnd);
     1154        return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
    13731155
    13741156    case CBN_SELENDOK:
     
    13771159         * issuing the message. IE4 depends on this.
    13781160         */
    1379         return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
    1380                              (LPARAM)hwnd);
     1161        return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
    13811162
    13821163    case CBN_KILLFOCUS:
     
    13921173         *  return 0
    13931174         */
    1394         SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
    1395                              (LPARAM)hwnd);
     1175        SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
    13961176        if (infoPtr->flags & WCBE_ACTEDIT) {
    13971177            GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
     
    14021182
    14031183            infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
    1404             if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) {
    1405                 /* abort the change */
    1406                 TRACE("Notify requested abort of change\n");
    1407                 return 0;
    1408             }
     1184            if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
    14091185        }
    14101186        /* possible CB_GETCURSEL */
     
    14121188        return 0;
    14131189
    1414     case CBN_CLOSEUP:
    14151190    default:
    14161191        /*
     
    14201195         * after passing the command to the parent of the ComboEx.
    14211196         */
    1422         lret = SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
    1423                              (LPARAM)hwnd);
     1197        lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
    14241198        if (infoPtr->hwndEdit)
    14251199            SetFocus(infoPtr->hwndEdit);
     
    14301204
    14311205
    1432 inline static LRESULT
    1433 COMBOEX_WM_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1434 {
    1435     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    1436     DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)lParam;
     1206static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
     1207{
    14371208    CBE_ITEMDATA *item, *olditem;
     1209    NMCOMBOBOXEXW nmcit;
    14381210    INT i;
    1439     NMCOMBOBOXEXW nmcit;
    14401211
    14411212    TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
     
    14601231        }
    14611232        if (!item->next || (i != dis->itemID)) {
    1462             FIXME("COMBOBOXEX item structures broken. Please report!\n");
     1233            ERR("COMBOBOXEX item structures broken. Please report!\n");
    14631234            return FALSE;
    14641235        }
     
    14681239    infoPtr->nb_items--;
    14691240
    1470     COMBOEX_CopyItem (infoPtr, olditem, &nmcit.ceItem);
     1241    memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
     1242    COMBOEX_CopyItem (olditem, &nmcit.ceItem);
    14711243    COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
    14721244
    1473     if (olditem->pszText)
    1474         COMCTL32_Free(olditem->pszText);
     1245    COMBOEX_FreeText(olditem);
    14751246    COMCTL32_Free(olditem);
    14761247
    14771248    return TRUE;
    1478 
    1479 }
    1480 
    1481 
    1482 inline static LRESULT
    1483 COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1484 {
    1485     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    1486     DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
     1249}
     1250
     1251
     1252static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
     1253{
     1254    WCHAR nil[] = { 0 };
    14871255    CBE_ITEMDATA *item = 0;
    14881256    SIZE txtsize;
    14891257    RECT rect;
    1490     LPWSTR str;
    1491     int drawimage, drawstate;
     1258    LPCWSTR str = nil;
    14921259    UINT xbase, x, y;
    1493     UINT xioff = 0;               /* size and spacer of image if any */
    1494     IMAGEINFO iinfo;
    14951260    INT len;
    1496     COLORREF nbkc, ntxc;
     1261    COLORREF nbkc, ntxc, bkc, txc;
     1262    int drawimage, drawstate, xioff;
    14971263
    14981264    if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
    14991265
    1500     /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
    1501     if (!TRACE_ON(message)) {
    1502         TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
    1503               dis->CtlType, dis->CtlID);
    1504         TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
    1505               dis->itemID, dis->itemAction, dis->itemState);
    1506         TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
    1507               dis->hwndItem, dis->hDC, dis->rcItem.left,
    1508               dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
    1509               dis->itemData);
    1510     }
     1266    TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
     1267          dis->CtlType, dis->CtlID);
     1268    TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
     1269          dis->itemID, dis->itemAction, dis->itemState);
     1270    TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
     1271          dis->hwndItem, dis->hDC, dis->rcItem.left,
     1272          dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
     1273          dis->itemData);
    15111274
    15121275    /* MSDN says:                                                       */
     
    15361299            {
    15371300                RECT exrc, cbrc, edrc;
    1538                 GetWindowRect (hwnd, &exrc);
     1301                GetWindowRect (infoPtr->hwndSelf, &exrc);
    15391302                GetWindowRect (infoPtr->hwndCombo, &cbrc);
    15401303                edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
     
    15581321    /* If draw item is -1 (edit control) setup the item pointer */
    15591322    if (dis->itemID == 0xffffffff) {
    1560         CHAR str[260];
    1561         INT wlen, alen;
    1562 
    15631323        item = infoPtr->edit;
    15641324
    15651325        if (infoPtr->hwndEdit) {
     1326            INT len;
    15661327
    15671328            /* free previous text of edit item */
    1568             if (item->pszText) {
    1569                 COMCTL32_Free(item->pszText);
    1570                 item->pszText = 0;
    1571                 item->mask &= ~CBEIF_TEXT;
     1329            COMBOEX_FreeText(item);
     1330            item->mask &= ~CBEIF_TEXT;
     1331            if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
     1332                item->mask |= CBEIF_TEXT;
     1333                item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
     1334                if (item->pszText)
     1335                    GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
     1336           
     1337               TRACE("edit control hwndEdit=%0x, text len=%d str=%s\n",
     1338                     infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
    15721339            }
    1573             alen = SendMessageA (infoPtr->hwndEdit, WM_GETTEXT, 260, (LPARAM)&str);
    1574             TRACE("edit control hwndEdit=%0x, text len=%d str=<%s>\n",
    1575                   infoPtr->hwndEdit, alen, str);
    1576             if (alen > 0) {
    1577                 item->mask |= CBEIF_TEXT;
    1578                 wlen = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
    1579                 if (wlen > 0) {
    1580                     item->pszText = (LPWSTR)COMCTL32_Alloc ((wlen + 1)*sizeof(WCHAR));
    1581                     MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, wlen);
    1582                 }
    1583             }
    1584         }
    1585     }
     1340        }
     1341    }
     1342
    15861343
    15871344    /* if the item pointer is not set, then get the data and locate it */
    15881345    if (!item) {
    1589         item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
    1590                              CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
    1591         if (item == (CBE_ITEMDATA *)CB_ERR)
    1592             {
    1593                 FIXME("invalid item for id %d \n",dis->itemID);
    1594                 return 0;
     1346        item = get_item_data(infoPtr, dis->itemID);
     1347        if (item == (CBE_ITEMDATA *)CB_ERR) {
     1348            ERR("invalid item for id %d \n", dis->itemID);
     1349            return 0;
     1350        }
     1351    }
     1352
     1353    if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
     1354
     1355    xbase = CBE_STARTOFFSET;
     1356    if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
     1357        INT indent = item->iIndent;
     1358        if (indent == I_INDENTCALLBACK) {
     1359            NMCOMBOBOXEXW nmce;
     1360            ZeroMemory(&nmce, sizeof(nmce));
     1361            nmce.ceItem.mask = CBEIF_INDENT;
     1362            COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
     1363            if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
     1364                item->iIndent = nmce.ceItem.iIndent;
     1365            indent = nmce.ceItem.iIndent;
     1366        }
     1367        xbase += (indent * CBE_INDENT);
     1368    }
     1369
     1370    drawimage = -2;
     1371    drawstate = ILD_NORMAL;
     1372    if (item->mask & CBEIF_IMAGE)
     1373        drawimage = item->iImage;
     1374    if (dis->itemState & ODS_COMBOEXLBOX) {
     1375        /* drawing listbox entry */
     1376        if (dis->itemState & ODS_SELECTED) {
     1377            if (item->mask & CBEIF_SELECTEDIMAGE)
     1378                drawimage = item->iSelectedImage;
     1379            drawstate = ILD_SELECTED;
     1380        }
     1381    } else {
     1382        /* drawing combo/edit entry */
     1383        if (IsWindowVisible(infoPtr->hwndEdit)) {
     1384            /* if we have an edit control, the slave the
     1385             * selection state to the Edit focus state
     1386             */
     1387            if (infoPtr->flags & WCBE_EDITFOCUSED) {
     1388                if (item->mask & CBEIF_SELECTEDIMAGE)
     1389                    drawimage = item->iSelectedImage;
     1390                drawstate = ILD_SELECTED;
    15951391            }
    1596     }
    1597 
    1598     COMBOEX_DumpItem (item);
    1599 
    1600     xbase = CBE_STARTOFFSET;
    1601     if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
    1602         xbase += (item->iIndent * CBE_INDENT);
    1603     if (item->mask & CBEIF_IMAGE) {
    1604         ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
    1605         xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
    1606     }
    1607 
    1608     switch (dis->itemAction) {
    1609     case ODA_FOCUS:
    1610         if (dis->itemState & ODS_SELECTED /*1*/) {
    1611             if ((item->mask & CBEIF_TEXT) && item->pszText) {
    1612                 RECT rect2;
    1613 
    1614                 len = strlenW (item->pszText);
    1615                 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
    1616                 rect.left = xbase + xioff - 1;
    1617                 rect.right = rect.left + txtsize.cx + 2;
    1618                 rect.top = dis->rcItem.top;
    1619                 rect.bottom = dis->rcItem.bottom;
    1620                 GetClipBox (dis->hDC, &rect2);
    1621                 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
    1622                       dis->itemID, rect.left, rect.top,
    1623                       rect.right, rect.bottom);
    1624                 TRACE("                      clip=(%d,%d)-(%d,%d)\n",
    1625                       rect2.left, rect2.top,
    1626                       rect2.right, rect2.bottom);
    1627 
    1628                 DrawFocusRect(dis->hDC, &rect);
     1392        } else {
     1393            /* if we don't have an edit control, use
     1394             * the requested state.
     1395             */
     1396            if (dis->itemState & ODS_SELECTED) {
     1397                if (item->mask & CBEIF_SELECTEDIMAGE)
     1398                    drawimage = item->iSelectedImage;
     1399                drawstate = ILD_SELECTED;
    16291400            }
    1630             else {
    1631                 FIXME("ODA_FOCUS and ODS_SELECTED but no text\n");
    1632             }
    1633         }
    1634         else {
    1635             FIXME("ODA_FOCUS but not ODS_SELECTED\n");
    1636         }
    1637         break;
    1638     case ODA_SELECT:
    1639     case ODA_DRAWENTIRE:
    1640         drawimage = -1;
    1641         drawstate = ILD_NORMAL;
    1642         if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
    1643             if (item->mask & CBEIF_IMAGE)
    1644                 drawimage = item->iImage;
    1645             if (dis->itemState & ODS_COMBOEXLBOX) {
    1646                 /* drawing listbox entry */
    1647                 if (dis->itemState & ODS_SELECTED) {
    1648                     if (item->mask & CBEIF_SELECTEDIMAGE)
    1649                         drawimage = item->iSelectedImage;
    1650                     drawstate = ILD_SELECTED;
    1651                 }
    1652             }
    1653             else {
    1654                 /* drawing combo/edit entry */
    1655                 if (infoPtr->hwndEdit) {
    1656                     /* if we have an edit control, the slave the
    1657                      * selection state to the Edit focus state
    1658                      */
    1659                     if (infoPtr->flags & WCBE_EDITFOCUSED) {
    1660                         if (item->mask & CBEIF_SELECTEDIMAGE)
    1661                             drawimage = item->iSelectedImage;
    1662                         drawstate = ILD_SELECTED;
    1663                     }
    1664                 }
    1665                 else {
    1666                     /* if we don't have an edit control, use
    1667                      * the requested state.
    1668                      */
    1669                     if (dis->itemState & ODS_SELECTED) {
    1670                         if (item->mask & CBEIF_SELECTEDIMAGE)
    1671                             drawimage = item->iSelectedImage;
    1672                         drawstate = ILD_SELECTED;
    1673                     }
    1674                 }
    1675             }
    1676         }
    1677         if (drawimage != -1) {
    1678             TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
    1679             ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
    1680                             xbase, dis->rcItem.top, drawstate);
    1681         }
    1682 
    1683         /* setup pointer to text to be drawn */
    1684         if ((item->mask & CBEIF_TEXT) && item->pszText)
    1685             str = item->pszText;
    1686         else
    1687             str = (LPWSTR) L"";
     1401        }
     1402    }
     1403
     1404    if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
     1405        IMAGEINFO iinfo;
     1406        iinfo.rcImage.left = iinfo.rcImage.right = 0;
     1407        ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
     1408        xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
     1409    }  else xioff = 0;
     1410
     1411    /* setup pointer to text to be drawn */
     1412    str = COMBOEX_GetText(infoPtr, item);
     1413    if (!str) str = nil;
     1414
     1415    len = strlenW (str);
     1416    GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
     1417   
     1418    if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
     1419        int overlay = item->iOverlay;
     1420       
     1421        if (drawimage == I_IMAGECALLBACK) {
     1422            NMCOMBOBOXEXW nmce;
     1423            ZeroMemory(&nmce, sizeof(nmce));
     1424            nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
     1425            COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
     1426            if (drawstate == ILD_NORMAL) {
     1427                if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
     1428                drawimage = nmce.ceItem.iImage;
     1429            } else if (drawstate == ILD_SELECTED) {
     1430                if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
     1431                drawimage =  nmce.ceItem.iSelectedImage;
     1432            } else ERR("Bad draw state = %d\n", drawstate);
     1433        }
     1434
     1435        if (overlay == I_IMAGECALLBACK) {
     1436            NMCOMBOBOXEXW nmce;
     1437            ZeroMemory(&nmce, sizeof(nmce));
     1438            nmce.ceItem.mask = CBEIF_OVERLAY;
     1439            COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
     1440            if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
     1441                item->iOverlay = nmce.ceItem.iOverlay;
     1442            overlay = nmce.ceItem.iOverlay;
     1443        }
     1444   
     1445        if (drawimage >= 0 &&
     1446            !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
     1447            if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
     1448            ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
     1449                            drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
     1450        }
    16881451
    16891452        /* now draw the text */
    1690         len = lstrlenW (str);
    1691         GetTextExtentPointW (dis->hDC, str, len, &txtsize);
    1692         nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
    1693                             COLOR_HIGHLIGHT : COLOR_WINDOW);
    1694         SetBkColor (dis->hDC, nbkc);
    1695         ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
    1696                             COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
    1697         SetTextColor (dis->hDC, ntxc);
    1698         x = xbase + xioff;
    1699         y = dis->rcItem.top +
    1700             (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
    1701         rect.left = x;
    1702         rect.right = x + txtsize.cx;
    1703         rect.top = dis->rcItem.top + 1;
    1704         rect.bottom = dis->rcItem.bottom - 1;
    1705         TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
    1706               dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
    1707         ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
    1708                      &rect, str, len, 0);
    1709         if (dis->itemState & ODS_FOCUS) {
    1710             rect.top -= 1;
    1711             rect.bottom += 1;
    1712             rect.left -= 1;
    1713             rect.right += 1;
    1714             TRACE("drawing item %d focus after text, rect=(%d,%d)-(%d,%d)\n",
    1715                   dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
    1716             DrawFocusRect (dis->hDC, &rect);
    1717         }
    1718         break;
    1719     default:
    1720         FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
    1721               hwnd, wParam, lParam, dis->itemAction);
     1453        if (!IsWindowVisible (infoPtr->hwndEdit)) {
     1454            nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
     1455                                COLOR_HIGHLIGHT : COLOR_WINDOW);
     1456            bkc = SetBkColor (dis->hDC, nbkc);
     1457            ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
     1458                                COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
     1459            txc = SetTextColor (dis->hDC, ntxc);
     1460            x = xbase + xioff;
     1461            y = dis->rcItem.top +
     1462                (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
     1463            rect.left = x;
     1464            rect.right = x + txtsize.cx;
     1465            rect.top = dis->rcItem.top + 1;
     1466            rect.bottom = dis->rcItem.bottom - 1;
     1467            TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
     1468                  dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
     1469            ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
     1470                         &rect, str, len, 0);
     1471            SetBkColor (dis->hDC, bkc);
     1472            SetTextColor (dis->hDC, txc);
     1473        }
     1474    }
     1475   
     1476    if (dis->itemAction & ODA_FOCUS) {
     1477        rect.left = xbase + xioff - 1;
     1478        rect.right = rect.left + txtsize.cx + 2;
     1479        rect.top = dis->rcItem.top;
     1480        rect.bottom = dis->rcItem.bottom;
     1481        DrawFocusRect(dis->hDC, &rect);
    17221482    }
    17231483
     
    17261486
    17271487
    1728 static LRESULT
    1729 COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1730 {
    1731     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    1732 
     1488static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
     1489{
    17331490    if (infoPtr->hwndCombo)
    17341491        DestroyWindow (infoPtr->hwndCombo);
     
    17401497
    17411498    if (infoPtr->items) {
    1742         CBE_ITEMDATA *this, *next;
    1743 
    1744         this = infoPtr->items;
    1745         while (this) {
    1746             next = (CBE_ITEMDATA *)this->next;
    1747             if ((this->mask & CBEIF_TEXT) && this->pszText)
    1748                 COMCTL32_Free (this->pszText);
    1749             COMCTL32_Free (this);
    1750             this = next;
    1751         }
    1752     }
    1753 
    1754     if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
     1499        CBE_ITEMDATA *item, *next;
     1500
     1501        item = infoPtr->items;
     1502        while (item) {
     1503            next = (CBE_ITEMDATA *)item->next;
     1504            COMBOEX_FreeText (item);
     1505            COMCTL32_Free (item);
     1506            item = next;
     1507        }
     1508        infoPtr->items = 0;
     1509    }
     1510
     1511    if (infoPtr->defaultFont)
     1512        DeleteObject (infoPtr->defaultFont);
    17551513
    17561514    /* free comboex info data */
    17571515    COMCTL32_Free (infoPtr);
    1758     SetWindowLongA (hwnd, 0, 0);
     1516    SetWindowLongW (infoPtr->hwndSelf, 0, 0);
    17591517    return 0;
    17601518}
    17611519
    17621520
    1763 static LRESULT
    1764 COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1765 {
    1766     /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
    1767     MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
     1521static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
     1522{
     1523    SIZE mysize;
    17681524    HDC hdc;
    1769     SIZE mysize;
    17701525
    17711526    hdc = GetDC (0);
     
    17751530
    17761531    TRACE("adjusted height hwnd=%08x, height=%d\n",
    1777           hwnd, mis->itemHeight);
     1532          infoPtr->hwndSelf, mis->itemHeight);
    17781533
    17791534    return 0;
     
    17811536
    17821537
    1783 static LRESULT
    1784 COMBOEX_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
     1538static LRESULT COMBOEX_NCCreate (HWND hwnd)
    17851539{
    17861540    /* WARNING: The COMBOEX_INFO structure is not yet created */
    17871541    DWORD oldstyle, newstyle;
    17881542
    1789     oldstyle = (DWORD)GetWindowLongA (hwnd, GWL_STYLE);
     1543    oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
    17901544    newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
    17911545    if (newstyle != oldstyle) {
    17921546        TRACE("req style %08lx, reseting style %08lx\n",
    17931547              oldstyle, newstyle);
    1794         SetWindowLongA (hwnd, GWL_STYLE, newstyle);
     1548        SetWindowLongW (hwnd, GWL_STYLE, newstyle);
    17951549    }
    17961550    return 1;
     
    17981552
    17991553
    1800 static LRESULT
    1801 COMBOEX_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1802 {
    1803     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    1804     INT i;
    1805 
     1554static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
     1555{
    18061556    if (lParam == NF_REQUERY) {
    1807         i = SendMessageA(GetParent (hwnd),
     1557        INT i = SendMessageW(GetParent (infoPtr->hwndSelf),
    18081558                         WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
    1809         if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
    1810             ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
    1811                 i);
    1812             i = NFR_ANSI;
    1813         }
    18141559        infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
    1815         return (LRESULT)i;
    1816     }
    1817     return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
    1818 }
    1819 
    1820 
    1821 static LRESULT
    1822 COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1823 {
    1824     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
    1825     RECT rect;
    1826 
    1827     GetWindowRect (hwnd, &rect);
    1828     TRACE("my rect (%d,%d)-(%d,%d)\n",
    1829           rect.left, rect.top, rect.right, rect.bottom);
    1830 
    1831     MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
    1832                   rect.bottom - rect.top, TRUE);
     1560    }
     1561    return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
     1562}
     1563
     1564
     1565static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
     1566{
     1567    TRACE("(width=%d, height=%d)\n", width, height);
     1568
     1569    MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
    18331570
    18341571    COMBOEX_AdjustEditPos (infoPtr);
     
    18381575
    18391576
    1840 static LRESULT
    1841 COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
    1842 {
    1843     COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
     1577static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
     1578{
    18441579    RECT cbx_wrect, cbx_crect, cb_wrect;
    18451580    UINT width, height;
    1846     WINDOWPOS *wp = (WINDOWPOS *)lParam;
    1847 
    1848     GetWindowRect (hwnd, &cbx_wrect);
    1849     GetClientRect (hwnd, &cbx_crect);
     1581
     1582    GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
     1583    GetClientRect (infoPtr->hwndSelf, &cbx_crect);
    18501584    GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
    18511585
     
    18881622COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    18891623{
    1890     COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
     1624    HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
     1625    COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
    18911626    NMCBEENDEDITW cbeend;
    18921627    WCHAR edit_text[260];
    1893     COLORREF nbkc, obkc;
     1628    COLORREF obkc;
    18941629    HDC hDC;
    18951630    RECT rect;
     
    19041639    {
    19051640
    1906     case WM_CHAR:
     1641        case WM_CHAR:
    19071642            /* handle (ignore) the return character */
    19081643            if (wParam == VK_RETURN) return 0;
    19091644            /* all other characters pass into the real Edit */
    1910             return CallWindowProcA (infoPtr->prevEditWndProc,
     1645            return CallWindowProcW (infoPtr->prevEditWndProc,
    19111646                                   hwnd, uMsg, wParam, lParam);
    19121647
    1913     case WM_ERASEBKGND:
     1648        case WM_ERASEBKGND:
    19141649            /*
    19151650             * The following was determined by traces of the native
    19161651             */
    19171652            hDC = (HDC) wParam;
    1918             nbkc = GetSysColor (COLOR_WINDOW);
    1919             obkc = SetBkColor (hDC, nbkc);
     1653            obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
    19201654            GetClientRect (hwnd, &rect);
    19211655            TRACE("erasing (%d,%d)-(%d,%d)\n",
     
    19231657            ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
    19241658            SetBkColor (hDC, obkc);
    1925             return CallWindowProcA (infoPtr->prevEditWndProc,
     1659            return CallWindowProcW (infoPtr->prevEditWndProc,
    19261660                                   hwnd, uMsg, wParam, lParam);
    19271661
    1928     case WM_KEYDOWN: {
    1929             INT oldItem, selected;
     1662        case WM_KEYDOWN: {
     1663            INT oldItem, selected, step = 1;
    19301664            CBE_ITEMDATA *item;
    19311665
     
    19601694                cbeend.iWhy = CBENF_ESCAPE;
    19611695
    1962                 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
    1963                     /* abort the change */
    1964                     TRACE("Notify requested abort of change\n");
    1965                     return 0;
    1966                 }
    1967                 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
     1696                if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
     1697                oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
    19681698                InvalidateRect (infoPtr->hwndCombo, 0, 0);
    19691699                if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
     
    20101740                    item = COMBOEX_FindItem (infoPtr, selected);
    20111741                    TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
    2012                           selected, debugstr_w(item->pszText));
     1742                          selected, debugstr_txt(item->pszText));
    20131743                    TRACE("handling VK_RETURN, edittext=%s\n",
    20141744                          debugstr_w(edit_text));
    2015                     if (lstrcmpiW (item->pszText, edit_text)) {
     1745                    if (lstrcmpiW (COMBOEX_GetText(infoPtr, item), edit_text)) {
    20161746                        /* strings not equal -- indicate edit has changed */
    20171747                        selected = -1;
     
    20401770                break;
    20411771
     1772            case VK_UP:
     1773                step = -1;
     1774            case VK_DOWN:
     1775                /* by default, step is 1 */
     1776                oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
     1777                if (oldItem >= 0 && oldItem + step >= 0)
     1778                    SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
     1779                return 0;
    20421780            default:
    2043                 return CallWindowProcA (infoPtr->prevEditWndProc,
     1781                return CallWindowProcW (infoPtr->prevEditWndProc,
    20441782                                       hwnd, uMsg, wParam, lParam);
    20451783            }
     
    20471785            }
    20481786
    2049     case WM_SETFOCUS:
     1787        case WM_SETFOCUS:
    20501788            /* remember the focus to set state of icon */
    2051             lret = CallWindowProcA (infoPtr->prevEditWndProc,
     1789            lret = CallWindowProcW (infoPtr->prevEditWndProc,
    20521790                                   hwnd, uMsg, wParam, lParam);
    20531791            infoPtr->flags |= WCBE_EDITFOCUSED;
    20541792            return lret;
    20551793
    2056     case WM_KILLFOCUS:
     1794        case WM_KILLFOCUS:
    20571795            /*
    20581796             * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
     
    20721810            /* fall through */
    20731811
    2074     default:
    2075             return CallWindowProcA (infoPtr->prevEditWndProc,
     1812        default:
     1813            return CallWindowProcW (infoPtr->prevEditWndProc,
    20761814                                   hwnd, uMsg, wParam, lParam);
    20771815    }
     
    20831821COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    20841822{
    2085     COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
     1823    HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
     1824    COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
    20861825    NMCBEENDEDITW cbeend;
    20871826    NMMOUSE nmmse;
    2088     COLORREF nbkc, obkc;
     1827    COLORREF obkc;
    20891828    HDC hDC;
    20901829    HWND focusedhwnd;
     
    21011840
    21021841    case CB_FINDSTRINGEXACT:
    2103             return COMBOEX_FindStringExact (infoPtr, wParam, lParam);
     1842            return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCSTR)lParam);
    21041843
    21051844    case WM_DRAWITEM:
     
    21101849             */
    21111850            ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
    2112             return CallWindowProcA (infoPtr->prevComboWndProc,
     1851            return CallWindowProcW (infoPtr->prevComboWndProc,
    21131852                                   hwnd, uMsg, wParam, lParam);
    21141853
     
    21181857             */
    21191858            hDC = (HDC) wParam;
    2120             nbkc = GetSysColor (COLOR_WINDOW);
    2121             obkc = SetBkColor (hDC, nbkc);
     1859            obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
    21221860            GetClientRect (hwnd, &rect);
    21231861            TRACE("erasing (%d,%d)-(%d,%d)\n",
     
    21251863            ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
    21261864            SetBkColor (hDC, obkc);
    2127             return CallWindowProcA (infoPtr->prevComboWndProc,
     1865            return CallWindowProcW (infoPtr->prevComboWndProc,
    21281866                                   hwnd, uMsg, wParam, lParam);
    21291867
     
    21401878            nmmse.dwHitInfo = lParam;
    21411879            COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
    2142             return CallWindowProcA (infoPtr->prevComboWndProc,
     1880            return CallWindowProcW (infoPtr->prevComboWndProc,
    21431881                                   hwnd, uMsg, wParam, lParam);
    21441882
     
    21741912
    21751913                    infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
    2176                     if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
    2177                         /* abort the change */
    2178                         TRACE("Notify requested abort of change\n");
    2179                         return 0;
    2180                     }
     1914                    if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
    21811915                }
    21821916                /* possible CB_GETCURSEL */
     
    22191953                 */
    22201954                WCHAR edit_text[260];
    2221                 WCHAR *lastwrk;
    2222                 INT selected, cnt;
     1955                LPCWSTR lastwrk;
     1956                INT selected;
    22231957                CBE_ITEMDATA *item;
    22241958
     
    22311965                if (selected == -1) {
    22321966                    lastwrk = infoPtr->edit->pszText;
    2233                     cnt = lstrlenW (lastwrk);
    2234                     if (cnt >= 259) cnt = 259;
    22351967                }
    22361968                else {
    22371969                    item = COMBOEX_FindItem (infoPtr, selected);
    2238                     cnt = lstrlenW (item->pszText);
    2239                     lastwrk = item->pszText;
    2240                     if (cnt >= 259) cnt = 259;
     1970                    lastwrk = COMBOEX_GetText(infoPtr, item);
    22411971                }
    22421972
    22431973                TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
    2244                     selected, debugstr_w(lastwrk));
     1974                      selected, debugstr_w(lastwrk));
    22451975                TRACE("handling EN_CHANGE, edittext=%s\n",
    22461976                      debugstr_w(edit_text));
    22471977
    22481978                /* lstrcmpiW is between lastworkingURL and GetWindowText */
    2249 
    22501979                if (lstrcmpiW (lastwrk, edit_text)) {
    22511980                    /* strings not equal -- indicate edit has changed */
     
    22952024            }/* fall through */
    22962025    default:
    2297             return CallWindowProcA (infoPtr->prevComboWndProc,
     2026            return CallWindowProcW (infoPtr->prevComboWndProc,
    22982027                                   hwnd, uMsg, wParam, lParam);
    22992028    }
     
    23092038    TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
    23102039
    2311     if (!COMBOEX_GetInfoPtr (hwnd)) {
     2040    if (!infoPtr) {
    23122041        if (uMsg == WM_CREATE)
    2313             return COMBOEX_Create (hwnd, wParam, lParam);
     2042            return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
    23142043        if (uMsg == WM_NCCREATE)
    2315             COMBOEX_NCCreate (hwnd, wParam, lParam);
    2316         return DefWindowProcA (hwnd, uMsg, wParam, lParam);
     2044            COMBOEX_NCCreate (hwnd);
     2045        return DefWindowProcW (hwnd, uMsg, wParam, lParam);
    23172046    }
    23182047
    23192048    switch (uMsg)
    23202049    {
    2321         case CBEM_DELETEITEM:  /* maps to CB_DELETESTRING */
    2322             return COMBOEX_DeleteItem (hwnd, wParam, lParam);
     2050        case CBEM_DELETEITEM:
     2051            return COMBOEX_DeleteItem (infoPtr, wParam);
    23232052
    23242053        case CBEM_GETCOMBOCONTROL:
    2325             return COMBOEX_GetComboControl (hwnd, wParam, lParam);
     2054            return infoPtr->hwndCombo;
    23262055
    23272056        case CBEM_GETEDITCONTROL:
    2328             return COMBOEX_GetEditControl (hwnd, wParam, lParam);
     2057            return infoPtr->hwndEdit;
    23292058
    23302059        case CBEM_GETEXTENDEDSTYLE:
    2331             return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
     2060            return infoPtr->dwExtStyle;
    23322061
    23332062        case CBEM_GETIMAGELIST:
    2334             return COMBOEX_GetImageList (hwnd, wParam, lParam);
     2063            return (LRESULT)infoPtr->himl;
    23352064
    23362065        case CBEM_GETITEMA:
    2337             return COMBOEX_GetItemA (hwnd, wParam, lParam);
     2066            return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
    23382067
    23392068        case CBEM_GETITEMW:
    2340             return COMBOEX_GetItemW (hwnd, wParam, lParam);
     2069            return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
    23412070
    23422071        case CBEM_GETUNICODEFORMAT:
    2343             return COMBOEX_GetUnicodeFormat (hwnd, wParam, lParam);
     2072            return infoPtr->unicode;
    23442073
    23452074        case CBEM_HASEDITCHANGED:
    2346             return COMBOEX_HasEditChanged (hwnd, wParam, lParam);
     2075            return COMBOEX_HasEditChanged (infoPtr);
    23472076
    23482077        case CBEM_INSERTITEMA:
    2349             return COMBOEX_InsertItemA (hwnd, wParam, lParam);
     2078            return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
    23502079
    23512080        case CBEM_INSERTITEMW:
    2352             return COMBOEX_InsertItemW (hwnd, wParam, lParam);
    2353 
    2354         case CBEM_SETEXSTYLE:   /* FIXME: obsoleted, should be the same as: */
     2081            return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
     2082
     2083        case CBEM_SETEXSTYLE:
    23552084        case CBEM_SETEXTENDEDSTYLE:
    2356             return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
     2085            return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
    23572086
    23582087        case CBEM_SETIMAGELIST:
    2359             return COMBOEX_SetImageList (hwnd, wParam, lParam);
     2088            return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
    23602089
    23612090        case CBEM_SETITEMA:
    2362             return COMBOEX_SetItemA (hwnd, wParam, lParam);
     2091            return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
    23632092
    23642093        case CBEM_SETITEMW:
    2365             return COMBOEX_SetItemW (hwnd, wParam, lParam);
     2094            return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
    23662095
    23672096        case CBEM_SETUNICODEFORMAT:
    2368             return COMBOEX_SetUnicodeFormat (hwnd, wParam, lParam);
    2369 
     2097            return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
     2098
     2099        /*case CBEM_SETWINDOWTHEME:
     2100            FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
    23702101
    23712102/*   Combo messages we are not sure if we need to process or just forward */
     
    23822113            FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
    23832114                  uMsg, wParam, lParam);
    2384             return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
    23852115
    23862116/*   Combo messages OK to just forward to the regular COMBO */
     
    23912121        case CB_SETEXTENDEDUI:
    23922122        case CB_SHOWDROPDOWN:
    2393             return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
     2123            return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
    23942124
    23952125/*   Combo messages we need to process specially */
    23962126        case CB_FINDSTRINGEXACT:
    2397             return COMBOEX_FindStringExact (COMBOEX_GetInfoPtr (hwnd),
    2398                                             wParam, lParam);
     2127            return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCSTR)lParam);
    23992128
    24002129        case CB_GETITEMDATA:
    2401             return COMBOEX_GetItemData (hwnd, wParam, lParam);
     2130            return COMBOEX_GetItemData (infoPtr, (INT)wParam);
    24022131
    24032132        case CB_SETCURSEL:
    2404             return COMBOEX_SetCursel (hwnd, wParam, lParam);
     2133            return COMBOEX_SetCursel (infoPtr, (INT)wParam);
    24052134
    24062135        case CB_SETITEMDATA:
    2407             return COMBOEX_SetItemData (hwnd, wParam, lParam);
     2136            return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD)lParam);
    24082137
    24092138        case CB_SETITEMHEIGHT:
    2410             return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
     2139            return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
    24112140
    24122141
     
    24142143/*   Window messages passed to parent */
    24152144        case WM_COMMAND:
    2416             return COMBOEX_Command (hwnd, wParam, lParam);
     2145            return COMBOEX_Command (infoPtr, wParam, lParam);
    24172146
    24182147        case WM_NOTIFY:
    24192148            if (infoPtr->NtfUnicode)
    2420                 return SendMessageW (GetParent (hwnd),
    2421                                      uMsg, wParam, lParam);
     2149                return SendMessageW (GetParent (hwnd), uMsg, wParam, lParam);
    24222150            else
    2423                 return SendMessageA (GetParent (hwnd),
    2424                                      uMsg, wParam, lParam);
     2151                return SendMessageA (GetParent (hwnd), uMsg, wParam, lParam);
    24252152
    24262153
    24272154/*   Window messages we need to process */
    24282155        case WM_DELETEITEM:
    2429             return COMBOEX_WM_DeleteItem (hwnd, wParam, lParam);
     2156            return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
    24302157
    24312158        case WM_DRAWITEM:
    2432             return COMBOEX_DrawItem (hwnd, wParam, lParam);
     2159            return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
    24332160
    24342161        case WM_DESTROY:
    2435             return COMBOEX_Destroy (hwnd, wParam, lParam);
     2162            return COMBOEX_Destroy (infoPtr);
    24362163
    24372164        case WM_MEASUREITEM:
    2438             return COMBOEX_MeasureItem (hwnd, wParam, lParam);
     2165            return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
    24392166
    24402167        case WM_NOTIFYFORMAT:
    2441             return COMBOEX_NotifyFormat (hwnd, wParam, lParam);
     2168            return COMBOEX_NotifyFormat (infoPtr, lParam);
    24422169
    24432170        case WM_SIZE:
    2444             return COMBOEX_Size (hwnd, wParam, lParam);
     2171            return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
    24452172
    24462173        case WM_WINDOWPOSCHANGING:
    2447             return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
     2174            return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
    24482175
    24492176        default:
    24502177            if (uMsg >= WM_USER)
    2451                 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
    2452                      uMsg, wParam, lParam);
    2453             return DefWindowProcA (hwnd, uMsg, wParam, lParam);
     2178                ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
     2179            return DefWindowProcW (hwnd, uMsg, wParam, lParam);
    24542180    }
    24552181    return 0;
     
    24572183
    24582184
    2459 VOID
    2460 COMBOEX_Register (void)
    2461 {
    2462     WNDCLASSA wndClass;
    2463 
    2464     ZeroMemory (&wndClass, sizeof(WNDCLASSA));
     2185void COMBOEX_Register (void)
     2186{
     2187    WNDCLASSW wndClass;
     2188
     2189    ZeroMemory (&wndClass, sizeof(WNDCLASSW));
    24652190    wndClass.style         = CS_GLOBALCLASS;
    24662191    wndClass.lpfnWndProc   = (WNDPROC)COMBOEX_WindowProc;
    24672192    wndClass.cbClsExtra    = 0;
    24682193    wndClass.cbWndExtra    = sizeof(COMBOEX_INFO *);
    2469     wndClass.hCursor       = LoadCursorA (0, IDC_ARROWA);
     2194    wndClass.hCursor       = LoadCursorW (0, IDC_ARROWW);
    24702195    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    2471     wndClass.lpszClassName = WC_COMBOBOXEXA;
     2196    wndClass.lpszClassName = WC_COMBOBOXEXW;
    24722197 
    2473     RegisterClassA (&wndClass);
    2474 
    2475     ComboExInfo = GlobalAddAtomA("CC32SubclassInfo");
    2476 }
    2477 
    2478 
    2479 VOID
    2480 COMBOEX_Unregister (void)
    2481 {
    2482     UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);
    2483 }
    2484 
     2198    RegisterClassW (&wndClass);
     2199}
     2200
     2201
     2202void COMBOEX_Unregister (void)
     2203{
     2204    UnregisterClassW (WC_COMBOBOXEXW, (HINSTANCE)NULL);
     2205}
     2206
  • trunk/src/comctl32/comctl32.def

    r7815 r8382  
    1 ; $Id: comctl32.def,v 1.25 2002-02-06 17:23:18 sandervl Exp $
     1; $Id: comctl32.def,v 1.26 2002-05-08 11:24:59 sandervl Exp $
    22LIBRARY COMCTL32 INITINSTANCE
    33DESCRIPTION 'Odin32 System DLL - ComCtl32 - Common Controls Library'
     
    1515  DPA_SaveStream               = _DPA_SaveStream@16                  @10
    1616  DPA_Merge                    = _DPA_Merge@24                       @11
    17   CreatePropertySheetPage      = _CreatePropertySheetPageA@4         @12
     17;;12 stub Cctl1632_ThunkData32
    1818  MakeDragList                 = _MakeDragList@4                     @13
    1919  LBItemFromPt                 = _LBItemFromPt@16                    @14
     
    107107  CreateMRUListLazyA  = _CreateMRUListLazyA@16     @157
    108108
     109;;163 stub CreatePage
     110;;164 stub CreateProxyPage
     111
    109112  AddMRUData          = _AddMRUData@12             @167
    110113  FindMRUData         = _FindMRUData@16            @169
  • trunk/src/comctl32/comctl32.h

    r7815 r8382  
    1 /* $Id: comctl32.h,v 1.21 2002-02-06 17:23:18 sandervl Exp $ */
    2 /*
    3  * Win32 common controls implementation
     1/******************************************************************************
     2 *
     3 * Common definitions (resource ids and global variables)
    44 *
    5  * Copyright (C) 1999 Achim Hasenmueller
     5 * Copyright 1999 Thuy Nguyen
     6 * Copyright 1999 Eric Kohl
    67 *
    7  * Based on the work of the WINE group (www.winehq.com)
     8 * This library is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
    812 *
     13 * This library is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
    917 *
    10  * Project Odin Software License can be found in LICENSE.TXT
    11  *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with this library; if not, write to the Free Software
     20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1221 */
    1322
    14 /* Status: Corel WINE 20000807 */
    15 
    16 #ifndef _H_COMCTL32
    17 #define _H_COMCTL32
    18 
    19 #include "winbase.h"
    20 #include "wingdi.h"
    21 #include "winuser.h"
    22 #include <win/commctrl.h>
    23 #include "unicode.h"
    24 
    25 #define _OS2WIN_H
    26 #define NO_ULONG
    27 #include <misc.h>
    28 
    29 #ifndef __cplusplus
    30 #undef inline
    31 #define inline
    32 #endif
    33 
    34 extern HBRUSH  COMCTL32_hPattern55AABrush;
    35 
    36 #ifdef __cplusplus
    37 extern "C" {
    38 #endif
    39 
    40 /* registers window classes inside this DLL */
    41 void CDECL RegisterCOMCTL32WindowClasses(unsigned long hinstDLL);
    42 void CDECL UnregisterCOMCTL32WindowClasses(void);
    43 #ifdef __cplusplus
    44 }
    45 #endif
    46 
    47 // string functions from kernel32
    48 LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str );
    49 LPSTR  WIN32API HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str );
    50 
    51 
    52 /**************************************************************************
    53  *  UNDOCUMENTED functions
    54  */
    55 
    56 /* private heap memory functions */
    57 
    58 LPVOID WINAPI COMCTL32_Alloc (DWORD);
    59 LPVOID WINAPI COMCTL32_ReAlloc (LPVOID, DWORD);
    60 BOOL WINAPI COMCTL32_Free (LPVOID);
    61 DWORD  WINAPI COMCTL32_GetSize (LPVOID);
    62 
     23#ifndef __WINE_COMCTL32_H
     24#define __WINE_COMCTL32_H
    6325
    6426extern HMODULE COMCTL32_hModule;
     27extern HBRUSH  COMCTL32_hPattern55AABrush;
    6528
    6629/* Property sheet / Wizard */
     
    7538#define IDC_SUNKEN_LINE   12326
    7639
    77 #define IDS_CLOSE 4160
     40#define IDS_CLOSE        4160
    7841
    7942/* Toolbar customization dialog */
     
    9861#define IDB_HIST_LARGE      131
    9962
    100 //direction bitmaps
    101 #define IDB_DIRECTION_ALL   132
    102 #define IDB_DIRECTION_NS    133
    103 #define IDB_DIRECTION WE    134
    104 
    105 //Header filter bitmap
    106 #define IDB_HEADER_FILTER   140
    107 
    108 //cursors
    109 #define IDC_COMCTL32_ERROR       20480
    110 #define IDC_COMCTL32_INFORMATION 20481
    111 #define IDC_COMCTL32_EXCLAMATION 20482
    112 
    113 #define IDC_COMCTL32_DRAGRECT      102
    114 #define IDC_COMCTL32_ARROW1        104
    115 #define IDC_COMCTL32_ARROW2        105
    116 #define IDC_COMCTL32_DRAGHLINE     106
    117 #define IDC_COMCTL32_SPLITHLINE    107
    118 #define IDC_COMCTL32_HAND          108
    119 #define IDC_COMCTL32_DIRECTION_NS  109
    120 #define IDC_COMCTL32_DIRECTION_WE  110
    121 #define IDC_COMCTL32_DIRECTION_ALL 111
    122 #define IDC_COMCTL32_DIRECTION_N   112
    123 #define IDC_COMCTL32_DIRECTION_S   113
    124 #define IDC_COMCTL32_DIRECTION_E   114
    125 #define IDC_COMCTL32_DIRECTION_W   115
    126 #define IDC_COMCTL32_DIRECTION_NE  116
    127 #define IDC_COMCTL32_DIRECTION_NW  117
    128 #define IDC_COMCTL32_DIRECTION_SE  118
    129 #define IDC_COMCTL32_DIRECTION_SW  119
    130 
    131 #define IDC_COMCTL32_SPLITVLINE    135
    132 #define IDC_COMCTL32_ENTER         150
    13363
    13464/* Month calendar month menu popup */
    13565#define IDD_MCMONTHMENU     300
    13666
    137 #define IDM_JAN                         301
    138 #define IDM_FEB                         302
    139 #define IDM_MAR                         303
    140 #define IDM_APR                         304
    141 #define IDM_MAY                         305
    142 #define IDM_JUN                         306
    143 #define IDM_JUL                         307
    144 #define IDM_AUG                         308
    145 #define IDM_SEP                         309
    146 #define IDM_OCT                         310
    147 #define IDM_NOV                         311
    148 #define IDM_DEC                         312
     67#define IDM_JAN                         301
     68#define IDM_FEB                         302
     69#define IDM_MAR                         303
     70#define IDM_APR                         304
     71#define IDM_MAY                         305
     72#define IDM_JUN                         306
     73#define IDM_JUL                         307
     74#define IDM_AUG                         308
     75#define IDM_SEP                         309
     76#define IDM_OCT                         310
     77#define IDM_NOV                         311
     78#define IDM_DEC                         312
    14979
    15080#define IDM_TODAY                      4163
     
    16090#define IDC_DIVIDEROPEN                 107
    16191
     92#ifdef __WIN32OS2__
     93/* Header filter bitmap */
     94#define IDB_HEADER_FILTER   140
     95
     96#define IDC_COMCTL32_DRAGHLINE     106
     97#define IDC_COMCTL32_SPLITHLINE    107
     98
     99#endif
    162100
    163101/* DragList icon */
    164102#define IDI_DRAGARROW                   150
     103
     104typedef struct
     105{
     106    COLORREF clrBtnHighlight;       /* COLOR_BTNHIGHLIGHT                  */
     107    COLORREF clrBtnShadow;          /* COLOR_BTNSHADOW                     */
     108    COLORREF clrBtnText;            /* COLOR_BTNTEXT                       */
     109    COLORREF clrBtnFace;            /* COLOR_BTNFACE                       */
     110    COLORREF clrHighlight;          /* COLOR_HIGHLIGHT                     */
     111    COLORREF clrHighlightText;      /* COLOR_HIGHLIGHTTEXT                 */
     112    COLORREF clr3dHilight;          /* COLOR_3DHILIGHT                     */
     113    COLORREF clr3dShadow;           /* COLOR_3DSHADOW                      */
     114    COLORREF clr3dDkShadow;         /* COLOR_3DDKSHADOW                    */
     115    COLORREF clr3dFace;             /* COLOR_3DFACE                        */
     116    COLORREF clrWindow;             /* COLOR_WINDOW                        */
     117    COLORREF clrWindowText;         /* COLOR_WINDOWTEXT                    */
     118    COLORREF clrGrayText;           /* COLOR_GREYTEXT                      */
     119    COLORREF clrActiveCaption;      /* COLOR_ACTIVECAPTION                 */
     120    COLORREF clrInfoBk;             /* COLOR_INFOBK                        */
     121    COLORREF clrInfoText;           /* COLOR_INFOTEXT                      */
     122} COMCTL32_SysColor;
     123
     124extern COMCTL32_SysColor  comctl32_color;
     125
     126/* Internal function */
     127HWND COMCTL32_CreateToolTip (HWND);
     128VOID COMCTL32_RefreshSysColors(void);
     129INT  Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen);
     130BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc);
    165131
    166132#define COMCTL32_VERSION_MINOR 0
     
    168134#define WINE_FILEVERSIONSTR "5.00"
    169135
    170 #define UINT_PTR DWORD
    171 
     136#ifdef __WIN32OS2__
     137#define swprintf   wsprintfW
    172138#ifdef __cplusplus
    173139extern "C" {
     
    216182
    217183
    218 INT  Str_GetPtrWtoA (LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen);
    219 BOOL Str_SetPtrAtoW (LPWSTR *lppDest, LPCSTR lpSrc);
    220 
    221184#ifdef __cplusplus
    222185}
    223186#endif
     187#endif
    224188
    225 #endif /* _H_COMCTL32 */
     189#endif  /* __WINE_COMCTL32_H */
  • trunk/src/comctl32/comctl32dbg.def

    r7921 r8382  
    1 ; $Id: comctl32dbg.def,v 1.1 2002-02-15 15:39:29 sandervl Exp $
     1; $Id: comctl32dbg.def,v 1.2 2002-05-08 11:24:59 sandervl Exp $
    22LIBRARY COMCTL32 INITINSTANCE
    33DESCRIPTION 'Odin32 System DLL - ComCtl32 - Common Controls Library'
     
    1515  DPA_SaveStream               = _DbgDPA_SaveStream@16                  @10
    1616  DPA_Merge                    = _DbgDPA_Merge@24                       @11
    17   CreatePropertySheetPage      = _DbgCreatePropertySheetPageA@4         @12
     17;;12 stub Cctl1632_ThunkData32
    1818  MakeDragList                 = _DbgMakeDragList@4                     @13
    1919  LBItemFromPt                 = _DbgLBItemFromPt@16                    @14
  • trunk/src/comctl32/comctl32undoc.c

    r7815 r8382  
    55 *           1998 Juergen Schmied <j.schmied@metronet.de>
    66 *           2000 Eric Kohl for CodeWeavers
     7 *
     8 * This library is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * This library is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with this library; if not, write to the Free Software
     20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    721 *
    822 * NOTES
     
    3448#include "comctl32.h"
    3549
    36 #include "debugtools.h"
    37 
    38 DEFAULT_DEBUG_CHANNEL(commctrl);
     50#include "wine/debug.h"
     51
     52WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
    3953
    4054
     
    206220    INT nCount;
    207221    LPVOID *pWork1, *pWork2;
    208     INT nResult;
     222    INT nResult, i;
    209223    INT nIndex;
    210224
     
    224238        return FALSE;
    225239
    226     if (dwFlags & DPAM_SORT) {
     240    if (!(dwFlags & DPAM_NOSORT)) {
    227241        TRACE("sorting dpa's!\n");
    228242        if (hdpa1->nItemCount > 0)
     
    251265    do
    252266    {
    253         if (nIndex < 0) break;
     267        if (nIndex < 0) {
     268            if ((nCount >= 0) && (dwFlags & DPAM_INSERT)) {
     269                /* Now insert the remaining new items into DPA 1 */
     270                TRACE("%d items to be inserted at start of DPA 1\n",
     271                      nCount+1);
     272                for (i=nCount; i>=0; i--) {
     273                    PVOID ptr;
     274
     275                    ptr = (pfnMerge)(3, *pWork2, NULL, lParam);
     276                    if (!ptr)
     277                        return FALSE;
     278                    DPA_InsertPtr (hdpa1, 0, ptr);
     279                    pWork2--;
     280                }
     281            }
     282            break;
     283        }
    254284        nResult = (pfnCompare)(*pWork1, *pWork2, lParam);
    255285        TRACE("compare result=%d, dpa1.cnt=%d, dpa2.cnt=%d\n",
     
    270300            pWork1--;
    271301        }
    272         else if (nResult < 0)
     302        else if (nResult > 0)
    273303        {
    274             if (!(dwFlags & 8))
     304            /* item in DPA 1 missing from DPA 2 */
     305            if (dwFlags & DPAM_DELETE)
    275306            {
     307                /* Now delete the extra item in DPA1 */
    276308                PVOID ptr;
    277309
     
    285317        else
    286318        {
    287             if (!(dwFlags & 4))
     319            /* new item in DPA 2 */
     320            if (dwFlags & DPAM_INSERT)
    288321            {
     322                /* Now insert the new item in DPA 1 */
    289323                PVOID ptr;
    290324
     
    292326                if (!ptr)
    293327                    return FALSE;
    294                 DPA_InsertPtr (hdpa1, nIndex, ptr);
     328                DPA_InsertPtr (hdpa1, nIndex+1, ptr);
    295329            }
    296330            nCount--;
     
    28002834   return TRUE;
    28012835}
    2802 
  • trunk/src/comctl32/commctrl.c

    r7815 r8382  
    55 * Copyright 1998,2000 Eric Kohl
    66 *
     7 * This library is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU Lesser General Public
     9 * License as published by the Free Software Foundation; either
     10 * version 2.1 of the License, or (at your option) any later version.
     11 *
     12 * This library is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15 * Lesser General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU Lesser General Public
     18 * License along with this library; if not, write to the Free Software
     19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    720 */
    821
     
    1730#include "shlwapi.h"
    1831#include "comctl32.h"
    19 #include "debugtools.h"
    20 
    21 DEFAULT_DEBUG_CHANNEL(commctrl);
     32#include "wine/debug.h"
     33
     34WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
    2235
    2336extern void ANIMATE_Register(void);
     
    6881LANGID  COMCTL32_uiLang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
    6982HBRUSH  COMCTL32_hPattern55AABrush = (HANDLE)NULL;
     83COMCTL32_SysColor  comctl32_color;
    7084
    7185static HBITMAP COMCTL32_hPattern55AABitmap = (HANDLE)NULL;
     
    111125            COMCTL32_hPattern55AABitmap = CreateBitmap (8, 8, 1, 1, wPattern55AA);
    112126            COMCTL32_hPattern55AABrush = CreatePatternBrush (COMCTL32_hPattern55AABitmap);
     127
     128            /* Get all the colors at DLL load */
     129            COMCTL32_RefreshSysColors();
    113130
    114131            /* register all Win95 common control classes */
     
    396413 */
    397414
    398 VOID WINAPI
    399 DrawStatusTextW (HDC hdc, LPRECT lprc, LPCWSTR text, UINT style)
     415void WINAPI DrawStatusTextW (HDC hdc, LPRECT lprc, LPCWSTR text, UINT style)
    400416{
    401417    RECT r = *lprc;
     
    403419
    404420    if (style & SBT_POPOUT)
    405       border = BDR_RAISEDOUTER;
     421        border = BDR_RAISEDOUTER;
    406422    else if (style & SBT_NOBORDERS)
    407       border = 0;
    408 
    409     DrawEdge (hdc, &r, border, BF_RECT|BF_ADJUST|BF_MIDDLE);
     423        border = 0;
     424
     425    DrawEdge (hdc, &r, border, BF_RECT|BF_ADJUST);
    410426
    411427    /* now draw text */
    412428    if (text) {
    413       int oldbkmode = SetBkMode (hdc, TRANSPARENT);
    414       r.left += 3;
    415       DrawTextW (hdc, text, lstrlenW(text),
    416                    &r, DT_LEFT|DT_VCENTER|DT_SINGLELINE); 
    417       if (oldbkmode != TRANSPARENT)
     429        int oldbkmode = SetBkMode (hdc, TRANSPARENT);
     430        UINT align = DT_LEFT;
     431        if (*text == L'\t') {
     432            text++;
     433            align = DT_CENTER;
     434            if (*text == L'\t') {
     435                text++;
     436                align = DT_RIGHT;
     437            }
     438        }
     439        r.left += 3;
     440        if (style & SBT_RTLREADING)
     441            FIXME("Usupported RTL style!");
     442        DrawTextW (hdc, text, -1, &r, align|DT_VCENTER|DT_SINGLELINE);
    418443        SetBkMode(hdc, oldbkmode);
    419444    }
     
    437462 */
    438463
    439 VOID WINAPI
    440 DrawStatusTextA (HDC hdc, LPRECT lprc, LPCSTR text, UINT style)
     464void WINAPI DrawStatusTextA (HDC hdc, LPRECT lprc, LPCSTR text, UINT style)
    441465{
    442466    INT len;
     
    10151039    return hwndToolTip;
    10161040}
     1041
     1042
     1043/***********************************************************************
     1044 * COMCTL32_RefreshSysColors [NOT AN API]
     1045 *
     1046 * Invoked on any control recognizing a WM_SYSCOLORCHANGE message to
     1047 * refresh the color values in the color structure
     1048 *
     1049 * PARAMS
     1050 *     none
     1051 *
     1052 * RETURNS
     1053 *     none
     1054 */
     1055VOID
     1056COMCTL32_RefreshSysColors(void)
     1057{
     1058    comctl32_color.clrBtnHighlight = GetSysColor (COLOR_BTNHIGHLIGHT);
     1059    comctl32_color.clrBtnShadow = GetSysColor (COLOR_BTNSHADOW);
     1060    comctl32_color.clrBtnText = GetSysColor (COLOR_BTNTEXT);
     1061    comctl32_color.clrBtnFace = GetSysColor (COLOR_BTNFACE);
     1062    comctl32_color.clrHighlight = GetSysColor (COLOR_HIGHLIGHT);
     1063    comctl32_color.clrHighlightText = GetSysColor (COLOR_HIGHLIGHTTEXT);
     1064    comctl32_color.clr3dHilight = GetSysColor (COLOR_3DHILIGHT);
     1065    comctl32_color.clr3dShadow = GetSysColor (COLOR_3DSHADOW);
     1066    comctl32_color.clr3dDkShadow = GetSysColor (COLOR_3DDKSHADOW);
     1067    comctl32_color.clr3dFace = GetSysColor (COLOR_3DFACE);
     1068    comctl32_color.clrWindow = GetSysColor (COLOR_WINDOW);
     1069    comctl32_color.clrWindowText = GetSysColor (COLOR_WINDOWTEXT);
     1070    comctl32_color.clrGrayText = GetSysColor (COLOR_GRAYTEXT);
     1071    comctl32_color.clrActiveCaption = GetSysColor (COLOR_ACTIVECAPTION);
     1072    comctl32_color.clrInfoBk = GetSysColor (COLOR_INFOBK);
     1073    comctl32_color.clrInfoText = GetSysColor (COLOR_INFOTEXT);
     1074}
  • trunk/src/comctl32/dbgwrap.cpp

    r7921 r8382  
    5050DEBUGWRAP20(FlatSB_SetScrollRange)
    5151DEBUGWRAP12(FlatSB_ShowScrollBar)
    52 NODEF_DEBUGWRAP0(GetMUILanguage)
     52DEBUGWRAP0(GetMUILanguage)
    5353DEBUGWRAP12(ImageList_Add)
    5454DEBUGWRAP8(ImageList_AddIcon)
     
    9595NODEF_DEBUGWRAP8(ImageList_Write)
    9696DEBUGWRAP4(InitCommonControlsEx)
    97 NODEF_DEBUGWRAP4(InitMUILanguage)
     97DEBUGWRAP4(InitMUILanguage)
    9898DEBUGWRAP4(InitializeFlatSB)
    9999DEBUGWRAP4(PropertySheetA)
  • trunk/src/comctl32/flatsb.c

    r6709 r8382  
    44 * Copyright 1998, 1999 Eric Kohl
    55 * Copyright 1998 Alex Priem
     6 *
     7 * This library is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU Lesser General Public
     9 * License as published by the Free Software Foundation; either
     10 * version 2.1 of the License, or (at your option) any later version.
     11 *
     12 * This library is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15 * Lesser General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU Lesser General Public
     18 * License along with this library; if not, write to the Free Software
     19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    620 *
    721 * NOTES
     
    1630 */
    1731
     32#include <string.h>
    1833#include "winbase.h"
    1934#include "winerror.h"
    2035#include "commctrl.h"
    21 #include "debugtools.h"
    22 
    23 #ifdef __WIN32OS2__
    24 #include "ccbase.h"
    25 #endif
    26 
    27 DEFAULT_DEBUG_CHANNEL(commctrl);
     36#include "wine/debug.h"
     37
     38WINE_DEFAULT_DEBUG_CHANNEL(commctrl);
    2839
    2940typedef struct
    3041{
    31 #ifdef __WIN32OS2__
    32     COMCTL32_HEADER header;
    33 #endif
    3442    DWORD dwDummy;  /* just to keep the compiler happy ;-) */
    3543} FLATSB_INFO, *LPFLATSB_INFO;
     
    3947
    4048/***********************************************************************
    41  *              InitializeFlatSB
     49 *              InitializeFlatSB (COMCTL32.86)
    4250 *
    4351 *      returns nonzero if successful, zero otherwise
     
    5260
    5361/***********************************************************************
    54  *              UninitializeFlatSB
     62 *              UninitializeFlatSB (COMCTL32.90)
    5563 *
    5664 *      returns:
     
    6876
    6977/***********************************************************************
    70  *              FlatSB_GetScrollProp
     78 *              FlatSB_GetScrollProp (COMCTL32.32)
    7179 *
    7280 *      Returns nonzero if successful, or zero otherwise. If index is WSB_PROP_HSTYLE,
     
    8492
    8593/***********************************************************************
    86  *              FlatSB_SetScrollProp
     94 *              FlatSB_SetScrollProp (COMCTL32.36)
    8795 */
    8896BOOL WINAPI
     
    111119
    112120/***********************************************************************
    113  *              FlatSB_EnableScrollBar
     121 *              FlatSB_EnableScrollBar (COMCTL32.29)
    114122 */
    115123BOOL WINAPI
     
    120128
    121129/***********************************************************************
    122  *              FlatSB_ShowScrollBar
     130 *              FlatSB_ShowScrollBar (COMCTL32.38)
    123131 */
    124132BOOL WINAPI
     
    129137
    130138/***********************************************************************
    131  *              FlatSB_GetScrollRange
     139 *              FlatSB_GetScrollRange (COMCTL32.33)
    132140 */
    133141BOOL WINAPI
     
    138146
    139147/***********************************************************************
    140  *              FlatSB_GetScrollInfo
     148 *              FlatSB_GetScrollInfo (COMCTL32.30)
    141149 */
    142150BOOL WINAPI
     
    147155
    148156/***********************************************************************
    149  *              FlatSB_GetScrollPos
     157 *              FlatSB_GetScrollPos (COMCTL32.31)
    150158 */
    151159INT WINAPI
     
    156164
    157165/***********************************************************************
    158  *              FlatSB_SetScrollPos
     166 *              FlatSB_SetScrollPos (COMCTL32.35)
    159167 */
    160168INT WINAPI
     
    165173
    166174/***********************************************************************
    167  *              FlatSB_SetScrollInfo
     175 *              FlatSB_SetScrollInfo (COMCTL32.34)
    168176 */
    169177INT WINAPI
     
    174182
    175183/***********************************************************************
    176  *              FlatSB_SetScrollRange
     184 *              FlatSB_SetScrollRange (COMCTL32.37)
    177185 */
    178186INT WINAPI
     
    187195{
    188196    TRACE("[%04x] wParam=%04x lParam=%08lx\n", hwnd, wParam, lParam);
    189 #ifdef __WIN32OS2__
    190     initControl(hwnd,sizeof(FLATSB_INFO));
    191 #endif
    192 
    193197    return 0;
    194198}
     
    199203{
    200204    TRACE("[%04x] wParam=%04x lParam=%08lx\n", hwnd, wParam, lParam);
    201 #ifdef __WIN32OS2__
    202     /* free pager info data */
    203     doneControl(hwnd);
    204 #endif
    205205    return 0;
    206206}
     
    210210FlatSB_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    211211{
     212    if (!FlatSB_GetInfoPtr(hwnd) && (uMsg != WM_CREATE))
     213        return DefWindowProcA( hwnd, uMsg, wParam, lParam );
     214   
    212215    switch (uMsg)
    213216    {
     
    222225                ERR("unknown msg %04x wp=%08x lp=%08lx\n",
    223226                    uMsg, wParam, lParam);
    224 #ifdef __WIN32OS2__
    225             return defComCtl32ProcA (hwnd, uMsg, wParam, lParam);
    226 #else
    227227            return DefWindowProcA (hwnd, uMsg, wParam, lParam);
    228 #endif
    229228    }
    230229    return 0;
  • trunk/src/comctl32/imagelist.c

    r7815 r8382  
    66 *            2001 Michael Stefaniuc
    77 *            2001 Charles Loep for CodeWeavers
     8 *
     9 * This library is free software; you can redistribute it and/or
     10 * modify it under the terms of the GNU Lesser General Public
     11 * License as published by the Free Software Foundation; either
     12 * version 2.1 of the License, or (at your option) any later version.
     13 *
     14 * This library is distributed in the hope that it will be useful,
     15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17 * Lesser General Public License for more details.
     18 *
     19 * You should have received a copy of the GNU Lesser General Public
     20 * License along with this library; if not, write to the Free Software
     21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    822 *
    923 *  TODO:
     
    2236 *      partially implemented, the functions mentioned above will be
    2337 *      limited in functionality too.
     38 *
     39 *    - Hotspot handling still not correct. The Hotspot passed to BeginDrag
     40 *      is the offset of the image position relative to the actual mouse pointer
     41 *      position. However the Hotspot passed to SetDragCursorImage is the
     42 *      offset of the mouse messages sent to the application...
    2443 */
    2544
     
    3251#include "commctrl.h"
    3352#include "imagelist.h"
    34 #include "debugtools.h"
    35 
    36 DEFAULT_DEBUG_CHANNEL(imagelist);
     53#include "wine/debug.h"
     54
     55WINE_DEFAULT_DEBUG_CHANNEL(imagelist);
    3756
    3857
     
    5473    /* saved background */
    5574    HBITMAP     hbmBg;
     75    BOOL        bHSPending;
    5676} INTERNALDRAG;
    5777
    58 static INTERNALDRAG InternalDrag = { 0, 0, 0, 0, 0, 0, FALSE, 0 };
     78static INTERNALDRAG InternalDrag = { 0, 0, 0, 0, 0, 0, FALSE, 0, FALSE };
    5979
    6080
     
    748768
    749769    InternalDrag.himl->cCurImage = 1;
     770    InternalDrag.bHSPending = TRUE;
    750771
    751772    return TRUE;
     
    10721093ImageList_DragLeave (HWND hwndLock)
    10731094{
    1074     if (hwndLock)
     1095    /* As we don't save drag info in the window this can lead to problems if
     1096       an app does not supply the same window as DragEnter */
     1097    /* if (hwndLock)
    10751098        InternalDrag.hwnd = hwndLock;
    10761099    else
    1077         InternalDrag.hwnd = GetDesktopWindow ();
     1100        InternalDrag.hwnd = GetDesktopWindow (); */
     1101    if(!hwndLock)
     1102        hwndLock = GetDesktopWindow();
     1103    if(InternalDrag.hwnd != hwndLock)
     1104        FIXME("DragLeave hWnd != DragEnter hWnd\n");
    10781105
    10791106    ImageList_DragShowNolock (FALSE);
     
    14901517    DeleteObject(InternalDrag.hbmBg);
    14911518    InternalDrag.hbmBg = 0;
     1519    InternalDrag.bHSPending = FALSE;
    14921520
    14931521    return TRUE;
     
    26012629     * hotspot) to the origin of the second image.
    26022630     * See M$DN for details */
    2603     dx = InternalDrag.dxHotspot - dxHotspot;
    2604     dy = InternalDrag.dyHotspot - dyHotspot;
     2631    if(InternalDrag.bHSPending) {
     2632        dx = 0;
     2633        dy = 0;
     2634        InternalDrag.bHSPending = FALSE;
     2635    } else {
     2636        dx = InternalDrag.dxHotspot - dxHotspot;
     2637        dy = InternalDrag.dyHotspot - dyHotspot;
     2638    }
    26052639    himlTemp = ImageList_Merge (InternalDrag.himl, 0, himlDrag, iDrag, dx, dy);
    26062640
     
    26212655    /* update the InternalDragOffset, if the origin of the
    26222656     * DragImage was changed by ImageList_Merge. */
    2623     if (dx > InternalDrag.dxHotspot) {
    2624         InternalDrag.dxHotspot = dx;
    2625     }
    2626     if (dy > InternalDrag.dyHotspot) {
    2627         InternalDrag.dyHotspot = dy;
    2628     }
     2657    if (dx <= 0)
     2658        InternalDrag.dxHotspot = dxHotspot;
     2659    if (dy <= 0)
     2660        InternalDrag.dyHotspot = dyHotspot;
    26292661
    26302662    if (visible) {
     
    29342966
    29352967    if(bitCount == 1) {
    2936         //Hack.
     2968        /* Hack. */
    29372969        LPBITMAPINFO inf = (LPBITMAPINFO)bmih;
    29382970        inf->bmiColors[0].rgbRed = inf->bmiColors[0].rgbGreen = inf->bmiColors[0].rgbBlue = 0;
  • trunk/src/comctl32/ipaddress.c

    r7815 r8382  
    22 * IP Address control
    33 *
    4  * Copyright 1999 Chris Morgan<cmorgan@wpi.edu> and
    5  *                James Abbatiello<abbeyj@wpi.edu>
     4 * Copyright 2002 Dimitrie O. Paun
     5 * Copyright 1999 Chris Morgan<cmorgan@wpi.edu>
     6 * Copyright 1999 James Abbatiello<abbeyj@wpi.edu>
    67 * Copyright 1998, 1999 Eric Kohl
    78 * Copyright 1998 Alex Priem <alexp@sci.kun.nl>
    89 *
    9  * NOTES
    10  *
    11  * TODO:
    12  *    -Edit control doesn't support the ES_CENTER style which prevents
    13  *     this ipaddress control from having centered text look like the
    14  *     windows ipaddress control
    15  *    -Check all notifications/behavior.
    16  *    -Optimization:
    17  *        -include lpipsi in IPADDRESS_INFO.
    18  *        -CurrentFocus: field that has focus at moment of processing.
    19  *        -connect Rect32 rcClient.
    20  *        -check ipaddress.cpp for missing features.
    21  *    -refresh: draw '.' instead of setpixel.
     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
     23 *
    2224 */
    2325
     
    2729#include <string.h>
    2830
     31#include "ntddk.h"
    2932#include "winbase.h"
    3033#include "commctrl.h"
    31 #include "debugtools.h"
    32 
    33 DEFAULT_DEBUG_CHANNEL(ipaddress);
     34#include "wine/debug.h"
     35#ifdef __WIN32OS2__
     36#include "comctl32.h"
     37#endif
     38
     39WINE_DEFAULT_DEBUG_CHANNEL(ipaddress);
    3440
    3541typedef struct
    3642{
    37         BYTE LowerLimit[4];
    38         BYTE UpperLimit[4];
    39 
    40         RECT    rcClient;
    41         INT     uFocus;
     43    HWND     EditHwnd;
     44    INT      LowerLimit;
     45    INT      UpperLimit;
     46    WNDPROC  OrigProc;
     47} IPPART_INFO;
     48
     49typedef struct
     50{
     51    HWND        Self;
     52    IPPART_INFO Part[4];
    4253} IPADDRESS_INFO;
    4354
    44 typedef struct
    45 {
    46     WNDPROC wpOrigProc[4];
    47     HWND    hwndIP[4];
    48     IPADDRESS_INFO *infoPtr;
    49     HWND    hwnd;
    50     UINT    uRefCount;
    51 } IP_SUBCLASS_INFO, *LPIP_SUBCLASS_INFO;
    52 
    53 #define IPADDRESS_GetInfoPtr(hwnd) ((IPADDRESS_INFO *)GetWindowLongA (hwnd, 0))
    54 
    55 static BOOL
    56 IPADDRESS_SendNotify (HWND hwnd, UINT command);
    57 static BOOL
    58 IPADDRESS_SendIPAddressNotify (HWND hwnd, UINT field, BYTE newValue);
    59 
    60 /* property name of tooltip window handle */
     55#define POS_DEFAULT     0
     56#define POS_LEFT        1
     57#define POS_RIGHT       2
     58#define POS_SELALL      3
     59
    6160#define IP_SUBCLASS_PROP "CCIP32SubclassInfo"
     61#define IPADDRESS_GetInfoPtr(hwnd) ((IPADDRESS_INFO *)GetWindowLongW (hwnd, 0))
    6262
    6363
     
    6565IPADDRESS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    6666
    67 
    68 static VOID
    69 IPADDRESS_Refresh (HWND hwnd, HDC hdc)
    70 {
    71   RECT rcClient;
    72   HBRUSH hbr;
    73   COLORREF clr=GetSysColor (COLOR_3DDKSHADOW);
    74   int i,x,fieldsize;
    75 
    76   GetClientRect (hwnd, &rcClient);
    77   hbr = CreateSolidBrush (RGB(255,255,255));
    78   DrawEdge (hdc, &rcClient, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
    79   FillRect (hdc, &rcClient, hbr);
    80   DeleteObject (hbr);
    81 
    82   x=rcClient.left;
    83   fieldsize=(rcClient.right-rcClient.left) / 4;
    84 
    85   for (i=0; i<3; i++) {         /* Should draw text "." here */
    86     x+=fieldsize;
    87     SetPixel (hdc, x,   13, clr);
    88     SetPixel (hdc, x,   14, clr);
    89     SetPixel (hdc, x+1, 13, clr);
    90     SetPixel (hdc, x+1, 14, clr);
    91   }
    92 }
    93 
    94 
    95 static LRESULT
    96 IPADDRESS_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
    97 {
    98   IPADDRESS_INFO *infoPtr;
    99   RECT rcClient, edit;
    100   int i,fieldsize;
    101   LPIP_SUBCLASS_INFO lpipsi;
     67static LRESULT IPADDRESS_Notify (IPADDRESS_INFO *infoPtr, UINT command)
     68{
     69    HWND hwnd = infoPtr->Self;
     70   
     71    TRACE("(command=%x)\n", command);
     72   
     73    return SendMessageW (GetParent (hwnd), WM_COMMAND,
     74             MAKEWPARAM (GetWindowLongW (hwnd, GWL_ID), command), (LPARAM)hwnd);
     75}
     76
     77static INT IPADDRESS_IPNotify (IPADDRESS_INFO *infoPtr, INT field, INT value)
     78{
     79    NMIPADDRESS nmip;
     80
     81    TRACE("(field=%x, value=%d)\n", field, value);
     82   
     83    nmip.hdr.hwndFrom = infoPtr->Self;
     84    nmip.hdr.idFrom   = GetWindowLongW (infoPtr->Self, GWL_ID);
     85    nmip.hdr.code     = IPN_FIELDCHANGED;
     86
     87    nmip.iField = field;
     88    nmip.iValue = value;
     89
     90    SendMessageW (GetParent (infoPtr->Self), WM_NOTIFY,
     91                  (WPARAM)nmip.hdr.idFrom, (LPARAM)&nmip);
     92
     93    TRACE("<-- %d\n", nmip.iValue);
     94   
     95    return nmip.iValue;
     96}
     97
     98
     99static int IPADDRESS_GetPartIndex(IPADDRESS_INFO *infoPtr, HWND hwnd)
     100{
     101    int i;
     102   
     103    TRACE("(hwnd=%x)\n", hwnd);
     104   
     105    for (i = 0; i < 4; i++)
     106        if (infoPtr->Part[i].EditHwnd == hwnd) return i;
     107   
     108    ERR("We subclassed the wrong window! (hwnd=%x)\n", hwnd);
     109    return -1;
     110}
     111
     112
     113static LRESULT IPADDRESS_Draw (IPADDRESS_INFO *infoPtr, HDC hdc)
     114{
     115    RECT rect, rcPart;
     116    POINT pt;
     117    int i;
     118
     119    TRACE("\n");
     120   
     121    GetClientRect (infoPtr->Self, &rect);
     122    DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
     123
     124    for (i = 0; i < 3; i++) {
     125        GetWindowRect (infoPtr->Part[i].EditHwnd, &rcPart);
     126        pt.x = rcPart.right;
     127        ScreenToClient(infoPtr->Self, &pt);
     128        rect.left = pt.x;       
     129        GetWindowRect (infoPtr->Part[i+1].EditHwnd, &rcPart);
     130        pt.x = rcPart.left;
     131        ScreenToClient(infoPtr->Self, &pt);
     132        rect.right = pt.x;
     133        DrawTextA(hdc, ".", 1, &rect, DT_SINGLELINE | DT_CENTER | DT_BOTTOM);
     134    }
     135
     136    return 0;
     137}
     138
     139
     140static LRESULT IPADDRESS_Create (HWND hwnd)
     141{
     142    IPADDRESS_INFO *infoPtr;
     143    RECT rcClient, edit;
     144    int i, fieldsize;
     145    WCHAR EDIT[] = { 'E', 'd', 'i', 't', 0 };
     146
     147    TRACE("\n");
     148   
     149    SetWindowLongW (hwnd, GWL_STYLE,
     150                    GetWindowLongW(hwnd, GWL_STYLE) & ~WS_BORDER);
     151   
     152    infoPtr = (IPADDRESS_INFO *)COMCTL32_Alloc (sizeof(IPADDRESS_INFO));
     153    if (!infoPtr) return -1;
     154    SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
     155
     156    GetClientRect (hwnd, &rcClient);
     157
     158    fieldsize = (rcClient.right - rcClient.left) / 4;
     159
     160    edit.top    = rcClient.top + 2;
     161    edit.bottom = rcClient.bottom - 2;
     162
     163    infoPtr->Self = hwnd;
     164 
     165    for (i = 0; i < 4; i++) {
     166        IPPART_INFO* part = &infoPtr->Part[i];
    102167       
    103 
    104   infoPtr = (IPADDRESS_INFO *)COMCTL32_Alloc (sizeof(IPADDRESS_INFO));
    105   SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
    106 
    107   GetClientRect (hwnd, &rcClient);
    108 
    109   fieldsize=(rcClient.right-rcClient.left) /4;
    110 
    111   edit.top   =rcClient.top+2;
    112   edit.bottom=rcClient.bottom-2;
    113 
    114   lpipsi=(LPIP_SUBCLASS_INFO) GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
    115   if (lpipsi == NULL)  {
    116     lpipsi = (LPIP_SUBCLASS_INFO) COMCTL32_Alloc (sizeof(IP_SUBCLASS_INFO));
    117     lpipsi->hwnd = hwnd;
    118     lpipsi->uRefCount++;
    119     SetPropA ((HWND)hwnd, IP_SUBCLASS_PROP, (HANDLE)lpipsi);
    120 /*              infoPtr->lpipsi= lpipsi; */
    121   } else
    122     WARN("IP-create called twice\n");
     168        part->LowerLimit = 0;
     169        part->UpperLimit = 255;
     170        edit.left = rcClient.left + i*fieldsize + 6;
     171        edit.right = rcClient.left + (i+1)*fieldsize - 2;
     172        part->EditHwnd =
     173                CreateWindowW (EDIT, NULL, WS_CHILD | WS_VISIBLE | ES_CENTER,
     174                               edit.left, edit.top, edit.right - edit.left,
     175                               edit.bottom - edit.top, hwnd, (HMENU) 1,
     176                               GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
     177        SetPropA(part->EditHwnd, IP_SUBCLASS_PROP, hwnd);
     178        part->OrigProc = (WNDPROC)
     179                SetWindowLongW (part->EditHwnd, GWL_WNDPROC,
     180                                (LONG)IPADDRESS_SubclassProc);
     181    }
     182
     183    return 0;
     184}
     185
     186
     187static LRESULT IPADDRESS_Destroy (IPADDRESS_INFO *infoPtr)
     188{
     189    int i;
     190
     191    TRACE("\n");
     192   
     193    for (i = 0; i < 4; i++) {
     194        IPPART_INFO* part = &infoPtr->Part[i];
     195        SetWindowLongW (part->EditHwnd, GWL_WNDPROC, (LONG)part->OrigProc);
     196    }
     197
     198    SetWindowLongW (infoPtr->Self, 0, 0);
     199    COMCTL32_Free (infoPtr);
     200    return 0;
     201}
     202
     203
     204static LRESULT IPADDRESS_Paint (IPADDRESS_INFO *infoPtr, HDC hdc)
     205{
     206    PAINTSTRUCT ps;
     207
     208    TRACE("\n");
     209   
     210    if (hdc) return IPADDRESS_Draw (infoPtr, hdc);
     211 
     212    hdc = BeginPaint (infoPtr->Self, &ps);
     213    IPADDRESS_Draw (infoPtr, hdc);
     214    EndPaint (infoPtr->Self, &ps);
     215    return 0;
     216}
     217
     218
     219static BOOL IPADDRESS_IsBlank (IPADDRESS_INFO *infoPtr)
     220{
     221    int i;
     222
     223    TRACE("\n");
     224
     225    for (i = 0; i < 4; i++)
     226        if (GetWindowTextLengthW (infoPtr->Part[i].EditHwnd)) return FALSE;
     227
     228    return TRUE;
     229}
     230
     231
     232static int IPADDRESS_GetAddress (IPADDRESS_INFO *infoPtr, LPDWORD ip_address)
     233{
     234    WCHAR field[5];
     235    int i, invalid = 0;
     236    DWORD ip_addr = 0;
     237
     238    TRACE("\n");
     239
     240    for (i = 0; i < 4; i++) {
     241        ip_addr *= 256;
     242        if (GetWindowTextW (infoPtr->Part[i].EditHwnd, field, 4))
     243            ip_addr += wcstol(field, 0, 10);
     244        else
     245            invalid++;
     246    }
     247    *ip_address = ip_addr;
     248
     249    return 4 - invalid;
     250}
     251
     252
     253static BOOL IPADDRESS_SetRange (IPADDRESS_INFO *infoPtr, int index, WORD range)
     254{
     255    TRACE("\n");
     256
     257    if ( (index < 0) || (index > 3) ) return FALSE;
     258
     259    infoPtr->Part[index].LowerLimit = range & 0xFF;
     260    infoPtr->Part[index].UpperLimit = (range >> 8)  & 0xFF;
     261
     262    return TRUE;
     263}
     264
     265
     266static void IPADDRESS_ClearAddress (IPADDRESS_INFO *infoPtr)
     267{
     268    WCHAR nil[1] = { 0 };
     269    int i;
     270
     271    TRACE("\n");
     272
     273    for (i = 0; i < 4; i++)
     274        SetWindowTextW (infoPtr->Part[i].EditHwnd, nil);
     275}
     276
     277
     278static LRESULT IPADDRESS_SetAddress (IPADDRESS_INFO *infoPtr, DWORD ip_address)
     279{
     280    WCHAR buf[20], fmt[] = { '%', 'd', 0 };
     281    int i;
     282
     283    TRACE("\n");
     284
     285    for (i = 3; i >= 0; i--) {
     286        IPPART_INFO* part = &infoPtr->Part[i];
     287        int value = ip_address & 0xff;
     288        if ( (value >= part->LowerLimit) && (value <= part->UpperLimit) ) {
     289            swprintf (buf, fmt, value);
     290            SetWindowTextW (part->EditHwnd, buf);
     291            IPADDRESS_Notify (infoPtr, EN_CHANGE);
     292        }
     293        ip_address >>= 8;
     294    }
     295
     296    return TRUE;
     297}
     298
     299
     300static void IPADDRESS_SetFocusToField (IPADDRESS_INFO *infoPtr, INT index)
     301{
     302    TRACE("(index=%d)\n", index);
     303 
     304    if (index > 3) {
     305        for (index = 0; index < 4; index++)
     306            if (!GetWindowTextLengthW(infoPtr->Part[index].EditHwnd)) break;
     307    }
     308    if (index < 9 || index > 3) index = 0;
    123309       
    124   for (i=0; i<=3; i++)
    125   {
    126     infoPtr->LowerLimit[i]=0;
    127     infoPtr->UpperLimit[i]=255;
    128     edit.left=rcClient.left+i*fieldsize+6;
    129     edit.right=rcClient.left+(i+1)*fieldsize-2;
    130     lpipsi->hwndIP[i]= CreateWindowA ("edit", NULL,
    131         WS_CHILD | WS_VISIBLE | ES_CENTER,
    132         edit.left, edit.top, edit.right-edit.left, edit.bottom-edit.top,
    133         hwnd, (HMENU) 1, GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
    134     lpipsi->wpOrigProc[i]= (WNDPROC)
    135         SetWindowLongA (lpipsi->hwndIP[i],GWL_WNDPROC, (LONG)
    136         IPADDRESS_SubclassProc);
    137     SetPropA ((HWND)lpipsi->hwndIP[i], IP_SUBCLASS_PROP, (HANDLE)lpipsi);
    138   }
    139 
    140   lpipsi->infoPtr= infoPtr;
    141 
    142   return 0;
    143 }
    144 
    145 
    146 static LRESULT
    147 IPADDRESS_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
    148 {
    149   int i;
    150   IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd);
    151   LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
    152             GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
    153 
    154   for (i=0; i<=3; i++) {
    155     SetWindowLongA ((HWND)lpipsi->hwndIP[i], GWL_WNDPROC,
    156                   (LONG)lpipsi->wpOrigProc[i]);
    157   }
    158 
    159   COMCTL32_Free (infoPtr);
    160   SetWindowLongA (hwnd, 0, 0);
    161   return 0;
    162 }
    163 
    164 
    165 static LRESULT
    166 IPADDRESS_KillFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
    167 {
    168   HDC hdc;
    169 
    170   TRACE("\n");
    171   hdc = GetDC (hwnd);
    172   IPADDRESS_Refresh (hwnd, hdc);
    173   ReleaseDC (hwnd, hdc);
    174 
    175   IPADDRESS_SendIPAddressNotify (hwnd, 0, 0);  /* FIXME: should use -1 */
    176   IPADDRESS_SendNotify (hwnd, EN_KILLFOCUS);       
    177   InvalidateRect (hwnd, NULL, TRUE);
    178 
    179   return 0;
    180 }
    181 
    182 
    183 static LRESULT
    184 IPADDRESS_Paint (HWND hwnd, WPARAM wParam)
    185 {
    186   HDC hdc;
    187   PAINTSTRUCT ps;
    188 
    189   hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
    190   IPADDRESS_Refresh (hwnd, hdc);
    191   if(!wParam)
    192     EndPaint (hwnd, &ps);
    193   return 0;
    194 }
    195 
    196 
    197 static LRESULT
    198 IPADDRESS_SetFocus (HWND hwnd, WPARAM wParam, LPARAM lParam)
    199 {
    200   HDC hdc;
    201 
    202   TRACE("\n");
    203 
    204   hdc = GetDC (hwnd);
    205   IPADDRESS_Refresh (hwnd, hdc);
    206   ReleaseDC (hwnd, hdc);
    207 
    208   return 0;
    209 }
    210 
    211 
    212 static LRESULT
    213 IPADDRESS_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
    214 {
    215   /* IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd); */
    216   TRACE("\n");
    217   return 0;
    218 }
    219 
    220 
    221 static BOOL
    222 IPADDRESS_SendNotify (HWND hwnd, UINT command)
    223 {
    224   TRACE("%x\n",command);
    225   return (BOOL)SendMessageA (GetParent (hwnd), WM_COMMAND,
    226               MAKEWPARAM (GetWindowLongA (hwnd, GWL_ID),command), (LPARAM)hwnd);
    227 }
    228 
    229 
    230 static BOOL
    231 IPADDRESS_SendIPAddressNotify (HWND hwnd, UINT field, BYTE newValue)
    232 {
    233   NMIPADDRESS nmip;
    234 
    235   TRACE("%x %x\n",field,newValue);
    236   nmip.hdr.hwndFrom = hwnd;
    237   nmip.hdr.idFrom   = GetWindowLongA (hwnd, GWL_ID);
    238   nmip.hdr.code     = IPN_FIELDCHANGED;
    239 
    240   nmip.iField=field;
    241   nmip.iValue=newValue;
    242 
    243   return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
    244                              (WPARAM)nmip.hdr.idFrom, (LPARAM)&nmip);
    245 }
    246 
    247 
    248 static LRESULT
    249 IPADDRESS_ClearAddress (HWND hwnd, WPARAM wParam, LPARAM lParam)
    250 {
    251   int i;
    252   HDC hdc;
    253   char buf[1];
    254   LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
    255             GetPropA ((HWND)hwnd,IP_SUBCLASS_PROP);
    256 
    257   TRACE("\n");
    258 
    259   buf[0]=0;
    260   for (i=0; i<=3; i++)
    261     SetWindowTextA (lpipsi->hwndIP[i],buf);
     310    SetFocus (infoPtr->Part[index].EditHwnd);
     311}
     312
     313
     314static BOOL IPADDRESS_ConstrainField (IPADDRESS_INFO *infoPtr, int currentfield)
     315{
     316    IPPART_INFO *part = &infoPtr->Part[currentfield];
     317    WCHAR field[10], fmt[] = { '%', 'd', 0 };
     318    int curValue, newValue;
     319
     320    TRACE("(currentfield=%d)\n", currentfield);
     321
     322    if (currentfield < 0 || currentfield > 3) return FALSE;
     323 
     324    if (!GetWindowTextW (part->EditHwnd, field, 4)) return FALSE;
     325   
     326    curValue = wcstol(field, 0, 10);
     327    TRACE("  curValue=%d\n", curValue);
     328   
     329    newValue = IPADDRESS_IPNotify(infoPtr, currentfield, curValue);
     330    TRACE("  newValue=%d\n", newValue);
     331
     332    if (newValue < part->LowerLimit) newValue = part->LowerLimit;
     333    if (newValue > part->UpperLimit) newValue = part->UpperLimit;
     334   
     335    if (newValue == curValue) return FALSE;
     336   
     337    swprintf (field, fmt, newValue);
     338    TRACE("  field='%s'\n", debugstr_w(field));
     339    return SetWindowTextW (part->EditHwnd, field);
     340}
     341
     342
     343static BOOL IPADDRESS_GotoNextField (IPADDRESS_INFO *infoPtr, int cur, int sel)
     344{
     345    TRACE("\n");
     346
     347    if(cur >= -1 && cur < 4) {
     348        IPADDRESS_ConstrainField(infoPtr, cur);
    262349       
    263   hdc = GetDC (hwnd);
    264   IPADDRESS_Refresh (hwnd, hdc);
    265   ReleaseDC (hwnd, hdc);
    266        
    267   return 0;
    268 }
    269 
    270 
    271 static LRESULT
    272 IPADDRESS_IsBlank (HWND hwnd, WPARAM wParam, LPARAM lParam)
    273 {
    274   int i;
    275   char buf[20];
    276   LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
    277             GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
    278 
    279   TRACE("\n");
    280 
    281   for (i=0; i<=3; i++) {
    282     GetWindowTextA (lpipsi->hwndIP[i],buf,5);
    283     if (buf[0])
    284       return 0;
    285   }
    286 
    287   return 1;
    288 }
    289 
    290 
    291 static LRESULT
    292 IPADDRESS_GetAddress (HWND hwnd, WPARAM wParam, LPARAM lParam)
    293 {
    294   char field[20];
    295   int i,valid,fieldvalue;
    296   DWORD ip_addr;
    297   IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd);
    298   LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
    299             GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
    300 
    301   TRACE("\n");
    302 
    303   valid=0;
    304   ip_addr=0;
    305   for (i=0; i<=3; i++) {
    306     GetWindowTextA (lpipsi->hwndIP[i],field,4);
    307     ip_addr*=256;
    308     if (field[0]) {
    309       field[3]=0;
    310       fieldvalue=atoi(field);
    311       if (fieldvalue<infoPtr->LowerLimit[i])
    312         fieldvalue=infoPtr->LowerLimit[i];
    313       if (fieldvalue>infoPtr->UpperLimit[i])
    314         fieldvalue=infoPtr->UpperLimit[i];
    315       ip_addr+=fieldvalue;
    316       valid++;
    317     }
    318   }
    319 
    320   *(LPDWORD) lParam=ip_addr;
    321 
    322   return valid;
    323 }
    324 
    325 
    326 static LRESULT
    327 IPADDRESS_SetRange (HWND hwnd, WPARAM wParam, LPARAM lParam)
    328 {
    329   IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd);
    330   INT index;
    331        
    332   TRACE("\n");
    333 
    334   index=(INT) wParam;
    335   if ((index<0) || (index>3)) return 0;
    336 
    337   infoPtr->LowerLimit[index]=lParam & 0xff;
    338   infoPtr->UpperLimit[index]=(lParam >>8)  & 0xff;
    339   return 1;
    340 }
    341 
    342 
    343 static LRESULT
    344 IPADDRESS_SetAddress (HWND hwnd, WPARAM wParam, LPARAM lParam)
    345 {
    346   IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd);
    347   HDC hdc;
    348   LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO)
    349             GetPropA ((HWND)hwnd, IP_SUBCLASS_PROP);
    350   int i,value;
    351   DWORD ip_address;
    352   char buf[20];
    353 
    354   TRACE("\n");
    355   ip_address=(DWORD) lParam;
    356 
    357   for (i=3; i>=0; i--) {
    358     value=ip_address & 0xff;
    359     if ((value>=infoPtr->LowerLimit[i]) && (value<=infoPtr->UpperLimit[i]))
    360     {
    361       sprintf (buf,"%d",value);
    362       SetWindowTextA (lpipsi->hwndIP[i],buf);
    363       IPADDRESS_SendNotify (hwnd, EN_CHANGE);
    364     }
    365     ip_address= ip_address >> 8;
    366   }
    367 
    368   hdc = GetDC (hwnd);           /* & send notifications */
    369   IPADDRESS_Refresh (hwnd, hdc);
    370   ReleaseDC (hwnd, hdc);
    371 
    372   return TRUE;
    373 }
    374 
    375 
    376 static LRESULT
    377 IPADDRESS_SetFocusToField (HWND hwnd, WPARAM wParam, LPARAM lParam)
    378 {
    379   /* IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd); */
    380   LPIP_SUBCLASS_INFO lpipsi=(LPIP_SUBCLASS_INFO) GetPropA ((HWND)hwnd,
    381                                                    IP_SUBCLASS_PROP);
    382   INT index;
    383 
    384   index=(INT) wParam;
    385   TRACE(" %d\n", index);
    386   if ((index<0) || (index>3)) return 0;
    387        
    388   SetFocus (lpipsi->hwndIP[index]);
    389        
    390   return 1;
    391 }
    392 
    393 
    394 static LRESULT
    395 IPADDRESS_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
    396 {
    397   TRACE("\n");
    398 
    399   SetFocus (hwnd);
    400   IPADDRESS_SendNotify (hwnd, EN_SETFOCUS);
    401   IPADDRESS_SetFocusToField (hwnd, 0, 0);
    402 
    403   return TRUE;
    404 }
    405 
    406 
    407 static INT
    408 IPADDRESS_CheckField (LPIP_SUBCLASS_INFO lpipsi, int currentfield)
    409 {
    410   int newField,fieldvalue;
    411   char field[20];
    412   IPADDRESS_INFO *infoPtr=lpipsi->infoPtr;
    413 
    414   if(currentfield >= 0 && currentfield < 4)
    415   {
    416     TRACE("\n");
    417     GetWindowTextA (lpipsi->hwndIP[currentfield],field,4);
    418     if (field[0])
    419     {
    420       field[3]=0;       
    421       newField=-1;
    422       fieldvalue=atoi(field);
    423    
    424       if (fieldvalue < infoPtr->LowerLimit[currentfield])
    425         newField=infoPtr->LowerLimit[currentfield];
    426    
    427       if (fieldvalue > infoPtr->UpperLimit[currentfield])
    428         newField=infoPtr->UpperLimit[currentfield];
    429    
    430       if (newField >= 0)
    431       {
    432         sprintf (field,"%d",newField);
    433         SetWindowTextA (lpipsi->hwndIP[currentfield], field);
    434         return TRUE;
    435       }
    436     }
    437   }
    438   return FALSE;
    439 }
    440 
    441 
    442 static INT
    443 IPADDRESS_GotoNextField (LPIP_SUBCLASS_INFO lpipsi, int currentfield)
    444 {
    445   if(currentfield >= -1 && currentfield < 4)
    446   {
    447     IPADDRESS_CheckField(lpipsi, currentfield); /* check the fields value */ 
    448 
    449     if(currentfield < 3)
    450     {
    451       SetFocus (lpipsi->hwndIP[currentfield+1]);
    452       return TRUE;
    453     }
    454   }
    455   return FALSE;
    456 }
    457 
    458 
    459 /* period: move and select the text in the next field to the right if */
    460 /*         the current field is not empty(l!=0), we are not in the */
    461 /*         left most position, and nothing is selected(startsel==endsel) */
    462 
    463 /* spacebar: same behavior as period */
    464 
    465 /* alpha characters: completely ignored */
    466 
    467 /* digits: accepted when field text length < 2 ignored otherwise. */
    468 /*         when 3 numbers have been entered into the field the value */
    469 /*         of the field is checked, if the field value exceeds the */
    470 /*         maximum value and is changed the field remains the current */
    471 /*         field, otherwise focus moves to the field to the right */
    472 
    473 /* tab: change focus from the current ipaddress control to the next */
    474 /*      control in the tab order */
    475 
    476 /* right arrow: move to the field on the right to the left most */
    477 /*              position in that field if no text is selected, */
    478 /*              we are in the right most position in the field, */
    479 /*              we are not in the right most field */
    480 
    481 /* left arrow: move to the field on the left to the right most */
    482 /*             position in that field if no text is selected, */
    483 /*             we are in the left most position in the current field */
    484 /*             and we are not in the left most field */
    485 
    486 /* backspace: delete the character to the left of the cursor position, */
    487 /*            if none are present move to the field on the left if */
    488 /*            we are not in the left most field and delete the right */
    489 /*            most digit in that field while keeping the cursor */
    490 /*            on the right side of the field */
    491 
    492 
     350        if(cur < 3) {
     351            IPPART_INFO *next = &infoPtr->Part[cur + 1];
     352            int start = 0, end = 0;
     353            SetFocus (next->EditHwnd);
     354            if (sel != POS_DEFAULT) {
     355                if (sel == POS_RIGHT)
     356                    start = end = GetWindowTextLengthW(next->EditHwnd);
     357                else if (sel == POS_SELALL)
     358                    end = -1;
     359                SendMessageW(next->EditHwnd, EM_SETSEL, start, end);
     360            }
     361            return TRUE;
     362        }
     363                 
     364    }
     365    return FALSE;
     366}
     367
     368
     369/*
     370 * period: move and select the text in the next field to the right if
     371 *         the current field is not empty(l!=0), we are not in the
     372 *         left most position, and nothing is selected(startsel==endsel)
     373 *
     374 * spacebar: same behavior as period
     375 *
     376 * alpha characters: completely ignored
     377 *
     378 * digits: accepted when field text length < 2 ignored otherwise.
     379 *         when 3 numbers have been entered into the field the value
     380 *         of the field is checked, if the field value exceeds the
     381 *         maximum value and is changed the field remains the current
     382 *         field, otherwise focus moves to the field to the right
     383 *
     384 * tab: change focus from the current ipaddress control to the next
     385 *      control in the tab order
     386 *
     387 * right arrow: move to the field on the right to the left most
     388 *              position in that field if no text is selected,
     389 *              we are in the right most position in the field,
     390 *              we are not in the right most field
     391 *
     392 * left arrow: move to the field on the left to the right most
     393 *             position in that field if no text is selected,
     394 *             we are in the left most position in the current field
     395 *             and we are not in the left most field
     396 *
     397 * backspace: delete the character to the left of the cursor position,
     398 *            if none are present move to the field on the left if
     399 *            we are not in the left most field and delete the right
     400 *            most digit in that field while keeping the cursor
     401 *            on the right side of the field
     402 */
    493403LRESULT CALLBACK
    494404IPADDRESS_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    495405{
    496   IPADDRESS_INFO *infoPtr;
    497   LPIP_SUBCLASS_INFO lpipsi = (LPIP_SUBCLASS_INFO) GetPropA
    498         ((HWND)hwnd,IP_SUBCLASS_PROP);
    499   CHAR c = (CHAR)wParam;
    500   INT i, l, index, startsel, endsel;
    501 
    502   infoPtr = lpipsi->infoPtr;
    503   index=0;             /* FIXME */
    504   for (i=0; i<=3; i++)
    505     if (lpipsi->hwndIP[i]==hwnd) index=i;
    506 
    507   switch (uMsg) {
    508   case WM_CHAR:
    509     if(isdigit(c)) /* process all digits */
    510     {
    511       int return_val;
    512       SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
    513       l = GetWindowTextLengthA (lpipsi->hwndIP[index]);
    514       if(l==2 && startsel==endsel) /* field is full after this key is processed */
    515       {
    516         /* process the digit press before we check the field */
    517         return_val = CallWindowProcA (lpipsi->wpOrigProc[index], hwnd, uMsg, wParam, lParam);
     406    HWND Self = (HWND)GetPropA (hwnd, IP_SUBCLASS_PROP);
     407    IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (Self);
     408    CHAR c = (CHAR)wParam;
     409    INT index, len = 0, startsel, endsel;
     410    IPPART_INFO *part;
     411
     412    TRACE("(hwnd=0x%x msg=0x%x wparam=0x%x lparam=0x%lx)\n", hwnd, uMsg, wParam, lParam);
     413
     414    if ( (index = IPADDRESS_GetPartIndex(infoPtr, hwnd)) < 0) return 0;
     415    part = &infoPtr->Part[index];
     416
     417    if (uMsg == WM_CHAR || uMsg == WM_KEYDOWN) {
     418        len = GetWindowTextLengthW (hwnd);
     419        SendMessageW(hwnd, EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
     420    }   
     421    switch (uMsg) {
     422        case WM_CHAR:
     423            if(isdigit(c)) {
     424                if(len == 2 && startsel==endsel && endsel==len) {
     425                    /* process the digit press before we check the field */
     426                    int return_val = CallWindowProcW (part->OrigProc, hwnd, uMsg, wParam, lParam);
    518427         
    519         /* if the field value was changed stay at the current field */
    520         if(!IPADDRESS_CheckField(lpipsi, index))
    521           IPADDRESS_GotoNextField (lpipsi,index);
    522 
    523         return return_val;
    524       }
    525      
    526       if(l > 2) /* field is full, stop key messages */
    527       {
    528         lParam = 0;
    529         wParam = 0;
    530       }
    531       break;
    532     }   
    533    
    534     if(c == '.') /* VK_PERIOD */
    535     {
    536       l = GetWindowTextLengthA(lpipsi->hwndIP[index]);
    537       SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
    538       if(l != 0 && startsel==endsel && startsel != 0)
    539       {
    540         IPADDRESS_GotoNextField(lpipsi, index);
    541         SendMessageA(lpipsi->hwndIP[index+1], EM_SETSEL, (WPARAM)0, (LPARAM)3);
    542       }
    543     }
     428                    /* if the field value was changed stay at the current field */
     429                    if(!IPADDRESS_ConstrainField(infoPtr, index))
     430                        IPADDRESS_GotoNextField (infoPtr, index, POS_DEFAULT);
     431
     432                    return return_val;
     433                } else if (len == 3 && startsel==endsel && endsel==len)
     434                    IPADDRESS_GotoNextField (infoPtr, index, POS_SELALL);
     435                else if (len < 3) break;
     436            } else if(c == '.' || c == ' ') {
     437                if(len && startsel==endsel && startsel != 0) {
     438                    IPADDRESS_GotoNextField(infoPtr, index, POS_SELALL);
     439                }
     440            } else if (c == VK_BACK) break;
     441            return 0;
    544442       
    545     /* stop all other characters */
    546     wParam = 0;
    547     lParam = 0;
    548     break;
    549 
    550   case WM_KEYDOWN:
    551     if(c == VK_SPACE)
    552     {
    553       l = GetWindowTextLengthA(lpipsi->hwndIP[index]);
    554       SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
    555       if(l != 0 && startsel==endsel && startsel != 0)
    556       {
    557         IPADDRESS_GotoNextField(lpipsi, index);
    558         SendMessageA(lpipsi->hwndIP[index+1], EM_SETSEL, (WPARAM)0, (LPARAM)3);
    559       }
    560     }
    561 
    562     if(c == VK_RIGHT)
    563     {
    564       SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
    565       l = GetWindowTextLengthA (lpipsi->hwndIP[index]);
    566    
    567       if(startsel==endsel && startsel==l)
    568       {
    569         IPADDRESS_GotoNextField(lpipsi, index);
    570         SendMessageA(lpipsi->hwndIP[index+1], EM_SETSEL, (WPARAM)0,(LPARAM)0);
    571       }
    572     }
    573 
    574     if(c == VK_LEFT)
    575     {
    576       SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
    577       if(startsel==0 && startsel==endsel && index > 0)
    578       {       
    579         IPADDRESS_GotoNextField(lpipsi, index - 2);
    580         l = GetWindowTextLengthA(lpipsi->hwndIP[index-1]);
    581         SendMessageA(lpipsi->hwndIP[index-1], EM_SETSEL, (WPARAM)l,(LPARAM)l);
    582       }     
    583     }
    584    
    585     if(c == VK_BACK) /* VK_BACKSPACE */
    586     {
    587       CHAR buf[4];
    588 
    589       SendMessageA(lpipsi->hwndIP[index], EM_GETSEL, (WPARAM)&startsel, (LPARAM)&endsel);
    590       l = GetWindowTextLengthA (lpipsi->hwndIP[index]);
    591       if(startsel==endsel && startsel==0 && index > 0)
    592       {
    593         l = GetWindowTextLengthA(lpipsi->hwndIP[index-1]);
    594         if(l!=0)
    595         {
    596           GetWindowTextA (lpipsi->hwndIP[index-1],buf,4);
    597           buf[l-1] = '\0';
    598           SetWindowTextA(lpipsi->hwndIP[index-1], buf);
    599           SendMessageA(lpipsi->hwndIP[index-1], EM_SETSEL, (WPARAM)l,(LPARAM)l);
    600         }
    601         IPADDRESS_GotoNextField(lpipsi, index - 2);
    602       }
    603     }
    604     break;
    605 
    606   default:
    607     break;
    608   }
    609   return CallWindowProcA (lpipsi->wpOrigProc[index], hwnd, uMsg, wParam, lParam);
     443        case WM_KEYDOWN:
     444            switch(c) {
     445                case VK_RIGHT:
     446                    if(startsel==endsel && startsel==len) {
     447                        IPADDRESS_GotoNextField(infoPtr, index, POS_LEFT);
     448                        return 0;
     449                    }
     450                    break;
     451                case VK_LEFT:
     452                    if(startsel==0 && startsel==endsel && index > 0) {
     453                        IPADDRESS_GotoNextField(infoPtr, index - 2, POS_RIGHT);
     454                        return 0;
     455                    }
     456                    break;
     457                case VK_BACK:
     458                    if(startsel==endsel && startsel==0 && index > 0) {
     459                        IPPART_INFO *prev = &infoPtr->Part[index-1];
     460                        WCHAR val[10];
     461                       
     462                        if(GetWindowTextW(prev->EditHwnd, val, 5)) {
     463                            val[lstrlenW(val) - 1] = 0;
     464                            SetWindowTextW(prev->EditHwnd, val);
     465                        }
     466                               
     467                        IPADDRESS_GotoNextField(infoPtr, index - 2, POS_RIGHT);
     468                        return 0;
     469                    }
     470                    break;
     471            }               
     472            break;
     473        case WM_KILLFOCUS:
     474            if (IPADDRESS_GetPartIndex(infoPtr, (HWND)wParam) < 0)
     475                IPADDRESS_Notify(infoPtr, EN_KILLFOCUS);
     476            break;
     477        case WM_SETFOCUS:
     478            if (IPADDRESS_GetPartIndex(infoPtr, (HWND)wParam) < 0)
     479                IPADDRESS_Notify(infoPtr, EN_SETFOCUS);
     480            break;
     481    }
     482    return CallWindowProcW (part->OrigProc, hwnd, uMsg, wParam, lParam);
    610483}
    611484
     
    614487IPADDRESS_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    615488{
    616   TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n", hwnd, uMsg, wParam, lParam);
    617   if (!IPADDRESS_GetInfoPtr (hwnd) && (uMsg != WM_CREATE))
    618       return DefWindowProcA (hwnd, uMsg, wParam, lParam);
    619   switch (uMsg)
    620   {
    621     case IPM_CLEARADDRESS:
    622       return IPADDRESS_ClearAddress (hwnd, wParam, lParam);
    623 
    624     case IPM_SETADDRESS:
    625       return IPADDRESS_SetAddress (hwnd, wParam, lParam);
    626 
    627     case IPM_GETADDRESS:
    628       return IPADDRESS_GetAddress (hwnd, wParam, lParam);
    629 
    630     case IPM_SETRANGE:
    631       return IPADDRESS_SetRange (hwnd, wParam, lParam);
    632 
    633     case IPM_SETFOCUS:
    634       return IPADDRESS_SetFocusToField (hwnd, wParam, lParam);
    635 
    636     case IPM_ISBLANK:
    637       return IPADDRESS_IsBlank (hwnd, wParam, lParam);
    638 
    639     case WM_CREATE:
    640       return IPADDRESS_Create (hwnd, wParam, lParam);
    641 
    642     case WM_DESTROY:
    643       return IPADDRESS_Destroy (hwnd, wParam, lParam);
    644 
    645     case WM_GETDLGCODE:
    646       return DLGC_WANTARROWS | DLGC_WANTCHARS;
    647 
    648     case WM_KILLFOCUS:
    649       return IPADDRESS_KillFocus (hwnd, wParam, lParam);
    650 
    651     case WM_LBUTTONDOWN:
    652       return IPADDRESS_LButtonDown (hwnd, wParam, lParam);
    653 
    654     case WM_PAINT:
    655       return IPADDRESS_Paint (hwnd, wParam);
    656 
    657     case WM_SETFOCUS:
    658       return IPADDRESS_SetFocus (hwnd, wParam, lParam);
    659 
    660     case WM_SIZE:
    661       return IPADDRESS_Size (hwnd, wParam, lParam);
    662 
    663     default:
    664       if (uMsg >= WM_USER)
    665         ERR("unknown msg %04x wp=%08x lp=%08lx\n",
    666                      uMsg, wParam, lParam);
    667       return DefWindowProcA (hwnd, uMsg, wParam, lParam);
     489    IPADDRESS_INFO *infoPtr = IPADDRESS_GetInfoPtr (hwnd);
     490 
     491    TRACE("(hwnd=0x%x msg=0x%x wparam=0x%x lparam=0x%lx)\n", hwnd, uMsg, wParam, lParam);
     492 
     493    if (!infoPtr && (uMsg != WM_CREATE))
     494        return DefWindowProcW (hwnd, uMsg, wParam, lParam);
     495 
     496    switch (uMsg)
     497    {
     498        case WM_CREATE:
     499            return IPADDRESS_Create (hwnd);
     500
     501        case WM_DESTROY:
     502            return IPADDRESS_Destroy (infoPtr);
     503
     504        case WM_PAINT:
     505            return IPADDRESS_Paint (infoPtr, (HDC)wParam);
     506
     507        case WM_COMMAND:
     508            switch(wParam >> 16) {
     509                case EN_CHANGE:
     510                    IPADDRESS_Notify(infoPtr, EN_CHANGE);
     511                    break;
     512                case EN_KILLFOCUS:
     513                    IPADDRESS_ConstrainField(infoPtr, IPADDRESS_GetPartIndex(infoPtr, (HWND)lParam));
     514                    break;
     515            }
     516            break;
     517
     518        case IPM_CLEARADDRESS:
     519            IPADDRESS_ClearAddress (infoPtr);
     520            break;
     521
     522        case IPM_SETADDRESS:
     523            return IPADDRESS_SetAddress (infoPtr, (DWORD)lParam);
     524
     525        case IPM_GETADDRESS:
     526            return IPADDRESS_GetAddress (infoPtr, (LPDWORD)lParam);
     527
     528        case IPM_SETRANGE:
     529            return IPADDRESS_SetRange (infoPtr, (int)wParam, (WORD)lParam);
     530
     531        case IPM_SETFOCUS:
     532            IPADDRESS_SetFocusToField (infoPtr, (int)wParam);
     533            break;
     534
     535        case IPM_ISBLANK:
     536            return IPADDRESS_IsBlank (infoPtr);
     537
     538        default:
     539            if (uMsg >= WM_USER)
     540                ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
     541            return DefWindowProcW (hwnd, uMsg, wParam, lParam);
    668542    }
    669543    return 0;
     
    673547void IPADDRESS_Register (void)
    674548{
    675   WNDCLASSA wndClass;
    676 
    677   ZeroMemory (&wndClass, sizeof(WNDCLASSA));
    678   wndClass.style         = CS_GLOBALCLASS;
    679   wndClass.lpfnWndProc   = (WNDPROC)IPADDRESS_WindowProc;
    680   wndClass.cbClsExtra    = 0;
    681   wndClass.cbWndExtra    = sizeof(IPADDRESS_INFO *);
    682   wndClass.hCursor       = LoadCursorA (0, IDC_ARROWA);
    683   wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
    684   wndClass.lpszClassName = WC_IPADDRESSA;
     549    WNDCLASSW wndClass;
     550
     551    ZeroMemory (&wndClass, sizeof(WNDCLASSW));
     552    wndClass.style         = CS_GLOBALCLASS;
     553    wndClass.lpfnWndProc   = (WNDPROC)IPADDRESS_WindowProc;
     554    wndClass.cbClsExtra    = 0;
     555    wndClass.cbWndExtra    = sizeof(IPADDRESS_INFO *);
     556    wndClass.hCursor       = LoadCursorW (0, IDC_IBEAMW);
     557    wndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
     558    wndClass.lpszClassName = WC_IPADDRESSW;
    685559 
    686   RegisterClassA (&wndClass);
    687 }
    688 
    689 
    690 VOID IPADDRESS_Unregister (void)
    691 {
    692   UnregisterClassA (WC_IPADDRESSA, (HINSTANCE)NULL);
    693 }
     560    RegisterClassW (&wndClass);
     561}
     562
     563
     564void IPADDRESS_Unregister (void)
     565{
     566    UnregisterClassW (WC_IPADDRESSW, (HINSTANCE)NULL);
     567}
  • 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 
  • trunk/src/comctl32/pager.c

    r6705 r8382  
    33 *
    44 * Copyright 1998, 1999 Eric Kohl
     5 *
     6 * This library is free software; you can redistribute it and/or
     7 * modify it under the terms of the GNU Lesser General Public
     8 * License as published by the Free Software Foundation; either
     9 * version 2.1 of the License, or (at your option) any later version.
     10 *
     11 * This library is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14 * Lesser General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU Lesser General Public
     17 * License along with this library; if not, write to the Free Software
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    519 *
    620 * NOTES
     
    1832#include "winbase.h"
    1933#include "commctrl.h"
    20 #include "debugtools.h"
    21 
    22 DEFAULT_DEBUG_CHANNEL(pager);
    23 
    24 #ifdef __WIN32OS2__
    25 #include "ccbase.h"
    26 #undef inline
    27 #define inline
    28 #endif
     34#include "wine/debug.h"
     35
     36WINE_DEFAULT_DEBUG_CHANNEL(pager);
    2937
    3038typedef struct
    3139{
    32 #ifdef __WIN32OS2__
    33     COMCTL32_HEADER header;
    34 #endif
    3540    HWND   hwndChild;  /* handle of the contained wnd */
    3641    BOOL   bNoResize;  /* set when created with CCS_NORESIZE */
     
    594599}
    595600
     601/******************************************************************
     602 * For the PGM_RECALCSIZE message (but not the other uses in      *
     603 * this module), the native control does only the following:      *
     604 *                                                                *
     605 *    if (some condition)                                         *
     606 *          PostMessageA(hwnd, EM_FMTLINES, 0, 0);                *
     607 *    return DefWindowProcA(hwnd, PGM_RECALCSIZE, 0, 0);          *
     608 *                                                                *
     609 * When we figure out what the "some condition" is we will        *
     610 * implement that for the message processing.                     *
     611 ******************************************************************/
     612
    596613static LRESULT
    597614PAGER_RecalcSize(HWND hwnd)
     
    630647    TRACE("[%04x] %06lx\n", hwnd, infoPtr->clrBk);
    631648
    632     PAGER_RecalcSize(hwnd);
    633     SendMessageA(hwnd, WM_NCPAINT, (WPARAM)0, (LPARAM)0);
     649    /* the native control seems to do things this way */
     650    SetWindowPos(hwnd, 0,0,0,0,0,
     651                 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
     652                 SWP_NOZORDER | SWP_NOACTIVATE);
     653
     654    RedrawWindow(hwnd, 0, 0, RDW_ERASE | RDW_INVALIDATE);
    634655
    635656    return (LRESULT)clrTemp;
     
    757778
    758779static LRESULT
     780PAGER_FmtLines(HWND hwnd)
     781{
     782    PAGER_INFO *infoPtr = PAGER_GetInfoPtr (hwnd);
     783
     784    /* initiate NCCalcSize to resize client wnd and get size */
     785    SetWindowPos(hwnd, 0, 0,0,0,0,
     786                 SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE |
     787                 SWP_NOZORDER | SWP_NOACTIVATE);
     788
     789    SetWindowPos(infoPtr->hwndChild, 0,
     790                 0,0,infoPtr->nWidth,infoPtr->nHeight,
     791                 0);
     792
     793    return DefWindowProcA (hwnd, EM_FMTLINES, 0, 0);
     794}
     795
     796static LRESULT
    759797PAGER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
    760798{
     
    763801
    764802    /* allocate memory for info structure */
    765 #ifdef __WIN32OS2__
    766     infoPtr =(PAGER_INFO*)initControl(hwnd,sizeof(PAGER_INFO));
    767 #else
    768803    infoPtr = (PAGER_INFO *)COMCTL32_Alloc (sizeof(PAGER_INFO));
    769 #endif
    770804    SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
    771805
     
    820854    RECT rcChildw, rcmyw, wnrc, lbrc, rbrc;
    821855    POINT cursor;
     856    BOOL resizeClient = FALSE;
     857    BOOL repaintBtns = FALSE;
     858    INT scrollRange;
    822859
    823860    /*
     
    830867    DefWindowProcA (hwnd, WM_NCCALCSIZE, wParam, lParam);
    831868
     869    TRACE("orig rect=(%d,%d)-(%d,%d)\n",
     870          lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
     871
    832872    if (PAGER_IsHorizontal(hwnd))
    833873    {
     
    838878        GetCursorPos (&cursor);
    839879        GetWindowRect (hwnd, &rcmyw);
     880
     881        /* Reset buttons and hide any grey ones */
     882        scrollRange = infoPtr->nWidth - (rcmyw.right - rcmyw.left);
     883
     884        TRACE("nPos=%d, scrollrange=%d, nWidth=%d, myw=(%d,%d)-(%d,%d)\n",
     885              infoPtr->nPos, scrollRange, infoPtr->nWidth,
     886              rcmyw.left, rcmyw.top, rcmyw.right, rcmyw.bottom);
     887        PAGER_GrayAndRestoreBtns(infoPtr, scrollRange, &resizeClient, &repaintBtns);
     888        PAGER_HideGrayBtns(infoPtr, &resizeClient);
     889
    840890        if (PtInRect (&rcmyw, cursor)) {
    841891            GetWindowRect (hwnd, &wnrc);
     
    852902                RedrawWindow (hwnd, 0, 0, RDW_INVALIDATE | RDW_ERASE);
    853903        }
    854         if (infoPtr->TLbtnState) /* != PGF_INVISIBLE */
     904        if (infoPtr->TLbtnState && (lpRect->left + infoPtr->nButtonSize < lpRect->right))
    855905            lpRect->left += infoPtr->nButtonSize;
    856         if (infoPtr->BRbtnState)
     906        if (infoPtr->BRbtnState && (lpRect->right - infoPtr->nButtonSize > lpRect->left))
    857907            lpRect->right -= infoPtr->nButtonSize;
    858908    }
     
    875925        GetCursorPos (&cursor);
    876926        GetWindowRect (hwnd, &rcmyw);
     927
     928        /* Reset buttons and hide any grey ones */
     929        scrollRange = infoPtr->nHeight - (rcmyw.bottom - rcmyw.top);
     930
     931        TRACE("nPos=%d, scrollrange=%d, nHeigth=%d, myw=(%d,%d)-(%d,%d)\n",
     932              infoPtr->nPos, scrollRange, infoPtr->nHeight,
     933              rcmyw.left, rcmyw.top,
     934              rcmyw.right, rcmyw.bottom);
     935        PAGER_GrayAndRestoreBtns(infoPtr, scrollRange, &resizeClient, &repaintBtns);
     936        PAGER_HideGrayBtns(infoPtr, &resizeClient);
     937
    877938        if (PtInRect (&rcmyw, cursor)) {
    878939
     
    900961                RedrawWindow (hwnd, 0, 0, RDW_INVALIDATE | RDW_ERASE);
    901962        }
    902         if (infoPtr->TLbtnState)
     963        if (infoPtr->TLbtnState && (lpRect->top + infoPtr->nButtonSize < lpRect->bottom))
    903964            lpRect->top += infoPtr->nButtonSize;
    904         if (infoPtr->BRbtnState)
     965        if (infoPtr->BRbtnState && (lpRect->bottom - infoPtr->nButtonSize > lpRect->top))
    905966            lpRect->bottom -= infoPtr->nButtonSize;
    906967        /* ???? */
     
    909970    }
    910971
    911     TRACE("[%04x] client rect set to %dx%d at (%d,%d)\n", hwnd,
    912                 lpRect->right-lpRect->left,
    913                 lpRect->bottom-lpRect->top,
    914                 lpRect->left, lpRect->top);
     972    TRACE("[%04x] client rect set to %dx%d at (%d,%d) BtnState[%d,%d]\n",
     973          hwnd, lpRect->right-lpRect->left, lpRect->bottom-lpRect->top,
     974          lpRect->left, lpRect->top,
     975          infoPtr->TLbtnState, infoPtr->BRbtnState);
    915976
    916977    return 0;
     
    12481309    switch (uMsg)
    12491310    {
     1311        case EM_FMTLINES:
     1312            return PAGER_FmtLines(hwnd);
     1313
    12501314        case PGM_FORWARDMOUSE:
    12511315            return PAGER_ForwardMouse (hwnd, wParam);
     
    13561420
    13571421        default:
    1358 #ifdef __WIN32OS2__
    1359             return defComCtl32ProcA(hwnd, uMsg, wParam, lParam);
    1360 #else
    13611422            return DefWindowProcA (hwnd, uMsg, wParam, lParam);
    1362 #endif
    13631423    }
    13641424
  • trunk/src/comctl32/rebar.c

    r7815 r8382  
    2121
    2222/*
    23  * Rebar control    rev 8b
     23 * Rebar control    rev 8e
    2424 *
    2525 * Copyright 1998, 1999 Eric Kohl
     26 *
     27 * This library is free software; you can redistribute it and/or
     28 * modify it under the terms of the GNU Lesser General Public
     29 * License as published by the Free Software Foundation; either
     30 * version 2.1 of the License, or (at your option) any later version.
     31 *
     32 * This library is distributed in the hope that it will be useful,
     33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     35 * Lesser General Public License for more details.
     36 *
     37 * You should have received a copy of the GNU Lesser General Public
     38 * License along with this library; if not, write to the Free Software
     39 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2640 *
    2741 * NOTES
     
    94108 * rev 8c
    95109 * 19. Fix problem in _Layout when all lengths are 0.
     110 * 20. If CLR_NONE specified, we will use default BtnFace color when drawing.
     111 * 21. Fix test in REBAR_Layout.
     112 * rev 8d
     113 * 22. Add support for WM_WINDOWPOSCHANGED to save new origin of window.
     114 * 23. Correct RBN_CHILDSIZE rect value for CCS_VERT rebar.
     115 * 24. Do UpdateWindow only if doing redraws.
     116 * rev 8e
     117 * 25. Adjust setting of offChild.cx based on RBBS_CHILDEDGE.
    96118 *
    97119 *
     
    126148#include "commctrl.h"
    127149/* #include "spy.h" */
    128 #include "debugtools.h"
    129 
    130 DEFAULT_DEBUG_CHANNEL(rebar);
     150#include "wine/debug.h"
     151
     152WINE_DEFAULT_DEBUG_CHANNEL(rebar);
    131153
    132154typedef struct
     
    225247    INT      ihitBand;    /* band number of band whose gripper was grabbed */
    226248    INT      ihitoffset;  /* offset of hotspot from gripper.left */
     249    POINT    origin;      /* left/upper corner of client */
    227250
    228251    REBAR_ROW  *rows;       /* pointer to row indexes              */
     
    11981221        width += infoPtr->calcSize.cx;
    11991222        height += infoPtr->calcSize.cy;
    1200     }
    1201 
    1202     TRACE("hwnd %04x, style=%08lx, setting at (%d,%d) for (%d,%d)\n",
     1223        x = infoPtr->origin.x;
     1224        y = infoPtr->origin.y;
     1225    }
     1226
     1227    TRACE("hwnd %08x, style=%08lx, setting at (%d,%d) for (%d,%d)\n",
    12031228        infoPtr->hwndSelf, infoPtr->dwStyle,
    12041229        x, y, width, height);
     
    12341259            rbcz.rcChild = lpBand->rcChild;
    12351260            rbcz.rcBand = lpBand->rcBand;
    1236             rbcz.rcBand.left += lpBand->cxHeader;
     1261            if (infoPtr->dwStyle & CCS_VERT)
     1262                rbcz.rcBand.top += lpBand->cxHeader;
     1263            else
     1264                rbcz.rcBand.left += lpBand->cxHeader;
    12371265            REBAR_Notify ((NMHDR *)&rbcz, infoPtr, RBN_CHILDSIZE);
    12381266            if (!EqualRect (&lpBand->rcChild, &rbcz.rcChild)) {
     
    13031331        ERR("EndDeferWindowPos returned NULL\n");
    13041332
    1305     UpdateWindow (infoPtr->hwndSelf);
     1333    if (infoPtr->DoRedraw)
     1334        UpdateWindow (infoPtr->hwndSelf);
    13061335
    13071336    if (infoPtr->fStatus & NTF_HGHTCHG) {
     
    14061435        if ((lpBand->fMask & RBBIM_CHILD) &&
    14071436            !(lpBand->fStyle & RBBS_FIXEDSIZE)) {
    1408             lpBand->offChild.cx = 4;   /* ??? */
     1437            lpBand->offChild.cx = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 4 : 0);
    14091438        }
    14101439        lpBand->offChild.cy = ((lpBand->fStyle & RBBS_CHILDEDGE) ? 2 : 0);
     
    17321761            lpBand = &infoPtr->bands[iband];
    17331762            if(HIDDENBAND(lpBand)) continue;
    1734             if (!(lpBand->fMask & RBBS_VARIABLEHEIGHT)) continue;
     1763            if (lpBand->fMask & RBBS_VARIABLEHEIGHT) continue;
    17351764            if (((INT)lpBand->cyMaxChild < 1) ||
    17361765                ((INT)lpBand->cyIntegral < 1)) {
     
    21412170            new = RGB(0,128,0);
    21422171#endif
    2143             old = SetBkColor (hdc, new);
    2144         }
     2172        }
     2173        else {
     2174            /* In the absence of documentation for Rebar vs. CLR_NONE,
     2175             * we will use the default BtnFace color. Note documentation
     2176             * exists for Listview and Imagelist.
     2177             */
     2178            new = infoPtr->clrBtnFace;
     2179#if GLATESTING
     2180            /* testing only - make background green to see it */
     2181            new = RGB(0,128,0);
     2182#endif
     2183        }
     2184        old = SetBkColor (hdc, new);
    21452185
    21462186        rect = lpBand->rcBand;
     
    37413781    POINTS ptsmove;
    37423782
    3743     /* Validate entry as hit on Gripper has occured */
     3783    /* Validate entry as hit on Gripper has occurred */
    37443784    if (GetCapture() != infoPtr->hwndSelf) return 0;
    37453785    if (infoPtr->ihitBand == -1) return 0;
     
    41974237
    41984238
     4239static LRESULT
     4240REBAR_WindowPosChanged (REBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     4241{
     4242    WINDOWPOS *lpwp = (WINDOWPOS *)lParam;
     4243    LRESULT ret;
     4244    RECT rc;
     4245
     4246    /* Save the new origin of this window - used by _ForceResize */
     4247    infoPtr->origin.x = lpwp->x;
     4248    infoPtr->origin.y = lpwp->y;
     4249    ret = DefWindowProcA(infoPtr->hwndSelf, WM_WINDOWPOSCHANGED,
     4250                         wParam, lParam);
     4251    GetWindowRect(infoPtr->hwndSelf, &rc);
     4252    TRACE("hwnd %08x new pos (%d,%d)-(%d,%d)\n",
     4253          infoPtr->hwndSelf, rc.left, rc.top, rc.right, rc.bottom);
     4254    return ret;
     4255}
     4256
     4257
    41994258static LRESULT WINAPI
    42004259REBAR_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
     
    44094468/*      case WM_VKEYTOITEM:     supported according to ControlSpy */
    44104469/*      case WM_WININICHANGE: */
     4470
     4471        case WM_WINDOWPOSCHANGED:
     4472            return REBAR_WindowPosChanged (infoPtr, wParam, lParam);
    44114473
    44124474        default:
  • trunk/src/comctl32/rsrc.orc

    r3972 r8382  
    1 /* $Id: rsrc.orc,v 1.6 2000-08-09 15:57:55 cbratschi Exp $ */
     1/* $Id: rsrc.orc,v 1.7 2002-05-08 11:25:02 sandervl Exp $ */
    22/*
    33 * Top level resource file for Common Controls
     
    1616 * being duplicated for each language.
    1717 */
    18 #include "cctl_xx.orc"
     18#include "resources\cctl_xx.orc"
    1919
    2020/*
     
    2626 */
    2727
    28 #include "cctl_Ca.orc"
    29 #include "cctl_Cs.orc"
    30 #include "cctl_Da.orc"
    31 #include "cctl_De.orc"
    32 #include "cctl_En.orc"
    33 #include "cctl_Eo.orc"
    34 #include "cctl_Es.orc"
    35 #include "cctl_Fi.orc"
    36 #include "cctl_Fr.orc"
    37 #include "cctl_Hu.orc"
    38 #include "cctl_It.orc"
    39 #include "cctl_Ko.orc"
    40 #include "cctl_Nl.orc"
    41 #include "cctl_No.orc"
    42 #include "cctl_Pl.orc"
    43 #include "cctl_Pt.orc"
    44 #include "cctl_Ru.orc"
    45 #include "cctl_Sv.orc"
    46 #include "cctl_Wa.orc"
     28#include "resources\cctl_Ca.orc"
     29#include "resources\cctl_Cs.orc"
     30#include "resources\cctl_Da.orc"
     31#include "resources\cctl_De.orc"
     32#include "resources\cctl_En.orc"
     33#include "resources\cctl_Eo.orc"
     34#include "resources\cctl_Es.orc"
     35#include "resources\cctl_Fi.orc"
     36#include "resources\cctl_Fr.orc"
     37#include "resources\cctl_Hu.orc"
     38#include "resources\cctl_It.orc"
     39#include "resources\cctl_Ko.orc"
     40#include "resources\cctl_Nl.orc"
     41#include "resources\cctl_No.orc"
     42#include "resources\cctl_Pl.orc"
     43#include "resources\cctl_Pt.orc"
     44#include "resources\cctl_Ru.orc"
     45#include "resources\cctl_Sv.orc"
     46#include "resources\cctl_Wa.orc"
  • trunk/src/comctl32/tab.c

    r7815 r8382  
    55 * Copyright 1999 Alex Priem <alexp@sci.kun.nl>
    66 * Copyright 1999 Francis Beaudet
     7 *
     8 * This library is free software; you can redistribute it and/or
     9 * modify it under the terms of the GNU Lesser General Public
     10 * License as published by the Free Software Foundation; either
     11 * version 2.1 of the License, or (at your option) any later version.
     12 *
     13 * This library is distributed in the hope that it will be useful,
     14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16 * Lesser General Public License for more details.
     17 *
     18 * You should have received a copy of the GNU Lesser General Public
     19 * License along with this library; if not, write to the Free Software
     20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    721 *
    822 * TODO:
     
    1933#include "commctrl.h"
    2034#include "comctl32.h"
    21 #include "debugtools.h"
     35#include "wine/debug.h"
    2236#include <math.h>
    2337
    24 DEFAULT_DEBUG_CHANNEL(tab);
     38WINE_DEFAULT_DEBUG_CHANNEL(tab);
    2539
    2640typedef struct
  • trunk/src/comctl32/toolbar.c

    r7815 r8382  
    44 * Copyright 1998,1999 Eric Kohl
    55 * Copyright 2000 Eric Kohl for CodeWeavers
     6 *
     7 * This library is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU Lesser General Public
     9 * License as published by the Free Software Foundation; either
     10 * version 2.1 of the License, or (at your option) any later version.
     11 *
     12 * This library is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15 * Lesser General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU Lesser General Public
     18 * License along with this library; if not, write to the Free Software
     19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    620 *
    721 *  Differences between MSDN and actual native control operation:
     
    5670#include "imagelist.h"
    5771#include "comctl32.h"
    58 #include "debugtools.h"
    59 
    60 DEFAULT_DEBUG_CHANNEL(toolbar);
     72#include "wine/debug.h"
     73
     74WINE_DEFAULT_DEBUG_CHANNEL(toolbar);
    6175
    6276typedef struct
     
    7387    RECT rect;
    7488} TBUTTON_INFO;
     89
     90typedef struct
     91{
     92    UINT nButtons;
     93    HINSTANCE hInst;
     94    UINT nID;
     95} TBITMAP_INFO;
    7596
    7697typedef struct
     
    91112    INT      nNumBitmaps;     /* number of bitmaps */
    92113    INT      nNumStrings;     /* number of strings */
     114    INT      nNumBitmapInfos;
    93115    BOOL     bUnicode;        /* ASCII (FALSE) or Unicode (TRUE)? */
    94116    BOOL     bCaptured;       /* mouse captured? */
     
    96118    INT      nOldHit;
    97119    INT      nHotItem;        /* index of the "hot" item */
     120    DWORD    dwBaseCustDraw;  /* CDRF_ response (w/o TBCDRF_) from PREPAINT */
     121    DWORD    dwItemCustDraw;  /* CDRF_ response (w/o TBCDRF_) from ITEMPREP */
     122    DWORD    dwItemCDFlag;    /* TBCDRF_ flags from last ITEMPREPAINT    */
     123    SIZE     szPadding;       /* padding values around button */
    98124    HFONT    hDefaultFont;
    99125    HFONT    hFont;           /* text font */
     
    115141
    116142    COLORREF   clrInsertMark;   /* insert mark color */
     143    COLORREF   clrBtnHighlight; /* color for Flat Separator */
     144    COLORREF   clrBtnShadow;    /* color for Flag Separator */
    117145    RECT     rcBound;         /* bounding rectangle */
    118146    INT      iVersion;
     
    120148    TBUTTON_INFO *buttons;      /* pointer to button array */
    121149    LPWSTR       *strings;      /* pointer to string array */
     150    TBITMAP_INFO *bitmaps;
    122151} TOOLBAR_INFO, *PTOOLBAR_INFO;
    123152
     
    147176#define TOOLBAR_HasText(x, y) (TOOLBAR_GetText(x, y) ? TRUE : FALSE)
    148177#define TOOLBAR_HasDropDownArrows(exStyle) ((exStyle & TBSTYLE_EX_DRAWDDARROWS) ? TRUE : FALSE)
     178
     179/* Used to find undocumented extended styles */
     180#define TBSTYLE_EX_ALL (TBSTYLE_EX_DRAWDDARROWS | \
     181                        TBSTYLE_EX_UNDOC1 | \
     182                        TBSTYLE_EX_MIXEDBUTTONS | \
     183                        TBSTYLE_EX_HIDECLIPPEDBUTTONS)
     184
     185static LRESULT
     186TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam);
    149187
    150188
     
    302340
    303341    if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
     342        if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
    304343        ERR("index %d is not valid, max %d\n",
    305344            btnPtr->iBitmap, infoPtr->nNumBitmaps);
     
    308347
    309348    if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
    310         if (index == -1) return FALSE;
     349        if ((index == I_IMAGECALLBACK) ||
     350            (index == I_IMAGENONE)) return FALSE;
    311351        ERR("TBN_GETDISPINFO returned invalid index %d\n",
    312352            index);
     
    335375
    336376    if (!TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
     377        if (btnPtr->iBitmap == I_IMAGENONE) return FALSE;
    337378        ERR("index %d is not valid, max %d\n",
    338379            btnPtr->iBitmap, infoPtr->nNumBitmaps);
     
    341382
    342383    if ((index = TOOLBAR_GetBitmapIndex(infoPtr, btnPtr)) < 0) {
    343         if (index == -1) return FALSE;
     384        if ((index == I_IMAGECALLBACK) ||
     385            (index == I_IMAGENONE)) return FALSE;
    344386        ERR("TBN_GETDISPINFO returned invalid index %d\n",
    345387            index);
     
    351393
    352394static void
    353 TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc)
    354 {
    355     INT x = (lpRect->left + lpRect->right) / 2 - 1;
    356     INT yBottom = lpRect->bottom - 3;
    357     INT yTop = lpRect->top + 1;
    358 
    359     SelectObject ( hdc, GetSysColorPen (COLOR_3DSHADOW));
    360     MoveToEx (hdc, x, yBottom, NULL);
    361     LineTo (hdc, x, yTop);
    362     x++;
    363     SelectObject ( hdc, GetSysColorPen (COLOR_3DHILIGHT));
    364     MoveToEx (hdc, x, yBottom, NULL);
    365     LineTo (hdc, x, yTop);
     395TOOLBAR_DrawFlatSeparator (LPRECT lpRect, HDC hdc, TOOLBAR_INFO *infoPtr)
     396{
     397    RECT myrect;
     398    COLORREF oldcolor, newcolor;
     399
     400    myrect.left = (lpRect->left + lpRect->right) / 2 - 1;
     401    myrect.right = myrect.left + 1;
     402    myrect.top = lpRect->top + 2;
     403    myrect.bottom = lpRect->bottom - 2;
     404
     405    newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
     406                comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
     407    oldcolor = SetBkColor (hdc, newcolor);
     408    ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
     409
     410    myrect.left = myrect.right;
     411    myrect.right = myrect.left + 1;
     412
     413    newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
     414                comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
     415    SetBkColor (hdc, newcolor);
     416    ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
     417
     418    SetBkColor (hdc, oldcolor);
    366419}
    367420
     
    379432*/
    380433static void
    381 TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr)
     434TOOLBAR_DrawDDFlatSeparator (LPRECT lpRect, HDC hdc, TBUTTON_INFO *btnPtr, TOOLBAR_INFO *infoPtr)
    382435{
    383436    RECT myrect;
     
    394447          myrect.left, myrect.top, myrect.right, myrect.bottom);
    395448
    396     newcolor = GetSysColor (COLOR_BTNSHADOW);
     449    newcolor = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
     450                comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
    397451    oldcolor = SetBkColor (hdc, newcolor);
    398452    ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
     
    401455    myrect.bottom = myrect.top + 1;
    402456
    403     newcolor = GetSysColor (COLOR_BTNHIGHLIGHT);
     457    newcolor = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
     458                comctl32_color.clrBtnHighlight : infoPtr->clrBtnHighlight;
    404459    SetBkColor (hdc, newcolor);
    405460    ExtTextOutA (hdc, 0, 0, ETO_OPAQUE, &myrect, 0, 0, 0);
     
    432487static void
    433488TOOLBAR_DrawString (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
    434                     HDC hdc, INT nState, DWORD dwStyle)
    435 {
    436     RECT   rcText = btnPtr->rect;
    437     HFONT  hOldFont;
    438     COLORREF clrOld;
     489                    HDC hdc, INT nState, DWORD dwStyle,
     490                    RECT *rcText, LPWSTR lpText, NMTBCUSTOMDRAW *tbcd)
     491{
     492    HFONT  hOldFont = 0;
     493    COLORREF clrOld = 0;
     494
     495    /* draw text */
     496    if (lpText) {
     497        TRACE("string rect=(%d,%d)-(%d,%d)\n",
     498              rcText->left, rcText->top, rcText->right, rcText->bottom);
     499
     500        hOldFont = SelectObject (hdc, infoPtr->hFont);
     501        if (!(nState & TBSTATE_ENABLED)) {
     502            clrOld = SetTextColor (hdc, tbcd->clrBtnHighlight);
     503            OffsetRect (rcText, 1, 1);
     504            DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
     505            SetTextColor (hdc, comctl32_color.clr3dShadow);
     506            OffsetRect (rcText, -1, -1);
     507        }
     508        else if (nState & TBSTATE_INDETERMINATE) {
     509            clrOld = SetTextColor (hdc, comctl32_color.clr3dShadow);
     510        }
     511        else if (btnPtr->bHot && (infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )) {
     512            clrOld = SetTextColor (hdc, tbcd->clrTextHighlight);
     513        }
     514        else {
     515            clrOld = SetTextColor (hdc, tbcd->clrText);
     516        }
     517
     518        DrawTextW (hdc, lpText, -1, rcText, infoPtr->dwDTFlags);
     519        SetTextColor (hdc, clrOld);
     520        SelectObject (hdc, hOldFont);
     521    }
     522}
     523
     524
     525static void
     526TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
     527{
     528    HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
     529    INT cx = lpRect->right - lpRect->left;
     530    INT cy = lpRect->bottom - lpRect->top;
     531    PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
     532    SelectObject (hdc, hbr);
     533}
     534
     535
     536static void
     537TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
     538                    HDC hdc, INT x, INT y)
     539{
     540    /* FIXME: this function is a hack since it uses image list
     541              internals directly */
     542
     543    HIMAGELIST himl = infoPtr->himlDef;
     544    HBITMAP hbmMask;
     545    HDC hdcImageList;
     546    HDC hdcMask;
     547
     548    if (!himl)
     549        return;
     550
     551    /* create new dc's */
     552    hdcImageList = CreateCompatibleDC (0);
     553    hdcMask = CreateCompatibleDC (0);
     554
     555    /* create new bitmap */
     556    hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
     557    SelectObject (hdcMask, hbmMask);
     558
     559    /* copy the mask bitmap */
     560    SelectObject (hdcImageList, himl->hbmMask);
     561    SetBkColor (hdcImageList, RGB(255, 255, 255));
     562    SetTextColor (hdcImageList, RGB(0, 0, 0));
     563    BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
     564              hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
     565
     566    /* draw the new mask */
     567    SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
     568    BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
     569              hdcMask, 0, 0, 0xB8074A);
     570
     571    SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
     572    BitBlt (hdc, x, y, himl->cx, himl->cy,
     573              hdcMask, 0, 0, 0xB8074A);
     574
     575    DeleteObject (hbmMask);
     576    DeleteDC (hdcMask);
     577    DeleteDC (hdcImageList);
     578}
     579
     580
     581static UINT
     582TOOLBAR_TranslateState(TBUTTON_INFO *btnPtr)
     583{
     584    UINT retstate = 0;
     585
     586    retstate |= (btnPtr->fsState & TBSTATE_CHECKED) ? CDIS_CHECKED  : 0;
     587    retstate |= (btnPtr->fsState & TBSTATE_PRESSED) ? CDIS_SELECTED : 0;
     588    retstate |= (btnPtr->fsState & TBSTATE_ENABLED) ? 0 : CDIS_DISABLED;
     589    retstate |= (btnPtr->fsState & TBSTATE_MARKED ) ? CDIS_MARKED   : 0;
     590    retstate |= (btnPtr->bHot                     ) ? CDIS_HOT      : 0;
     591    retstate |= (btnPtr->fsState & TBSTATE_INDETERMINATE) ? CDIS_INDETERMINATE : 0;
     592    /* FIXME: don't set CDIS_GRAYED, CDIS_FOCUS, CDIS_DEFAULT       */
     593    /*        don't test TBSTATE_HIDDEN                             */
     594    return retstate;
     595}
     596
     597
     598static void
     599TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
     600{
     601    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     602    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
     603    BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
     604                            (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
     605    RECT rc, rcArrow, rcBitmap, rcText, rcFill;
    439606    LPWSTR lpText = NULL;
    440     HIMAGELIST himl = infoPtr->himlDef;
    441 
    442     TRACE ("iString: %x\n", btnPtr->iString);
     607    NMTBCUSTOMDRAW tbcd;
     608    DWORD ntfret;
     609    INT offset;
     610
     611    if (btnPtr->fsState & TBSTATE_HIDDEN)
     612        return;
     613
     614    rc = btnPtr->rect;
     615    CopyRect (&rcFill, &rc);
     616    CopyRect (&rcArrow, &rc);
     617    CopyRect(&rcBitmap, &rc);
     618    CopyRect(&rcText, &rc);
    443619
    444620    /* get a pointer to the text */
    445621    lpText = TOOLBAR_GetText(infoPtr, btnPtr);
    446622
     623    if (hasDropDownArrow)
     624    {
     625        if (dwStyle & TBSTYLE_FLAT)
     626            rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
     627        else
     628            rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
     629        rcArrow.left = rc.right;
     630    }
     631
     632    /* Center the bitmap horizontally and vertically */
     633    if (dwStyle & TBSTYLE_LIST)
     634        rcBitmap.left += 3;
     635    else
     636        rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
     637
     638    if(lpText)
     639        rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
     640    else
     641        rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
     642
     643    TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
     644          btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
     645          infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
     646    TRACE ("iString: %x\n", btnPtr->iString);
    447647    TRACE ("Stringtext: %s\n", debugstr_w(lpText));
    448648
     
    452652        InflateRect (&rcText, -3, -3);
    453653
    454         if (himl && TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
     654        if (infoPtr->himlDef &&
     655            TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) {
    455656                /* The following test looked like this before
    456657                 * I changed it. IE4 "Links" toolbar would not
     
    477678        }
    478679
    479         if (nState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
     680        if (btnPtr->fsState & (TBSTATE_PRESSED | TBSTATE_CHECKED))
    480681            OffsetRect (&rcText, 1, 1);
    481 
    482         TRACE("string rect=(%d,%d)-(%d,%d)\n",
    483               rcText.left, rcText.top, rcText.right, rcText.bottom);
    484 
    485         hOldFont = SelectObject (hdc, infoPtr->hFont);
    486         if (!(nState & TBSTATE_ENABLED)) {
    487             clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DHILIGHT));
    488             OffsetRect (&rcText, 1, 1);
    489             DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
    490             SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
    491             OffsetRect (&rcText, -1, -1);
    492             DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
    493         }
    494         else if (nState & TBSTATE_INDETERMINATE) {
    495             clrOld = SetTextColor (hdc, GetSysColor (COLOR_3DSHADOW));
    496             DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
    497         }
    498         else {
    499             clrOld = SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT));
    500             DrawTextW (hdc, lpText, -1, &rcText, infoPtr->dwDTFlags);
    501         }
    502 
    503         SetTextColor (hdc, clrOld);
    504         SelectObject (hdc, hOldFont);
    505     }
    506 }
    507 
    508 
    509 static void
    510 TOOLBAR_DrawPattern (HDC hdc, LPRECT lpRect)
    511 {
    512     HBRUSH hbr = SelectObject (hdc, COMCTL32_hPattern55AABrush);
    513     INT cx = lpRect->right - lpRect->left;
    514     INT cy = lpRect->bottom - lpRect->top;
    515     PatBlt (hdc, lpRect->left, lpRect->top, cx, cy, 0x00FA0089);
    516     SelectObject (hdc, hbr);
    517 }
    518 
    519 
    520 static void
    521 TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
    522                     HDC hdc, INT x, INT y)
    523 {
    524     /* FIXME: this function is a hack since it uses image list
    525               internals directly */
    526 
    527     HIMAGELIST himl = infoPtr->himlDef;
    528     HBITMAP hbmMask;
    529     HDC hdcImageList;
    530     HDC hdcMask;
    531 
    532     if (!himl)
    533         return;
    534 
    535     /* create new dc's */
    536     hdcImageList = CreateCompatibleDC (0);
    537     hdcMask = CreateCompatibleDC (0);
    538 
    539     /* create new bitmap */
    540     hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
    541     SelectObject (hdcMask, hbmMask);
    542 
    543     /* copy the mask bitmap */
    544     SelectObject (hdcImageList, himl->hbmMask);
    545     SetBkColor (hdcImageList, RGB(255, 255, 255));
    546     SetTextColor (hdcImageList, RGB(0, 0, 0));
    547     BitBlt (hdcMask, 0, 0, himl->cx, himl->cy,
    548               hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY);
    549 
    550     /* draw the new mask */
    551     SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT));
    552     BitBlt (hdc, x+1, y+1, himl->cx, himl->cy,
    553               hdcMask, 0, 0, 0xB8074A);
    554 
    555     SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW));
    556     BitBlt (hdc, x, y, himl->cx, himl->cy,
    557               hdcMask, 0, 0, 0xB8074A);
    558 
    559     DeleteObject (hbmMask);
    560     DeleteDC (hdcMask);
    561     DeleteDC (hdcImageList);
    562 }
    563 
    564 
    565 static void
    566 TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
    567 {
    568     TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    569     DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    570     BOOL hasDropDownArrow = TOOLBAR_HasDropDownArrows(infoPtr->dwExStyle) &&
    571                             (btnPtr->fsStyle & TBSTYLE_DROPDOWN);
    572     RECT rc, rcArrow, rcBitmap;
    573 
    574     if (btnPtr->fsState & TBSTATE_HIDDEN)
    575         return;
    576 
    577     rc = btnPtr->rect;
    578     CopyRect (&rcArrow, &rc);
    579     CopyRect(&rcBitmap, &rc);
     682    }
     683
     684    /* Initialize fields in all cases, because we use these later */
     685    ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
     686    tbcd.clrText = comctl32_color.clrBtnText;
     687    tbcd.clrTextHighlight = comctl32_color.clrHighlightText;
     688    tbcd.clrBtnFace = comctl32_color.clrBtnFace;
     689    tbcd.clrBtnHighlight = comctl32_color.clrBtnHighlight;
     690    tbcd.clrMark = comctl32_color.clrHighlight;
     691    tbcd.clrHighlightHotTrack = 0;
     692    tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
     693    tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
     694    /* MSDN says that this is the text rectangle.              */
     695    /* But (why always a but) tracing of v5.7 of native shows  */
     696    /* that this is really a *relative* rectangle based on the */
     697    /* the nmcd.rc. Also the left and top are always 0 ignoring*/
     698    /* any bitmap that might be present.                       */
     699    tbcd.rcText.left = 0;
     700    tbcd.rcText.top = 0;
     701    tbcd.rcText.right = rcText.right - rc.left;
     702    tbcd.rcText.bottom = rcText.bottom - rc.top;
     703
     704    /* FIXME: what should these be set to ????? */
     705    tbcd.hbrMonoDither = 0;
     706    tbcd.hbrLines = 0;
     707    tbcd.hpenLines = 0;
     708
     709    /* Issue Item Prepaint notify */
     710    infoPtr->dwItemCustDraw = 0;
     711    infoPtr->dwItemCDFlag = 0;
     712    if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYITEMDRAW)
     713    {
     714        tbcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
     715        tbcd.nmcd.hdc = hdc;
     716        tbcd.nmcd.rc = rc;
     717        tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
     718        tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
     719        tbcd.nmcd.lItemlParam = btnPtr->dwData;
     720        ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
     721        infoPtr->dwItemCustDraw = ntfret & 0xffff;
     722        infoPtr->dwItemCDFlag = ntfret & 0xffff0000;
     723        if (infoPtr->dwItemCustDraw & CDRF_SKIPDEFAULT)
     724            return;
     725        /* save the only part of the rect that the user can change */
     726        rcText.right = tbcd.rcText.right + rc.left;
     727        rcText.bottom = tbcd.rcText.bottom + rc.top;
     728    }
    580729
    581730    if (!infoPtr->bBtnTranspnt)
    582         FillRect( hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
    583 
    584     if (hasDropDownArrow)
    585     {
    586         if (dwStyle & TBSTYLE_FLAT)
    587             rc.right = max(rc.left, rc.right - DDARROW_WIDTH);
    588         else
    589             rc.right = max(rc.left, rc.right - DDARROW_WIDTH - 2);
    590         rcArrow.left = rc.right;
    591     }
    592 
    593     /* Center the bitmap horizontally and vertically */
    594     if (dwStyle & TBSTYLE_LIST)
    595         rcBitmap.left += 3;
    596     else
    597         rcBitmap.left+=(infoPtr->nButtonWidth - infoPtr->nBitmapWidth) / 2;
    598 
    599     if(TOOLBAR_HasText(infoPtr, btnPtr))
    600         rcBitmap.top+=2; /* this looks to be the correct value from vmware comparison - cmm */
    601     else
    602         rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2;
    603 
    604     TRACE("iBitmap: %d, start=(%d,%d) w=%d, h=%d\n",
    605           btnPtr->iBitmap, rcBitmap.left, rcBitmap.top,
    606           infoPtr->nBitmapWidth, infoPtr->nBitmapHeight);
     731        FillRect( hdc, &rcFill, GetSysColorBrush(COLOR_BTNFACE));
    607732
    608733    /* separator */
     
    615740        if ((dwStyle & TBSTYLE_FLAT) /* && (btnPtr->iBitmap == 0) */) {
    616741            if (btnPtr->fsStyle & TBSTYLE_DROPDOWN)
    617                 TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr);
     742                TOOLBAR_DrawDDFlatSeparator (&rc, hdc, btnPtr, infoPtr);
    618743            else
    619                 TOOLBAR_DrawFlatSeparator (&rc, hdc);
    620         }
    621         return;
     744                TOOLBAR_DrawFlatSeparator (&rc, hdc, infoPtr);
     745        }
     746        else if (btnPtr->fsStyle != TBSTYLE_SEP) {
     747            FIXME("Draw some kind of separator: fsStyle=%x\n",
     748                  btnPtr->fsStyle);
     749        }
     750        goto FINALNOTIFY;
    622751    }
    623752
    624753    /* disabled */
    625754    if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
    626         if (!(dwStyle & TBSTYLE_FLAT))
     755        if (!(dwStyle & TBSTYLE_FLAT) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
    627756        {
    628757            DrawEdge (hdc, &rc, EDGE_RAISED,
     
    644773            TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
    645774
    646         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    647         return;
     775        TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
     776        goto FINALNOTIFY;
    648777    }
    649778
    650779    /* pressed TBSTYLE_BUTTON */
    651780    if (btnPtr->fsState & TBSTATE_PRESSED) {
    652         if (dwStyle & TBSTYLE_FLAT)
     781        offset = (infoPtr->dwItemCDFlag & TBCDRF_NOOFFSET) ? 0 : 1;
     782        if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
    653783        {
    654             DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
    655             if (hasDropDownArrow)
    656             DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
    657         }
    658         else
    659         {
    660             DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
    661             if (hasDropDownArrow)
    662             DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
     784            if (dwStyle & TBSTYLE_FLAT)
     785            {
     786                DrawEdge (hdc, &rc, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
     787                if (hasDropDownArrow)
     788                    DrawEdge (hdc, &rcArrow, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST);
     789            }
     790            else
     791            {
     792                DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
     793                if (hasDropDownArrow)
     794                    DrawEdge (hdc, &rcArrow, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
     795            }
    663796        }
    664797
     
    667800
    668801        TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
    669                                hdc, rcBitmap.left+1, rcBitmap.top+1,
     802                               hdc, rcBitmap.left+offset, rcBitmap.top+offset,
    670803                               ILD_NORMAL);
    671804
    672         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    673         return;
     805        TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
     806        goto FINALNOTIFY;
    674807    }
    675808
     
    677810    if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
    678811        (btnPtr->fsState & TBSTATE_CHECKED)) {
    679         if (dwStyle & TBSTYLE_FLAT)
    680             DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
    681                         BF_RECT | BF_ADJUST);
    682         else
    683             DrawEdge (hdc, &rc, EDGE_SUNKEN,
    684                         BF_RECT | BF_MIDDLE | BF_ADJUST);
     812        if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
     813        {
     814            if (dwStyle & TBSTYLE_FLAT)
     815                DrawEdge (hdc, &rc, BDR_SUNKENOUTER,
     816                          BF_RECT | BF_ADJUST);
     817            else
     818                DrawEdge (hdc, &rc, EDGE_SUNKEN,
     819                          BF_RECT | BF_MIDDLE | BF_ADJUST);
     820        }
    685821
    686822        TOOLBAR_DrawPattern (hdc, &rc);
     
    690826                               ILD_NORMAL);
    691827
    692         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    693         return;
     828        TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
     829        goto FINALNOTIFY;
    694830    }
    695831
    696832    /* indeterminate */
    697833    if (btnPtr->fsState & TBSTATE_INDETERMINATE) {
    698         DrawEdge (hdc, &rc, EDGE_RAISED,
    699                     BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
     834        if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
     835            DrawEdge (hdc, &rc, EDGE_RAISED,
     836                      BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    700837
    701838        TOOLBAR_DrawPattern (hdc, &rc);
    702839        TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rcBitmap.left, rcBitmap.top);
    703         TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
    704         return;
     840        TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
     841        goto FINALNOTIFY;
    705842    }
    706843
     
    710847        if (btnPtr->bHot)
    711848        {
    712             DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
    713             if (hasDropDownArrow)
    714             DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
     849            if ( infoPtr->dwItemCDFlag & TBCDRF_HILITEHOTTRACK )
     850            {
     851                COLORREF oldclr;
     852
     853                oldclr = SetBkColor(hdc, tbcd.clrHighlightHotTrack);
     854                ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, 0);
     855                if (hasDropDownArrow)
     856                    ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rcArrow, NULL, 0, 0);
     857                SetBkColor(hdc, oldclr);
     858            }
     859            else
     860            {
     861                if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
     862                {
     863                    DrawEdge (hdc, &rc, BDR_RAISEDINNER, BF_RECT);
     864                    if (hasDropDownArrow)
     865                        DrawEdge (hdc, &rcArrow, BDR_RAISEDINNER, BF_RECT);
     866                }
     867            }
    715868        }
    716869#if 1
     
    746899    else
    747900    {
    748         DrawEdge (hdc, &rc, EDGE_RAISED,
    749                 BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
     901        if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
     902            DrawEdge (hdc, &rc, EDGE_RAISED,
     903                      BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    750904
    751905        if (hasDropDownArrow)
    752906        {
    753             DrawEdge (hdc, &rcArrow, EDGE_RAISED,
    754                     BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
     907            if (!(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES))
     908                DrawEdge (hdc, &rcArrow, EDGE_RAISED,
     909                          BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
    755910            TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME);
    756911        }
     
    758913        TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,
    759914                               hdc, rcBitmap.left, rcBitmap.top,
    760                                ILD_NORMAL);
    761     }
    762 
    763     TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle);
     915                               ILD_NORMAL);}
     916   
     917
     918    TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState, dwStyle, &rcText, lpText, &tbcd);
     919
     920 FINALNOTIFY:
     921    if (infoPtr->dwItemCustDraw & CDRF_NOTIFYPOSTPAINT)
     922    {
     923        tbcd.nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
     924        tbcd.nmcd.hdc = hdc;
     925        tbcd.nmcd.rc = rc;
     926        tbcd.nmcd.dwItemSpec = btnPtr->idCommand;
     927        tbcd.nmcd.uItemState = TOOLBAR_TranslateState(btnPtr);
     928        tbcd.nmcd.lItemlParam = btnPtr->dwData;
     929        tbcd.rcText = rcText;
     930        tbcd.nStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
     931        tbcd.nHLStringBkMode = (infoPtr->bBtnTranspnt) ? TRANSPARENT : OPAQUE;
     932        ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
     933    }
     934
    764935}
    765936
     
    772943    INT i, oldBKmode = 0;
    773944    RECT rcTemp;
     945    NMTBCUSTOMDRAW tbcd;
     946    DWORD ntfret;
    774947
    775948    /* if imagelist belongs to the app, it can be changed
     
    779952
    780953    TOOLBAR_DumpToolbar (infoPtr, __LINE__);
     954
     955    /* Send initial notify */
     956    ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
     957    tbcd.nmcd.dwDrawStage = CDDS_PREPAINT;
     958    tbcd.nmcd.hdc = hdc;
     959    tbcd.nmcd.rc = ps->rcPaint;
     960    ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
     961    infoPtr->dwBaseCustDraw = ntfret & 0xffff;
    781962
    782963    if (infoPtr->bBtnTranspnt)
     
    793974    if (infoPtr->bBtnTranspnt && (oldBKmode != TRANSPARENT))
    794975        SetBkMode (hdc, oldBKmode);
     976
     977    if (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTPAINT)
     978    {
     979        ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
     980        tbcd.nmcd.dwDrawStage = CDDS_POSTPAINT;
     981        tbcd.nmcd.hdc = hdc;
     982        tbcd.nmcd.rc = ps->rcPaint;
     983        ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
     984    }
    795985}
    796986
     
    8201010        LPWSTR lpText = TOOLBAR_GetText(infoPtr, btnPtr);
    8211011
    822         /* first get size of all the text */
    823         GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
    824 
    825         /* feed above size into the rectangle for DrawText */
    826         myrect.left = myrect.top = 0;
    827         myrect.right = lpSize->cx;
    828         myrect.bottom = lpSize->cy;
    829 
    830         /* Use DrawText to get true size as drawn (less pesky "&") */
    831         DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
    832                    DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
     1012        if(lpText != NULL) {
     1013            /* first get size of all the text */
     1014            GetTextExtentPoint32W (hdc, lpText, strlenW (lpText), lpSize);
     1015
     1016            /* feed above size into the rectangle for DrawText */
     1017            myrect.left = myrect.top = 0;
     1018            myrect.right = lpSize->cx;
     1019            myrect.bottom = lpSize->cy;
     1020
     1021            /* Use DrawText to get true size as drawn (less pesky "&") */
     1022            DrawTextW (hdc, lpText, -1, &myrect, DT_VCENTER | DT_SINGLELINE |
     1023                   DT_CALCRECT | ((btnPtr->fsStyle & TBSTYLE_NOPREFIX) ?
    8331024                                  DT_NOPREFIX : 0));
    8341025
    835         /* feed back to caller  */
    836         lpSize->cx = myrect.right;
    837         lpSize->cy = myrect.bottom;
     1026            /* feed back to caller  */
     1027            lpSize->cx = myrect.right;
     1028            lpSize->cy = myrect.bottom;
     1029        }
    8381030    }
    8391031
     
    8911083* the toolbar wrapping on its own, it can use the TBSTYLE_WRAPABLE
    8921084* flag, and set the TBSTATE_WRAP flags manually on the appropriate items.
     1085*
     1086* Note: TBSTYLE_WRAPABLE or TBSTYLE_EX_UNDOC1 can be used also to allow
     1087* vertical toolbar lists.
    8931088*/
    8941089
     
    9051100    /*  no layout is necessary. Applications may use this style */
    9061101    /*  to perform their own layout on the toolbar.             */
    907     if( !(dwStyle & TBSTYLE_WRAPABLE) )
    908         return;
     1102    if( !(dwStyle & TBSTYLE_WRAPABLE) &&
     1103        !(infoPtr->dwExStyle & TBSTYLE_EX_UNDOC1) )  return;
    9091104
    9101105    btnPtr = infoPtr->buttons;
     
    9721167            /*  go to the next until it reaches a non separator.      */
    9731168            /*  Wrap the last separator if it is before a button.     */
    974             while( ( (btnPtr[i].fsStyle & TBSTYLE_SEP) ||
    975                         (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
     1169            while( ( ((btnPtr[i].fsStyle & TBSTYLE_SEP) &&
     1170                      !(btnPtr[i].fsStyle & TBSTYLE_DROPDOWN)) ||
     1171                     (btnPtr[i].fsState & TBSTATE_HIDDEN) ) &&
    9761172                        i < infoPtr->nNumButtons )
    9771173            {
     
    10811277    TOOLBAR_CalcStrings (hwnd, &sizeString);
    10821278
     1279    for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
     1280    {
     1281        if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
     1282            usesBitmaps = TRUE;
     1283    }
    10831284    if (dwStyle & TBSTYLE_LIST)
    10841285    {
    1085         for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
    1086         {
    1087             if (infoPtr->buttons[i].iBitmap >= 0)
    1088                 usesBitmaps = TRUE;
    1089         }
    10901286        infoPtr->nButtonHeight = max((usesBitmaps) ? infoPtr->nBitmapHeight :
    1091                                      0, sizeString.cy) + 6;
     1287                                     0, sizeString.cy) + infoPtr->szPadding.cy;
    10921288        infoPtr->nButtonWidth = ((usesBitmaps) ? infoPtr->nBitmapWidth :
    10931289                                 0) + sizeString.cx + 6;
     
    10981294    }
    10991295    else {
    1100         for (i = 0; i < infoPtr->nNumButtons && !usesBitmaps; i++)
    1101         {
    1102             if (TOOLBAR_IsValidBitmapIndex(infoPtr,infoPtr->buttons[i].iBitmap))
    1103                 usesBitmaps = TRUE;
    1104         }
    1105 
    11061296        if (sizeString.cy > 0)
    11071297        {
     
    12521442        btnPtr->nRow = nRows + nSepRows;
    12531443
    1254         TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d\n",
    1255               i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow);
     1444        TRACE("button %d style=%x, bWrap=%d, nRows=%d, nSepRows=%d, btnrow=%d, (%d,%d)-(%d,%d)\n",
     1445              i, btnPtr->fsStyle, bWrap, nRows, nSepRows, btnPtr->nRow,
     1446              x, y, x+cx, y+cy);
    12561447
    12571448        if( bWrap )
     
    12751466            }
    12761467            x = infoPtr->nIndent;
     1468
     1469            /* Increment row number unless this is the last button    */
     1470            /* and it has Wrap set.                                   */
     1471            if (i != infoPtr->nNumButtons-1)
    12771472                nRows++;
    12781473        }
     
    12831478    /* infoPtr->nRows is the number of rows on the toolbar */
    12841479    infoPtr->nRows = nRows + nSepRows + 1;
     1480
     1481#if 0
     1482    /********************************************************************
     1483     * The following while interesting, does not match the values       *
     1484     * created above for the button rectangles, nor the rcBound rect.   *
     1485     * We will comment it out and remove it later.                      *
     1486     *                                                                  *
     1487     * The problem showed up as heights in the pager control that was   *
     1488     * wrong.                                                           *
     1489     ********************************************************************/
    12851490
    12861491    /* nSepRows * (infoPtr->nBitmapHeight + 1) is the space following   */
     
    12901495                        nSepRows * (infoPtr->nBitmapHeight + 1) +
    12911496                        BOTTOM_BORDER;
     1497#endif
     1498
     1499    infoPtr->nHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
     1500
    12921501    TRACE("toolbar height %d, button width %d\n", infoPtr->nHeight, infoPtr->nButtonWidth);
    12931502}
     
    13331542    if (CommandIsIndex) {
    13341543        TRACE("command is really index command=%d\n", idCommand);
     1544        if (idCommand >= infoPtr->nNumButtons) return -1;
    13351545        return idCommand;
    13361546    }
     
    17912001
    17922002                /* set colors and select objects */
    1793                 oldBk = SetBkColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
     2003                oldBk = SetBkColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlight:comctl32_color.clrWindow);
    17942004                if (btnInfo->bVirtual)
    1795                    oldText = SetTextColor (lpdis->hDC, GetSysColor(COLOR_GRAYTEXT));
     2005                   oldText = SetTextColor (lpdis->hDC, comctl32_color.clrGrayText);
    17962006                else
    1797                    oldText = SetTextColor (lpdis->hDC, GetSysColor((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHTTEXT:COLOR_WINDOWTEXT));
     2007                   oldText = SetTextColor (lpdis->hDC, (lpdis->itemState & ODS_FOCUS)?comctl32_color.clrHighlightText:comctl32_color.clrWindowText);
    17982008                hOldPen = SelectObject (lpdis->hDC, GetSysColorPen ((lpdis->itemState & ODS_SELECTED)?COLOR_HIGHLIGHT:COLOR_WINDOW));
    17992009                hOldBrush = SelectObject (lpdis->hDC, GetSysColorBrush ((lpdis->itemState & ODS_FOCUS)?COLOR_HIGHLIGHT:COLOR_WINDOW));
     
    20002210    }
    20012211
     2212    TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
     2213
     2214    if (infoPtr->nNumBitmapInfos == 0)
     2215    {
     2216        infoPtr->bitmaps = COMCTL32_Alloc(sizeof(TBITMAP_INFO));
     2217    }
     2218    else
     2219    {
     2220        TBITMAP_INFO *oldBitmaps = infoPtr->bitmaps;
     2221        infoPtr->bitmaps = COMCTL32_Alloc((infoPtr->nNumBitmapInfos + 1) * sizeof(TBITMAP_INFO));
     2222        memcpy(&infoPtr->bitmaps[0], &oldBitmaps[0], infoPtr->nNumBitmapInfos);
     2223    }
     2224
     2225    infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nButtons = nButtons;
     2226    infoPtr->bitmaps[infoPtr->nNumBitmapInfos].hInst = lpAddBmp->hInst;
     2227    infoPtr->bitmaps[infoPtr->nNumBitmapInfos].nID = lpAddBmp->nID;
     2228
     2229    infoPtr->nNumBitmapInfos++;
     2230    TRACE("Number of bitmap infos: %d\n", infoPtr->nNumBitmapInfos);
     2231
    20022232    if (nIndex != -1)
    20032233    {
     
    28243054
    28253055
    2826 /* << TOOLBAR_GetColorScheme >> */
    2827 
    2828 
    28293056static LRESULT
    28303057TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
     
    29323159
    29333160/* << TOOLBAR_GetObject >> */
    2934 /* << TOOLBAR_GetPadding >> */
     3161
     3162
     3163static LRESULT
     3164TOOLBAR_GetPadding (HWND hwnd)
     3165{
     3166    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     3167    DWORD oldPad;
     3168
     3169    oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
     3170    return (LRESULT) oldPad;
     3171}
    29353172
    29363173
     
    32153452    TOOLBAR_DumpButton(infoPtr, (TBUTTON_INFO *)lpTbb, nIndex, FALSE);
    32163453
    3217     if (nIndex < 0)
    3218         return FALSE;
    3219 
    3220     TRACE("inserting button index=%d\n", nIndex);
    3221     if (nIndex > infoPtr->nNumButtons) {
     3454    if (nIndex == -1) {
     3455       /* EPP: this seems to be an undocumented call (from my IE4)
     3456        * I assume in that case that:
     3457        * - lpTbb->iString is a string pointer (not a string index in strings[] table
     3458        * - index of insertion is at the end of existing buttons
     3459        * I only see this happen with nIndex == -1, but it could have a special
     3460        * meaning (like -nIndex (or ~nIndex) to get the real position of insertion).
     3461        */
    32223462        nIndex = infoPtr->nNumButtons;
    3223         TRACE("adjust index=%d\n", nIndex);
    3224     }
    3225 
    3226     oldButtons = infoPtr->buttons;
    3227     infoPtr->nNumButtons++;
    3228     infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
    3229     /* pre insert copy */
    3230     if (nIndex > 0) {
    3231         memcpy (&infoPtr->buttons[0], &oldButtons[0],
    3232                 nIndex * sizeof(TBUTTON_INFO));
    3233     }
    3234 
     3463
     3464    } else if (nIndex < 0)
     3465       return FALSE;
    32353466
    32363467    /* If the string passed is not an index, assume address of string
     
    32483479        lpTbb->iString = TOOLBAR_AddStringW(hwnd, 0, (LPARAM)ptr);
    32493480        COMCTL32_Free(ptr);
     3481    }
     3482
     3483    TRACE("inserting button index=%d\n", nIndex);
     3484    if (nIndex > infoPtr->nNumButtons) {
     3485        nIndex = infoPtr->nNumButtons;
     3486        TRACE("adjust index=%d\n", nIndex);
     3487    }
     3488
     3489    oldButtons = infoPtr->buttons;
     3490    infoPtr->nNumButtons++;
     3491    infoPtr->buttons = COMCTL32_Alloc (sizeof (TBUTTON_INFO) * infoPtr->nNumButtons);
     3492    /* pre insert copy */
     3493    if (nIndex > 0) {
     3494        memcpy (&infoPtr->buttons[0], &oldButtons[0],
     3495                nIndex * sizeof(TBUTTON_INFO));
    32503496    }
    32513497
     
    32853531    COMCTL32_Free (oldButtons);
    32863532
     3533    TOOLBAR_CalcToolbar (hwnd);
     3534
    32873535    InvalidateRect (hwnd, NULL, TRUE);
    32883536
     
    34073655
    34083656
    3409 /* << TOOLBAR_ReplaceBitmap >> */
    3410 
     3657static LRESULT
     3658TOOLBAR_ReplaceBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
     3659{
     3660    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     3661    LPTBREPLACEBITMAP lpReplace = (LPTBREPLACEBITMAP) lParam;
     3662    HBITMAP hBitmap;
     3663    int i = 0, nOldButtons = 0, pos = 0;
     3664
     3665    TRACE("hInstOld %x nIDOld %x hInstNew %x nIDNew %x nButtons %x\n",
     3666          lpReplace->hInstOld, lpReplace->nIDOld, lpReplace->hInstNew, lpReplace->nIDNew,
     3667          lpReplace->nButtons);
     3668
     3669    if (lpReplace->hInstOld == -1)
     3670    {
     3671        FIXME("changing standard bitmaps not implemented\n");
     3672        return FALSE;
     3673    }
     3674    else if (lpReplace->hInstOld != 0)
     3675    {
     3676        FIXME("resources not in the current module not implemented\n");
     3677        return FALSE;
     3678    }
     3679    else
     3680    {
     3681        hBitmap = (HBITMAP) lpReplace->nIDNew;
     3682    }
     3683
     3684    TRACE("To be replaced hInstOld %x nIDOld %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
     3685    for (i = 0; i < infoPtr->nNumBitmapInfos; i++) {
     3686        TBITMAP_INFO *tbi = &infoPtr->bitmaps[i];
     3687        TRACE("tbimapinfo %d hInstOld %x nIDOld %x\n", i, tbi->hInst, tbi->nID);
     3688        if (tbi->hInst == lpReplace->hInstOld && tbi->nID == lpReplace->nIDOld)
     3689        {
     3690            TRACE("Found: nButtons %d hInst %x nID %x\n", tbi->nButtons, tbi->hInst, tbi->nID);
     3691            nOldButtons = tbi->nButtons;
     3692            tbi->nButtons = lpReplace->nButtons;
     3693            tbi->hInst = lpReplace->hInstNew;
     3694            tbi->nID = lpReplace->nIDNew;
     3695            TRACE("tbimapinfo changed %d hInstOld %x nIDOld %x\n", i, tbi->hInst, tbi->nID);
     3696            break;
     3697        }
     3698        pos += tbi->nButtons;
     3699    }
     3700
     3701    if (nOldButtons == 0)
     3702    {
     3703        WARN("No hinst/bitmap found! hInst %x nID %x\n", lpReplace->hInstOld, lpReplace->nIDOld);
     3704        return FALSE;
     3705    }
     3706
     3707    infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldButtons + lpReplace->nButtons;
     3708
     3709    /* ImageList_Replace(infoPtr->himlDef, pos, hBitmap, NULL); */
     3710
     3711
     3712    for (i = pos + nOldButtons - 1; i >= pos; i--) {
     3713        ImageList_Remove(infoPtr->himlDef, i);
     3714    }
     3715
     3716    ImageList_AddMasked(infoPtr->himlDef, hBitmap, CLR_DEFAULT);
     3717
     3718    InvalidateRect(hwnd, NULL, FALSE);
     3719
     3720    return TRUE;
     3721}
    34113722
    34123723static LRESULT
     
    35993910{
    36003911    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    3601 
    3602     if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0))
     3912    INT cx = LOWORD(lParam), cy = HIWORD(lParam);
     3913
     3914    if ((cx < 0) || (cy < 0))
    36033915    {
    3604         ERR("invalid parameter\n");
     3916        ERR("invalid parameter 0x%08lx\n", (DWORD)lParam);
    36053917        return FALSE;
    36063918    }
     
    36123924     * Further testing shows that we must actually perform the change too.
    36133925     */
    3614     infoPtr->nButtonWidth = (INT)LOWORD(lParam);
    3615     infoPtr->nButtonHeight = (INT)HIWORD(lParam);
     3926    /*
     3927     * The documentation also does not mention that if 0 is supplied for
     3928     * either size, the system changes it to the default of 24 wide and
     3929     * 22 high. Demonstarted in ControlSpy Toolbar. GLA 3/02
     3930     */
     3931    infoPtr->nButtonWidth = (cx) ? cx : 24;
     3932    infoPtr->nButtonHeight = (cy) ? cy : 22;
    36163933    return TRUE;
    36173934}
     
    36813998
    36823999
    3683 /* << TOOLBAR_SetColorScheme >> */
    3684 
    3685 
    36864000static LRESULT
    36874001TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
     
    37184032}
    37194033
    3720 
    37214034static LRESULT
    37224035TOOLBAR_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
     
    37274040    dwTemp = infoPtr->dwExStyle;
    37284041    infoPtr->dwExStyle = (DWORD)lParam;
     4042
     4043    if (infoPtr->dwExStyle & (TBSTYLE_EX_MIXEDBUTTONS |
     4044                              TBSTYLE_EX_HIDECLIPPEDBUTTONS)) {
     4045        FIXME("Extended style not implemented %s %s\n",
     4046              (infoPtr->dwExStyle & TBSTYLE_EX_MIXEDBUTTONS) ?
     4047              "TBSTYLE_EX_MIXEDBUTTONS" : "",
     4048              (infoPtr->dwExStyle & TBSTYLE_EX_HIDECLIPPEDBUTTONS) ?
     4049              "TBSTYLE_EX_HIDECLIPPEDBUTTONS" : "");
     4050    }
     4051
     4052    if (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL)
     4053        FIXME("Unknown Toolbar Extended Style 0x%08lx. Please report.\n",
     4054              (infoPtr->dwExStyle & ~TBSTYLE_EX_ALL));
    37294055
    37304056    return (LRESULT)dwTemp;
     
    38694195
    38704196
    3871 /* << TOOLBAR_SetPadding >> */
     4197static LRESULT
     4198TOOLBAR_SetPadding (HWND hwnd, WPARAM wParam, LPARAM lParam)
     4199{
     4200    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     4201    DWORD  oldPad;
     4202
     4203    oldPad = MAKELONG(infoPtr->szPadding.cx, infoPtr->szPadding.cy);
     4204    infoPtr->szPadding.cx = LOWORD((DWORD)lParam);
     4205    infoPtr->szPadding.cy = HIWORD((DWORD)lParam);
     4206    FIXME("stub - nothing done with values, cx=%ld, cy=%ld\n",
     4207          infoPtr->szPadding.cx, infoPtr->szPadding.cy);
     4208    return (LRESULT) oldPad;
     4209}
    38724210
    38734211
     
    40154353
    40164354static LRESULT
     4355TOOLBAR_GetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
     4356{
     4357    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     4358
     4359    lParam->clrBtnHighlight = (infoPtr->clrBtnHighlight == CLR_DEFAULT) ?
     4360                               comctl32_color.clrBtnHighlight :
     4361                               infoPtr->clrBtnHighlight;
     4362    lParam->clrBtnShadow = (infoPtr->clrBtnShadow == CLR_DEFAULT) ?
     4363                           comctl32_color.clrBtnShadow : infoPtr->clrBtnShadow;
     4364    return 1;
     4365}
     4366
     4367
     4368static LRESULT
     4369TOOLBAR_SetColorScheme (HWND hwnd, LPCOLORSCHEME lParam)
     4370{
     4371    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     4372
     4373    TRACE("new colors Hl=%lx Shd=%lx, old colors Hl=%lx Shd=%lx\n",
     4374          lParam->clrBtnHighlight, lParam->clrBtnShadow,
     4375          infoPtr->clrBtnHighlight, infoPtr->clrBtnShadow);
     4376
     4377    infoPtr->clrBtnHighlight = lParam->clrBtnHighlight;
     4378    infoPtr->clrBtnShadow = lParam->clrBtnShadow;
     4379    InvalidateRect(hwnd, 0, 0);
     4380    return 0;
     4381}
     4382
     4383
     4384static LRESULT
    40174385TOOLBAR_SetVersion (HWND hwnd, INT iVersion)
    40184386{
     
    40234391
    40244392    return iOldVersion;
     4393}
     4394
     4395
     4396/*********************************************************************/
     4397/*                                                                   */
     4398/* This is undocumented and appears to be a "Super" TB_SETHOTITEM    */
     4399/* without the restriction of TBSTYLE_FLAT. This implementation is   */
     4400/* based on relay traces of the native control and IE 5.5            */
     4401/*                                                                   */
     4402/*********************************************************************/
     4403static LRESULT
     4404TOOLBAR_Unkwn45E (HWND hwnd, WPARAM wParam, LPARAM lParam)
     4405{
     4406    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
     4407    INT nOldHotItem = infoPtr->nHotItem;
     4408    TBUTTON_INFO *btnPtr;
     4409    INT no_hi = 0;
     4410    NMTBHOTITEM nmhotitem;
     4411
     4412    if ((INT) wParam < 0 || (INT)wParam > infoPtr->nNumButtons)
     4413        wParam = -2;
     4414
     4415    infoPtr->nHotItem = (INT)wParam;
     4416    if (nOldHotItem != infoPtr->nHotItem) {
     4417        nmhotitem.dwFlags = (DWORD)lParam;
     4418        if ( !(nmhotitem.dwFlags & HICF_ENTERING) )
     4419            nmhotitem.idOld = (nOldHotItem >= 0) ?
     4420                infoPtr->buttons[nOldHotItem].idCommand : 0;
     4421        if ( !(nmhotitem.dwFlags & HICF_LEAVING) )
     4422            nmhotitem.idNew = (infoPtr->nHotItem >= 0) ?
     4423                infoPtr->buttons[infoPtr->nHotItem].idCommand : 0;
     4424        no_hi = TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
     4425    }
     4426    if ((INT)wParam >=0) {
     4427        btnPtr = &infoPtr->buttons[(INT)wParam];
     4428        btnPtr->bHot = (no_hi) ? FALSE : TRUE;
     4429        InvalidateRect (hwnd, &btnPtr->rect,
     4430                        TOOLBAR_HasText(infoPtr, btnPtr));
     4431    }
     4432    if (nOldHotItem>=0) {
     4433        btnPtr = &infoPtr->buttons[nOldHotItem];
     4434        btnPtr->bHot = FALSE;
     4435        InvalidateRect (hwnd, &btnPtr->rect,
     4436                        TOOLBAR_HasText(infoPtr, btnPtr));
     4437    }
     4438    GetFocus();
     4439    TRACE("old item=%d, new item=%d, flags=%08lx, notify=%d\n",
     4440          nOldHotItem, infoPtr->nHotItem, (DWORD)lParam, no_hi);
     4441
     4442    if (nOldHotItem < 0)
     4443        return -1;
     4444
     4445    return (LRESULT)nOldHotItem;
     4446}
     4447
     4448
     4449static LRESULT
     4450TOOLBAR_Unkwn463 (HWND hwnd, WPARAM wParam, LPARAM lParam)
     4451{
     4452    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
     4453    LPSIZE lpsize = (LPSIZE)lParam;
     4454
     4455    if (lpsize == NULL)
     4456        return FALSE;
     4457
     4458    /*
     4459     * Testing shows the following:
     4460     *   wParam    = 0 adjust cx value
     4461     *             = 1 set cy value to max size.
     4462     *   lParam    pointer to SIZE structure
     4463     *
     4464     */
     4465    TRACE("[0463] wParam %d, lParam 0x%08lx -> 0x%08lx 0x%08lx\n",
     4466          wParam, lParam, lpsize->cx, lpsize->cy);
     4467
     4468    switch(wParam) {
     4469    case 0:
     4470        if (lpsize->cx == -1) {
     4471            /* **** this is wrong, native measures each button and sets it */
     4472            lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
     4473        }
     4474        else if(HIWORD(lpsize->cx)) {
     4475            RECT rc;
     4476            HWND hwndParent = GetParent(hwnd);
     4477
     4478            InvalidateRect(hwnd, 0, 1);
     4479            GetWindowRect(hwnd, &rc);
     4480            MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2);
     4481            TRACE("mapped to (%d,%d)-(%d,%d)\n",
     4482                rc.left, rc.top, rc.right, rc.bottom);
     4483            lpsize->cx = max(rc.right-rc.left,
     4484                             infoPtr->rcBound.right - infoPtr->rcBound.left);
     4485        }
     4486        else {
     4487            lpsize->cx = infoPtr->rcBound.right - infoPtr->rcBound.left;
     4488        }
     4489        break;
     4490    case 1:
     4491        lpsize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
     4492        /* lpsize->cy = infoPtr->nHeight; */
     4493        break;
     4494    default:
     4495        ERR("Unknown wParam %d for Toolbar message [0463]. Please report\n",
     4496            wParam);
     4497        return 0;
     4498    }
     4499    TRACE("[0463] set to -> 0x%08lx 0x%08lx\n",
     4500          lpsize->cx, lpsize->cy);
     4501    return 1;
    40254502}
    40264503
     
    40584535    infoPtr->bAnchor = FALSE; /* no anchor highlighting */
    40594536    infoPtr->iVersion = 0;
    4060     infoPtr->bNtfUnicode = FALSE;
    40614537    infoPtr->hwndSelf = hwnd;
    40624538    infoPtr->bDoRedraw = TRUE;
     4539    infoPtr->clrBtnHighlight = CLR_DEFAULT;
     4540    infoPtr->clrBtnShadow = CLR_DEFAULT;
     4541    infoPtr->szPadding.cx = 7;
     4542    infoPtr->szPadding.cy = 6;
     4543    TOOLBAR_NotifyFormat(infoPtr, (WPARAM)hwnd, (LPARAM)NF_REQUERY);
    40634544
    40644545    SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
     
    41374618    DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
    41384619    NMTBCUSTOMDRAW tbcd;
    4139     INT ret = FALSE, ntfret;
     4620    INT ret = FALSE;
     4621    DWORD ntfret;
    41404622
    41414623    if (dwStyle & TBSTYLE_CUSTOMERASE) {
     
    41444626        tbcd.nmcd.hdc = (HDC)wParam;
    41454627        ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
     4628        infoPtr->dwBaseCustDraw = ntfret & 0xffff;
     4629
    41464630        /* FIXME: in general the return flags *can* be or'ed together */
    4147         switch (ntfret)
     4631        switch (infoPtr->dwBaseCustDraw)
    41484632            {
    41494633            case CDRF_DODEFAULT:
     
    41524636                return TRUE;
    41534637            default:
    4154                 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
     4638                FIXME("[%04x] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
    41554639                      hwnd, ntfret);
    41564640            }
     
    41764660        ret = DefWindowProcA (hwnd, WM_ERASEBKGND, wParam, lParam);
    41774661
    4178     if (dwStyle & TBSTYLE_CUSTOMERASE) {
     4662    if ((dwStyle & TBSTYLE_CUSTOMERASE) &&
     4663        (infoPtr->dwBaseCustDraw & CDRF_NOTIFYPOSTERASE)) {
    41794664        ZeroMemory (&tbcd, sizeof(NMTBCUSTOMDRAW));
    41804665        tbcd.nmcd.dwDrawStage = CDDS_POSTERASE;
    41814666        tbcd.nmcd.hdc = (HDC)wParam;
    41824667        ntfret = TOOLBAR_SendNotify ((NMHDR *)&tbcd, infoPtr, NM_CUSTOMDRAW);
    4183         switch (ntfret)
     4668        infoPtr->dwBaseCustDraw = ntfret & 0xffff;
     4669        switch (infoPtr->dwBaseCustDraw)
    41844670            {
    41854671            case CDRF_DODEFAULT:
     
    41884674                return TRUE;
    41894675            default:
    4190                 FIXME("[%04x] response %d not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
     4676                FIXME("[%04x] response %ld not handled to NM_CUSTOMDRAW (CDDS_PREERASE)\n",
    41914677                      hwnd, ntfret);
    41924678            }
     
    43454831        infoPtr->buttons[infoPtr->nHotItem].bHot = TRUE;
    43464832
    4347     if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0)) {
    43484833        btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
    43494834        btnPtr->fsState &= ~TBSTATE_PRESSED;
    43504835
    4351         if (nHit == infoPtr->nButtonDown) {
    4352             if (btnPtr->fsStyle & TBSTYLE_CHECK) {
     4836        if (btnPtr->fsStyle & TBSTYLE_CHECK) {
    43534837                if (btnPtr->fsStyle & TBSTYLE_GROUP) {
    43544838                    nOldIndex = TOOLBAR_GetCheckedGroupButtonIndex (infoPtr,
    4355                         infoPtr->nButtonDown);
    4356                     if (nOldIndex == infoPtr->nButtonDown)
     4839                        nHit);
     4840                    if (nOldIndex == nHit)
    43574841                        bSendMessage = FALSE;
    4358                     if ((nOldIndex != infoPtr->nButtonDown) &&
     4842                    if ((nOldIndex != nHit) &&
    43594843                        (nOldIndex != -1))
    43604844                        infoPtr->buttons[nOldIndex].fsState &= ~TBSTATE_CHECKED;
     
    43674851                        btnPtr->fsState |= TBSTATE_CHECKED;
    43684852                }
    4369             }
    4370         }
    4371         else
    4372             bSendMessage = FALSE;
     4853        }
    43734854
    43744855        if (nOldIndex != -1)
     
    43834864         * and obliterates nButtonDown and nOldHit (see TOOLBAR_CaptureChanged)
    43844865         */
    4385         ReleaseCapture ();
     4866        if ((infoPtr->bCaptured) && (infoPtr->nButtonDown >= 0))
     4867            ReleaseCapture ();
    43864868
    43874869        /* Issue NM_RELEASEDCAPTURE to parent to let him know it is released */
     
    44044886                        TBN_ENDDRAG);
    44054887
    4406         if (bSendMessage)
    4407             SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
    4408                           MAKEWPARAM(btnPtr->idCommand, 0), (LPARAM)hwnd);
     4888        SendMessageA (infoPtr->hwndNotify, WM_COMMAND,
     4889          MAKEWPARAM(infoPtr->buttons[nHit].idCommand, 0), (LPARAM)hwnd);
    44094890
    44104891        /* !!! Undocumented - toolbar at 4.71 level and above sends
     
    44164897        TOOLBAR_SendNotify ((NMHDR *) &nmmouse, infoPtr,
    44174898                        NM_CLICK);
    4418     }
    4419 
    44204899    return 0;
    44214900}
     
    44884967TOOLBAR_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
    44894968{
    4490     TBUTTON_INFO *btnPtr, *oldBtnPtr;
     4969    TBUTTON_INFO *btnPtr = NULL, *oldBtnPtr = NULL;
    44914970    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
    44924971    POINT pt;
    44934972    INT   nHit;
    44944973    TRACKMOUSEEVENT trackinfo;
     4974    NMTBHOTITEM nmhotitem;
    44954975
    44964976    /* fill in the TRACKMOUSEEVENT struct */
     
    45305010            oldBtnPtr = &infoPtr->buttons[infoPtr->nOldHit];
    45315011            oldBtnPtr->bHot = FALSE;
    4532                    
    4533             InvalidateRect (hwnd, &oldBtnPtr->rect,
    4534                 TOOLBAR_HasText(infoPtr, oldBtnPtr));
    4535         }
     5012        }
    45365013
    45375014        /* It's not a separator or in nowhere. It's a hot button. */
     
    45465023            {
    45475024                btnPtr->bHot = TRUE;
    4548                 InvalidateRect(hwnd, &btnPtr->rect,
    4549                     TOOLBAR_HasText(infoPtr, btnPtr));
    45505025            }
    4551 
    4552         }
    4553 
    4554     if (infoPtr->bCaptured) {
     5026        }
     5027
     5028        nmhotitem.dwFlags = HICF_MOUSE;
     5029        if (oldBtnPtr)
     5030            nmhotitem.idOld = oldBtnPtr->idCommand;
     5031        else
     5032            nmhotitem.dwFlags |= HICF_ENTERING;
     5033        if (btnPtr)
     5034            nmhotitem.idNew = btnPtr->idCommand;
     5035        else
     5036            nmhotitem.dwFlags |= HICF_LEAVING;
     5037        TOOLBAR_SendNotify((NMHDR*)&nmhotitem, infoPtr, TBN_HOTITEMCHANGE);
     5038
     5039        /* now invalidate the old and new buttons so they will be painted */
     5040        if (oldBtnPtr)
     5041            InvalidateRect (hwnd, &oldBtnPtr->rect,
     5042                            TOOLBAR_HasText(infoPtr, oldBtnPtr));
     5043        if (btnPtr && (btnPtr->fsState & TBSTATE_ENABLED))
     5044            InvalidateRect(hwnd, &btnPtr->rect,
     5045                           TOOLBAR_HasText(infoPtr, btnPtr));
     5046
     5047        if (infoPtr->bCaptured) {
    45555048            btnPtr = &infoPtr->buttons[infoPtr->nButtonDown];
    45565049            if (infoPtr->nOldHit == infoPtr->nButtonDown) {
     
    47055198
    47065199        if (lppgc->dwFlag == PGF_CALCWIDTH) {
    4707             lppgc->iWidth = infoPtr->nWidth;
     5200            lppgc->iWidth = infoPtr->rcBound.right - infoPtr->rcBound.left;
    47085201            TRACE("processed PGN_CALCSIZE, returning horz size = %d\n",
    4709                   infoPtr->nWidth);
     5202                  lppgc->iWidth);
    47105203        }
    47115204        else {
    4712             lppgc->iHeight = infoPtr->nHeight;
     5205            lppgc->iHeight = infoPtr->rcBound.bottom - infoPtr->rcBound.top;
    47135206            TRACE("processed PGN_CALCSIZE, returning vert size = %d\n",
    4714                   infoPtr->nHeight);
     5207                  lppgc->iHeight);
    47155208        }
    47165209        return 0;
     
    47215214
    47225215    if ((infoPtr->hwndToolTip) && (lpnmh->hwndFrom == infoPtr->hwndToolTip)) {
    4723         SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,   wParam, lParam);
     5216        if (infoPtr->bNtfUnicode)
     5217            return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
     5218                                 wParam, lParam);
     5219        else
     5220            return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
     5221                                 wParam, lParam);
    47245222
    47255223#if 0
     
    47405238
    47415239    return 0;
     5240}
     5241
     5242
     5243static LRESULT
     5244TOOLBAR_NotifyFormatFake(HWND hwnd, WPARAM wParam, LPARAM lParam)
     5245{
     5246    /* remove this routine when Toolbar is improved to pass infoPtr
     5247     * around instead of hwnd.
     5248     */
     5249    TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
     5250    return TOOLBAR_NotifyFormat(infoPtr, wParam, lParam);
     5251}
     5252
     5253
     5254static LRESULT
     5255TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
     5256{
     5257    INT i;
     5258
     5259    if (lParam == NF_REQUERY) {
     5260        i = SendMessageA(GetParent(infoPtr->hwndSelf),
     5261                         WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
     5262        if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
     5263            ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
     5264                i);
     5265            i = NFR_ANSI;
     5266        }
     5267        infoPtr->bNtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
     5268        return (LRESULT)i;
     5269    }
     5270    return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
    47425271}
    47435272
     
    49085437
    49095438
     5439static LRESULT
     5440TOOLBAR_SysColorChange (HWND hwnd)
     5441{
     5442    COMCTL32_RefreshSysColors();
     5443
     5444    return 0;
     5445}
     5446
     5447
    49105448
    49115449static LRESULT WINAPI
     
    49895527            return TOOLBAR_GetButtonTextW (hwnd, wParam, lParam);
    49905528
    4991 /*      case TB_GETCOLORSCHEME:                 */ /* 4.71 */
    4992 
    49935529        case TB_GETDISABLEDIMAGELIST:
    49945530            return TOOLBAR_GetDisabledImageList (hwnd, wParam, lParam);
     
    50165552
    50175553/*      case TB_GETOBJECT:                      */ /* 4.71 */
    5018 /*      case TB_GETPADDING:                     */ /* 4.71 */
     5554
     5555        case TB_GETPADDING:
     5556            return TOOLBAR_GetPadding (hwnd);
    50195557
    50205558        case TB_GETRECT:
     
    50385576        case TB_GETUNICODEFORMAT:
    50395577            return TOOLBAR_GetUnicodeFormat (hwnd, wParam, lParam);
    5040 
    5041         case CCM_GETVERSION:
    5042             return TOOLBAR_GetVersion (hwnd);
    50435578
    50445579        case TB_HIDEBUTTON:
     
    50895624            return TOOLBAR_PressButton (hwnd, wParam, lParam);
    50905625
    5091 /*      case TB_REPLACEBITMAP: */
     5626        case TB_REPLACEBITMAP:
     5627            return TOOLBAR_ReplaceBitmap (hwnd, wParam, lParam);
    50925628
    50935629        case TB_SAVERESTOREA:
     
    51185654            return TOOLBAR_SetCmdId (hwnd, wParam, lParam);
    51195655
    5120 /*      case TB_SETCOLORSCHEME:                 */ /* 4.71 */
    5121 
    51225656        case TB_SETDISABLEDIMAGELIST:
    51235657            return TOOLBAR_SetDisabledImageList (hwnd, wParam, lParam);
     
    51495683            return TOOLBAR_SetMaxTextRows (hwnd, wParam, lParam);
    51505684
    5151 /*      case TB_SETPADDING:                     */ /* 4.71 */
     5685        case TB_SETPADDING:
     5686            return TOOLBAR_SetPadding (hwnd, wParam, lParam);
    51525687
    51535688        case TB_SETPARENT:
     
    51695704            return TOOLBAR_SetUnicodeFormat (hwnd, wParam, lParam);
    51705705
     5706        case TB_UNKWN45E:
     5707            return TOOLBAR_Unkwn45E (hwnd, wParam, lParam);
     5708
     5709        case TB_UNKWN463:
     5710            return TOOLBAR_Unkwn463 (hwnd, wParam, lParam);
     5711
     5712
     5713/* Common Control Messages */
     5714
     5715/*      case TB_GETCOLORSCHEME:                 */ /* identical to CCM_ */
     5716        case CCM_GETCOLORSCHEME:
     5717            return TOOLBAR_GetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
     5718
     5719/*      case TB_SETCOLORSCHEME:                 */ /* identical to CCM_ */
     5720        case CCM_SETCOLORSCHEME:
     5721            return TOOLBAR_SetColorScheme (hwnd, (LPCOLORSCHEME)lParam);
     5722
     5723        case CCM_GETVERSION:
     5724            return TOOLBAR_GetVersion (hwnd);
     5725
    51715726        case CCM_SETVERSION:
    51725727            return TOOLBAR_SetVersion (hwnd, (INT)wParam);
     
    52235778            return TOOLBAR_Notify (hwnd, wParam, lParam);
    52245779
    5225 /*      case WM_NOTIFYFORMAT: */
     5780        case WM_NOTIFYFORMAT:
     5781            TOOLBAR_NotifyFormatFake (hwnd, wParam, lParam);
    52265782
    52275783        case WM_PAINT:
     
    52375793            return TOOLBAR_StyleChanged (hwnd, (INT)wParam, (LPSTYLESTRUCT)lParam);
    52385794
    5239 /*      case WM_SYSCOLORCHANGE: */
     5795        case WM_SYSCOLORCHANGE:
     5796            return TOOLBAR_SysColorChange (hwnd);
    52405797
    52415798/*      case WM_WININICHANGE: */
     
    52545811            }
    52555812
     5813        /* We see this in Outlook Express 5.x and just does DefWindowProc */
     5814        case PGM_FORWARDMOUSE:
     5815            return DefWindowProcA (hwnd, uMsg, wParam, lParam);
     5816
    52565817        default:
    52575818            if (uMsg >= WM_USER)
  • trunk/src/comctl32/tooltips.cpp

    r7616 r8382  
    2727#include "ccbase.h"
    2828#include "comctl32.h"
     29#ifdef __WIN32OS2__
     30#include <dbglog.h>
     31#endif
    2932
    3033#define ID_TIMERSHOW   1    /* show delay timer */
Note: See TracChangeset for help on using the changeset viewer.