1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart and Markus Holzem 
   9 // Licence:     wxWindows license 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  21     #pragma implementation "listctrl.h" 
  22     #pragma implementation "listctrlbase.h" 
  25 // For compilers that support precompilation, includes "wx.h". 
  26 #include "wx/wxprec.h" 
  38 #include "wx/listctrl.h" 
  41 #include "wx/msw/private.h" 
  43 #ifdef __GNUWIN32_OLD__ 
  44     #include "wx/msw/gnuwin32/extra.h" 
  51                 (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON) 
  54 // ---------------------------------------------------------------------------- 
  56 // ---------------------------------------------------------------------------- 
  58 static void wxConvertToMSWListItem(const wxListCtrl 
*ctrl
, wxListItem
& info
, LV_ITEM
& tvItem
); 
  59 static void wxConvertFromMSWListItem(const wxListCtrl 
*ctrl
, wxListItem
& info
, LV_ITEM
& tvItem
, HWND getFullInfo 
= 0); 
  61 // ---------------------------------------------------------------------------- 
  63 // ---------------------------------------------------------------------------- 
  65 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
) 
  66 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
) 
  68 // ============================================================================ 
  70 // ============================================================================ 
  72 // ---------------------------------------------------------------------------- 
  74 // ---------------------------------------------------------------------------- 
  76 void wxListEvent::CopyObject(wxObject
& object_dest
) const 
  78     wxListEvent 
*obj 
= (wxListEvent 
*)&object_dest
; 
  80     wxNotifyEvent::CopyObject(object_dest
); 
  83     obj
->m_itemIndex 
= m_itemIndex
; 
  84     obj
->m_oldItemIndex 
= m_oldItemIndex
; 
  86     obj
->m_cancelled 
= m_cancelled
; 
  87     obj
->m_pointDrag 
= m_pointDrag
; 
  88     obj
->m_item
.m_mask 
= m_item
.m_mask
; 
  89     obj
->m_item
.m_itemId 
= m_item
.m_itemId
; 
  90     obj
->m_item
.m_col 
= m_item
.m_col
; 
  91     obj
->m_item
.m_state 
= m_item
.m_state
; 
  92     obj
->m_item
.m_stateMask 
= m_item
.m_stateMask
; 
  93     obj
->m_item
.m_text 
= m_item
.m_text
; 
  94     obj
->m_item
.m_image 
= m_item
.m_image
; 
  95     obj
->m_item
.m_data 
= m_item
.m_data
; 
  96     obj
->m_item
.m_format 
= m_item
.m_format
; 
  97     obj
->m_item
.m_width 
= m_item
.m_width
; 
  99     if ( m_item
.HasAttributes() ) 
 101         obj
->m_item
.SetTextColour(m_item
.GetTextColour()); 
 102         obj
->m_item
.SetBackgroundColour(m_item
.GetBackgroundColour()); 
 103         obj
->m_item
.SetFont(m_item
.GetFont()); 
 107 // ---------------------------------------------------------------------------- 
 108 // wxListCtrl construction 
 109 // ---------------------------------------------------------------------------- 
 111 void wxListCtrl::Init() 
 113     m_imageListNormal 
= NULL
; 
 114     m_imageListSmall 
= NULL
; 
 115     m_imageListState 
= NULL
; 
 119     m_hasAnyAttr 
= FALSE
; 
 122 bool wxListCtrl::Create(wxWindow 
*parent
, 
 127                         const wxValidator
& validator
, 
 128                         const wxString
& name
) 
 131     SetValidator(validator
); 
 132 #endif // wxUSE_VALIDATORS 
 141     m_windowStyle 
= style
; 
 154     m_windowId 
= (id 
== -1) ? NewControlId() : id
; 
 156     DWORD wstyle 
= WS_VISIBLE 
| WS_CHILD 
| WS_TABSTOP 
| 
 157                    LVS_SHAREIMAGELISTS 
| LVS_SHOWSELALWAYS
; 
 158     if ( wxStyleHasBorder(m_windowStyle
) ) 
 160     m_baseStyle 
= wstyle
; 
 162     if ( !DoCreateControl(x
, y
, width
, height
) ) 
 166         parent
->AddChild(this); 
 171 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
) 
 173     DWORD wstyle 
= m_baseStyle
; 
 176     WXDWORD exStyle 
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
); 
 178     // Even with extended styles, need to combine with WS_BORDER 
 179     // for them to look right. 
 183     long oldStyle 
= 0; // Dummy 
 184     wstyle 
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
); 
 186     // Create the ListView control. 
 187     m_hWnd 
= (WXHWND
)CreateWindowEx(exStyle
, 
 192                                     GetWinHwnd(GetParent()), 
 199         wxLogError(wxT("Can't create list control window.")); 
 204     // for comctl32.dll v 4.70+ we want to have this attribute because it's 
 205     // prettier (and also because wxGTK does it like this) 
 206 #ifdef ListView_SetExtendedListViewStyle 
 207     if ( wstyle 
& LVS_REPORT 
) 
 209         ListView_SetExtendedListViewStyle(GetHwnd(), 
 210                                           LVS_EX_FULLROWSELECT
); 
 212 #endif // ListView_SetExtendedListViewStyle 
 214     SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
)); 
 215     SetForegroundColour(GetParent()->GetForegroundColour()); 
 222 void wxListCtrl::UpdateStyle() 
 226         // The new window view style 
 228         DWORD dwStyleNew 
= ConvertToMSWStyle(dummy
, m_windowStyle
); 
 229         dwStyleNew 
|= m_baseStyle
; 
 231         // Get the current window style. 
 232         DWORD dwStyleOld 
= ::GetWindowLong(GetHwnd(), GWL_STYLE
); 
 234         // Only set the window style if the view bits have changed. 
 235         if ( dwStyleOld 
!= dwStyleNew 
) 
 237             ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
); 
 242 void wxListCtrl::FreeAllAttrs(bool dontRecreate
) 
 246         for ( wxNode 
*node 
= m_attrs
.Next(); node
; node 
= m_attrs
.Next() ) 
 248             delete (wxListItemAttr 
*)node
->Data(); 
 254             m_attrs
.Create(wxKEY_INTEGER
, 1000);        // just as def ctor 
 257         m_hasAnyAttr 
= FALSE
; 
 261 wxListCtrl::~wxListCtrl() 
 263     FreeAllAttrs(TRUE 
/* no need to recreate hash any more */); 
 267         m_textCtrl
->UnsubclassWin(); 
 268         m_textCtrl
->SetHWND(0); 
 274 // ---------------------------------------------------------------------------- 
 275 // set/get/change style 
 276 // ---------------------------------------------------------------------------- 
 278 // Add or remove a single window style 
 279 void wxListCtrl::SetSingleStyle(long style
, bool add
) 
 281     long flag 
= GetWindowStyleFlag(); 
 283     // Get rid of conflicting styles 
 286         if ( style 
& wxLC_MASK_TYPE
) 
 287             flag 
= flag 
& ~wxLC_MASK_TYPE
; 
 288         if ( style 
& wxLC_MASK_ALIGN 
) 
 289             flag 
= flag 
& ~wxLC_MASK_ALIGN
; 
 290         if ( style 
& wxLC_MASK_SORT 
) 
 291             flag 
= flag 
& ~wxLC_MASK_SORT
; 
 307     m_windowStyle 
= flag
; 
 312 // Set the whole window style 
 313 void wxListCtrl::SetWindowStyleFlag(long flag
) 
 315     m_windowStyle 
= flag
; 
 320 // Can be just a single style, or a bitlist 
 321 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const 
 324     if ( style 
& wxLC_ICON 
) 
 326         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_SMALLICON 
) 
 327             oldStyle 
-= LVS_SMALLICON
; 
 328         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_REPORT 
) 
 329             oldStyle 
-= LVS_REPORT
; 
 330         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_LIST 
) 
 331             oldStyle 
-= LVS_LIST
; 
 335     if ( style 
& wxLC_SMALL_ICON 
) 
 337         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_ICON 
) 
 338             oldStyle 
-= LVS_ICON
; 
 339         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_REPORT 
) 
 340             oldStyle 
-= LVS_REPORT
; 
 341         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_LIST 
) 
 342             oldStyle 
-= LVS_LIST
; 
 343         wstyle 
|= LVS_SMALLICON
; 
 346     if ( style 
& wxLC_LIST 
) 
 348         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_ICON 
) 
 349             oldStyle 
-= LVS_ICON
; 
 350         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_REPORT 
) 
 351             oldStyle 
-= LVS_REPORT
; 
 352         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_SMALLICON 
) 
 353             oldStyle 
-= LVS_SMALLICON
; 
 357     if ( style 
& wxLC_REPORT 
) 
 359         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_ICON 
) 
 360             oldStyle 
-= LVS_ICON
; 
 361         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_LIST 
) 
 362             oldStyle 
-= LVS_LIST
; 
 363         if ( (oldStyle 
& LVS_TYPEMASK
) == LVS_SMALLICON 
) 
 364             oldStyle 
-= LVS_SMALLICON
; 
 366         wstyle 
|= LVS_REPORT
; 
 369     if ( style 
& wxLC_ALIGN_LEFT 
) 
 371         if ( oldStyle 
& LVS_ALIGNTOP 
) 
 372             oldStyle 
-= LVS_ALIGNTOP
; 
 373         wstyle 
|= LVS_ALIGNLEFT
; 
 376     if ( style 
& wxLC_ALIGN_TOP 
) 
 378         if ( oldStyle 
& LVS_ALIGNLEFT 
) 
 379             oldStyle 
-= LVS_ALIGNLEFT
; 
 380         wstyle 
|= LVS_ALIGNTOP
; 
 383     if ( style 
& wxLC_AUTOARRANGE 
) 
 384         wstyle 
|= LVS_AUTOARRANGE
; 
 386     // Apparently, no such style (documentation wrong?) 
 388        if ( style & wxLC_BUTTON ) 
 389        wstyle |= LVS_BUTTON; 
 392     if ( style 
& wxLC_NO_SORT_HEADER 
) 
 393         wstyle 
|= LVS_NOSORTHEADER
; 
 395     if ( style 
& wxLC_NO_HEADER 
) 
 396         wstyle 
|= LVS_NOCOLUMNHEADER
; 
 398     if ( style 
& wxLC_EDIT_LABELS 
) 
 399         wstyle 
|= LVS_EDITLABELS
; 
 401     if ( style 
& wxLC_SINGLE_SEL 
) 
 402         wstyle 
|= LVS_SINGLESEL
; 
 404     if ( style 
& wxLC_SORT_ASCENDING 
) 
 406         if ( oldStyle 
& LVS_SORTDESCENDING 
) 
 407             oldStyle 
-= LVS_SORTDESCENDING
; 
 408         wstyle 
|= LVS_SORTASCENDING
; 
 411     if ( style 
& wxLC_SORT_DESCENDING 
) 
 413         if ( oldStyle 
& LVS_SORTASCENDING 
) 
 414             oldStyle 
-= LVS_SORTASCENDING
; 
 415         wstyle 
|= LVS_SORTDESCENDING
; 
 421 // ---------------------------------------------------------------------------- 
 423 // ---------------------------------------------------------------------------- 
 425 // Sets the foreground, i.e. text, colour 
 426 bool wxListCtrl::SetForegroundColour(const wxColour
& col
) 
 428     if ( !wxWindow::SetForegroundColour(col
) ) 
 431     ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
)); 
 436 // Sets the background colour 
 437 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
) 
 439     if ( !wxWindow::SetBackgroundColour(col
) ) 
 442     // we set the same colour for both the "empty" background and the items 
 444     COLORREF color 
= wxColourToRGB(col
); 
 445     ListView_SetBkColor(GetHwnd(), color
); 
 446     ListView_SetTextBkColor(GetHwnd(), color
); 
 451 // Gets information about this column 
 452 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const 
 457     lvCol
.pszText 
= NULL
; 
 459     if ( item
.m_mask 
& wxLIST_MASK_TEXT 
) 
 461         lvCol
.mask 
|= LVCF_TEXT
; 
 462         lvCol
.pszText 
= new wxChar
[513]; 
 463         lvCol
.cchTextMax 
= 512; 
 466     bool success 
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0); 
 468     //  item.m_subItem = lvCol.iSubItem; 
 469     item
.m_width 
= lvCol
.cx
; 
 471     if ( (item
.m_mask 
& wxLIST_MASK_TEXT
) && lvCol
.pszText 
) 
 473         item
.m_text 
= lvCol
.pszText
; 
 474         delete[] lvCol
.pszText
; 
 477     if ( item
.m_mask 
& wxLIST_MASK_FORMAT 
) 
 479         if (lvCol
.fmt 
== LVCFMT_LEFT
) 
 480             item
.m_format 
= wxLIST_FORMAT_LEFT
; 
 481         else if (lvCol
.fmt 
== LVCFMT_RIGHT
) 
 482             item
.m_format 
= wxLIST_FORMAT_RIGHT
; 
 483         else if (lvCol
.fmt 
== LVCFMT_CENTER
) 
 484             item
.m_format 
= wxLIST_FORMAT_CENTRE
; 
 490 // Sets information about this column 
 491 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
) 
 496     lvCol
.pszText 
= NULL
; 
 498     if ( item
.m_mask 
& wxLIST_MASK_TEXT 
) 
 500         lvCol
.mask 
|= LVCF_TEXT
; 
 501         lvCol
.pszText 
= WXSTRINGCAST item
.m_text
; 
 502         lvCol
.cchTextMax 
= 0; // Ignored 
 504     if ( item
.m_mask 
& wxLIST_MASK_FORMAT 
) 
 506         lvCol
.mask 
|= LVCF_FMT
; 
 508         if ( item
.m_format 
== wxLIST_FORMAT_LEFT 
) 
 509             lvCol
.fmt 
= LVCFMT_LEFT
; 
 510         if ( item
.m_format 
== wxLIST_FORMAT_RIGHT 
) 
 511             lvCol
.fmt 
= LVCFMT_RIGHT
; 
 512         if ( item
.m_format 
== wxLIST_FORMAT_CENTRE 
) 
 513             lvCol
.fmt 
= LVCFMT_CENTER
; 
 516     if ( item
.m_mask 
& wxLIST_MASK_WIDTH 
) 
 518         lvCol
.mask 
|= LVCF_WIDTH
; 
 519         lvCol
.cx 
= item
.m_width
; 
 521         if ( lvCol
.cx 
== wxLIST_AUTOSIZE
) 
 522             lvCol
.cx 
= LVSCW_AUTOSIZE
; 
 523         else if ( lvCol
.cx 
== wxLIST_AUTOSIZE_USEHEADER
) 
 524             lvCol
.cx 
= LVSCW_AUTOSIZE_USEHEADER
; 
 526     lvCol
.mask 
|= LVCF_SUBITEM
; 
 527     lvCol
.iSubItem 
= col
; 
 528     return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0); 
 531 // Gets the column width 
 532 int wxListCtrl::GetColumnWidth(int col
) const 
 534     return ListView_GetColumnWidth(GetHwnd(), col
); 
 537 // Sets the column width 
 538 bool wxListCtrl::SetColumnWidth(int col
, int width
) 
 541     if ( m_windowStyle 
& wxLC_LIST 
) 
 545     if ( width2 
== wxLIST_AUTOSIZE
) 
 546         width2 
= LVSCW_AUTOSIZE
; 
 547     else if ( width2 
== wxLIST_AUTOSIZE_USEHEADER
) 
 548         width2 
= LVSCW_AUTOSIZE_USEHEADER
; 
 550     return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0); 
 553 // Gets the number of items that can fit vertically in the 
 554 // visible area of the list control (list or report view) 
 555 // or the total number of items in the list control (icon 
 556 // or small icon view) 
 557 int wxListCtrl::GetCountPerPage() const 
 559     return ListView_GetCountPerPage(GetHwnd()); 
 562 // Gets the edit control for editing labels. 
 563 wxTextCtrl
* wxListCtrl::GetEditControl() const 
 568 // Gets information about the item 
 569 bool wxListCtrl::GetItem(wxListItem
& info
) const 
 572     wxZeroMemory(lvItem
); 
 574     lvItem
.iItem 
= info
.m_itemId
; 
 575     lvItem
.iSubItem 
= info
.m_col
; 
 577     if ( info
.m_mask 
& wxLIST_MASK_TEXT 
) 
 579         lvItem
.mask 
|= LVIF_TEXT
; 
 580         lvItem
.pszText 
= new wxChar
[513]; 
 581         lvItem
.cchTextMax 
= 512; 
 585         lvItem
.pszText 
= NULL
; 
 588     if (info
.m_mask 
& wxLIST_MASK_DATA
) 
 589         lvItem
.mask 
|= LVIF_PARAM
; 
 591     if ( info
.m_mask 
& wxLIST_MASK_STATE 
) 
 593         lvItem
.mask 
|= LVIF_STATE
; 
 594         // the other bits are hardly interesting anyhow 
 595         lvItem
.stateMask 
= LVIS_SELECTED 
| LVIS_FOCUSED
; 
 598     bool success 
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0; 
 601         wxLogError(_("Couldn't retrieve information about list control item %d."), 
 606         wxConvertFromMSWListItem(this, info
, lvItem
); 
 610         delete[] lvItem
.pszText
; 
 615 // Sets information about the item 
 616 bool wxListCtrl::SetItem(wxListItem
& info
) 
 619     wxConvertToMSWListItem(this, info
, item
); 
 621     // check whether it has any custom attributes 
 622     if ( info
.HasAttributes() ) 
 624         m_attrs
.Put(item
.iItem
, (wxObject 
*)new wxListItemAttr(*info
.GetAttributes())); 
 630     bool ok 
= ListView_SetItem(GetHwnd(), &item
) != 0; 
 631     if ( ok 
&& (info
.m_mask 
& wxLIST_MASK_IMAGE
) ) 
 633         // make the change visible 
 634         ListView_Update(GetHwnd(), item
.iItem
); 
 640 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
) 
 644     info
.m_mask 
= wxLIST_MASK_TEXT
; 
 645     info
.m_itemId 
= index
; 
 649         info
.m_image 
= imageId
; 
 650         info
.m_mask 
|= wxLIST_MASK_IMAGE
; 
 652     return SetItem(info
); 
 656 // Gets the item state 
 657 int wxListCtrl::GetItemState(long item
, long stateMask
) const 
 661     info
.m_mask 
= wxLIST_MASK_STATE
; 
 662     info
.m_stateMask 
= stateMask
; 
 663     info
.m_itemId 
= item
; 
 671 // Sets the item state 
 672 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
) 
 676     info
.m_mask 
= wxLIST_MASK_STATE
; 
 677     info
.m_state 
= state
; 
 678     info
.m_stateMask 
= stateMask
; 
 679     info
.m_itemId 
= item
; 
 681     return SetItem(info
); 
 684 // Sets the item image 
 685 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
) 
 689     info
.m_mask 
= wxLIST_MASK_IMAGE
; 
 690     info
.m_image 
= image
; 
 691     info
.m_itemId 
= item
; 
 693     return SetItem(info
); 
 696 // Gets the item text 
 697 wxString 
wxListCtrl::GetItemText(long item
) const 
 701     info
.m_mask 
= wxLIST_MASK_TEXT
; 
 702     info
.m_itemId 
= item
; 
 709 // Sets the item text 
 710 void wxListCtrl::SetItemText(long item
, const wxString
& str
) 
 714     info
.m_mask 
= wxLIST_MASK_TEXT
; 
 715     info
.m_itemId 
= item
; 
 721 // Gets the item data 
 722 long wxListCtrl::GetItemData(long item
) const 
 726     info
.m_mask 
= wxLIST_MASK_DATA
; 
 727     info
.m_itemId 
= item
; 
 734 // Sets the item data 
 735 bool wxListCtrl::SetItemData(long item
, long data
) 
 739     info
.m_mask 
= wxLIST_MASK_DATA
; 
 740     info
.m_itemId 
= item
; 
 743     return SetItem(info
); 
 746 // Gets the item rectangle 
 747 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const 
 751     int code2 
= LVIR_BOUNDS
; 
 752     if ( code 
== wxLIST_RECT_BOUNDS 
) 
 754     else if ( code 
== wxLIST_RECT_ICON 
) 
 756     else if ( code 
== wxLIST_RECT_LABEL 
) 
 760     bool success 
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2 
) != 0); 
 762     bool success 
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0); 
 767     rect
.width 
= rect2
.right 
- rect2
.left
; 
 768     rect
.height 
= rect2
.bottom 
- rect2
.left
; 
 772 // Gets the item position 
 773 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const 
 777     bool success 
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0); 
 779     pos
.x 
= pt
.x
; pos
.y 
= pt
.y
; 
 783 // Sets the item position. 
 784 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
) 
 786     return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0); 
 789 // Gets the number of items in the list control 
 790 int wxListCtrl::GetItemCount() const 
 792     return ListView_GetItemCount(GetHwnd()); 
 795 // Retrieves the spacing between icons in pixels. 
 796 // If small is TRUE, gets the spacing for the small icon 
 797 // view, otherwise the large icon view. 
 798 int wxListCtrl::GetItemSpacing(bool isSmall
) const 
 800     return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
); 
 803 // Gets the number of selected items in the list control 
 804 int wxListCtrl::GetSelectedItemCount() const 
 806     return ListView_GetSelectedCount(GetHwnd()); 
 809 // Gets the text colour of the listview 
 810 wxColour 
wxListCtrl::GetTextColour() const 
 812     COLORREF ref 
= ListView_GetTextColor(GetHwnd()); 
 813     wxColour 
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
)); 
 817 // Sets the text colour of the listview 
 818 void wxListCtrl::SetTextColour(const wxColour
& col
) 
 820     ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue())); 
 823 // Gets the index of the topmost visible item when in 
 824 // list or report view 
 825 long wxListCtrl::GetTopItem() const 
 827     return (long) ListView_GetTopIndex(GetHwnd()); 
 830 // Searches for an item, starting from 'item'. 
 831 // 'geometry' is one of 
 832 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT. 
 833 // 'state' is a state bit flag, one or more of 
 834 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT. 
 835 // item can be -1 to find the first item that matches the 
 837 // Returns the item or -1 if unsuccessful. 
 838 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const 
 842     if ( geom 
== wxLIST_NEXT_ABOVE 
) 
 844     if ( geom 
== wxLIST_NEXT_ALL 
) 
 846     if ( geom 
== wxLIST_NEXT_BELOW 
) 
 848     if ( geom 
== wxLIST_NEXT_LEFT 
) 
 849         flags 
|= LVNI_TOLEFT
; 
 850     if ( geom 
== wxLIST_NEXT_RIGHT 
) 
 851         flags 
|= LVNI_TORIGHT
; 
 853     if ( state 
& wxLIST_STATE_CUT 
) 
 855     if ( state 
& wxLIST_STATE_DROPHILITED 
) 
 856         flags 
|= LVNI_DROPHILITED
; 
 857     if ( state 
& wxLIST_STATE_FOCUSED 
) 
 858         flags 
|= LVNI_FOCUSED
; 
 859     if ( state 
& wxLIST_STATE_SELECTED 
) 
 860         flags 
|= LVNI_SELECTED
; 
 862     return (long) ListView_GetNextItem(GetHwnd(), item
, flags
); 
 866 wxImageList 
*wxListCtrl::GetImageList(int which
) const 
 868     if ( which 
== wxIMAGE_LIST_NORMAL 
) 
 870         return m_imageListNormal
; 
 872     else if ( which 
== wxIMAGE_LIST_SMALL 
) 
 874         return m_imageListSmall
; 
 876     else if ( which 
== wxIMAGE_LIST_STATE 
) 
 878         return m_imageListState
; 
 883 void wxListCtrl::SetImageList(wxImageList 
*imageList
, int which
) 
 886     if ( which 
== wxIMAGE_LIST_NORMAL 
) 
 888         flags 
= LVSIL_NORMAL
; 
 889         m_imageListNormal 
= imageList
; 
 891     else if ( which 
== wxIMAGE_LIST_SMALL 
) 
 894         m_imageListSmall 
= imageList
; 
 896     else if ( which 
== wxIMAGE_LIST_STATE 
) 
 899         m_imageListState 
= imageList
; 
 901     ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList 
? imageList
->GetHIMAGELIST() : 0, flags
); 
 904 // ---------------------------------------------------------------------------- 
 906 // ---------------------------------------------------------------------------- 
 908 // Arranges the items 
 909 bool wxListCtrl::Arrange(int flag
) 
 912     if ( flag 
== wxLIST_ALIGN_LEFT 
) 
 913         code 
= LVA_ALIGNLEFT
; 
 914     else if ( flag 
== wxLIST_ALIGN_TOP 
) 
 916     else if ( flag 
== wxLIST_ALIGN_DEFAULT 
) 
 918     else if ( flag 
== wxLIST_ALIGN_SNAP_TO_GRID 
) 
 919         code 
= LVA_SNAPTOGRID
; 
 921     return (ListView_Arrange(GetHwnd(), code
) != 0); 
 925 bool wxListCtrl::DeleteItem(long item
) 
 927     return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0); 
 931 bool wxListCtrl::DeleteAllItems() 
 933     return (ListView_DeleteAllItems(GetHwnd()) != 0); 
 937 bool wxListCtrl::DeleteAllColumns() 
 939     while ( m_colCount 
> 0 ) 
 941         if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 ) 
 943             wxLogLastError("ListView_DeleteColumn"); 
 951     wxASSERT_MSG( m_colCount 
== 0, wxT("no columns should be left") ); 
 957 bool wxListCtrl::DeleteColumn(int col
) 
 959     bool success 
= (ListView_DeleteColumn(GetHwnd(), col
) != 0); 
 961     if ( success 
&& (m_colCount 
> 0) ) 
 966 // Clears items, and columns if there are any. 
 967 void wxListCtrl::ClearAll() 
 970     if ( m_colCount 
> 0 ) 
 974 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
) 
 976     wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) ); 
 978     HWND hWnd 
= (HWND
) ListView_EditLabel(GetHwnd(), item
); 
 982         m_textCtrl
->UnsubclassWin(); 
 983         m_textCtrl
->SetHWND(0); 
 988     m_textCtrl 
= (wxTextCtrl
*) textControlClass
->CreateObject(); 
 989     m_textCtrl
->SetHWND((WXHWND
) hWnd
); 
 990     m_textCtrl
->SubclassWin((WXHWND
) hWnd
); 
 995 // End label editing, optionally cancelling the edit 
 996 bool wxListCtrl::EndEditLabel(bool cancel
) 
1000     /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow. 
1002      bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0); 
1006      m_textCtrl->UnsubclassWin(); 
1007      m_textCtrl->SetHWND(0); 
1017 // Ensures this item is visible 
1018 bool wxListCtrl::EnsureVisible(long item
) 
1020     return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0); 
1023 // Find an item whose label matches this string, starting from the item after 'start' 
1024 // or the beginning if 'start' is -1. 
1025 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
) 
1027     LV_FINDINFO findInfo
; 
1029     findInfo
.flags 
= LVFI_STRING
; 
1031         findInfo
.flags 
|= LVFI_STRING
; 
1032     findInfo
.psz 
= WXSTRINGCAST str
; 
1034     return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
); 
1037 // Find an item whose data matches this data, starting from the item after 'start' 
1038 // or the beginning if 'start' is -1. 
1039 long wxListCtrl::FindItem(long start
, long data
) 
1041     LV_FINDINFO findInfo
; 
1043     findInfo
.flags 
= LVFI_PARAM
; 
1044     findInfo
.lParam 
= data
; 
1046     return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
); 
1049 // Find an item nearest this position in the specified direction, starting from 
1050 // the item after 'start' or the beginning if 'start' is -1. 
1051 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
) 
1053     LV_FINDINFO findInfo
; 
1055     findInfo
.flags 
= LVFI_NEARESTXY
; 
1056     findInfo
.pt
.x 
= pt
.x
; 
1057     findInfo
.pt
.y 
= pt
.y
; 
1058     findInfo
.vkDirection 
= VK_RIGHT
; 
1060     if ( direction 
== wxLIST_FIND_UP 
) 
1061         findInfo
.vkDirection 
= VK_UP
; 
1062     else if ( direction 
== wxLIST_FIND_DOWN 
) 
1063         findInfo
.vkDirection 
= VK_DOWN
; 
1064     else if ( direction 
== wxLIST_FIND_LEFT 
) 
1065         findInfo
.vkDirection 
= VK_LEFT
; 
1066     else if ( direction 
== wxLIST_FIND_RIGHT 
) 
1067         findInfo
.vkDirection 
= VK_RIGHT
; 
1069     return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
); 
1072 // Determines which item (if any) is at the specified point, 
1073 // giving details in 'flags' (see wxLIST_HITTEST_... flags above) 
1074 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
) 
1076     LV_HITTESTINFO hitTestInfo
; 
1077     hitTestInfo
.pt
.x 
= (int) point
.x
; 
1078     hitTestInfo
.pt
.y 
= (int) point
.y
; 
1080     ListView_HitTest(GetHwnd(), & hitTestInfo
); 
1083     if ( hitTestInfo
.flags 
& LVHT_ABOVE 
) 
1084         flags 
|= wxLIST_HITTEST_ABOVE
; 
1085     if ( hitTestInfo
.flags 
& LVHT_BELOW 
) 
1086         flags 
|= wxLIST_HITTEST_BELOW
; 
1087     if ( hitTestInfo
.flags 
& LVHT_NOWHERE 
) 
1088         flags 
|= wxLIST_HITTEST_NOWHERE
; 
1089     if ( hitTestInfo
.flags 
& LVHT_ONITEMICON 
) 
1090         flags 
|= wxLIST_HITTEST_ONITEMICON
; 
1091     if ( hitTestInfo
.flags 
& LVHT_ONITEMLABEL 
) 
1092         flags 
|= wxLIST_HITTEST_ONITEMLABEL
; 
1093     if ( hitTestInfo
.flags 
& LVHT_ONITEMSTATEICON 
) 
1094         flags 
|= wxLIST_HITTEST_ONITEMSTATEICON
; 
1095     if ( hitTestInfo
.flags 
& LVHT_TOLEFT 
) 
1096         flags 
|= wxLIST_HITTEST_TOLEFT
; 
1097     if ( hitTestInfo
.flags 
& LVHT_TORIGHT 
) 
1098         flags 
|= wxLIST_HITTEST_TORIGHT
; 
1100     return (long) hitTestInfo
.iItem
; 
1103 // Inserts an item, returning the index of the new item if successful, 
1105 long wxListCtrl::InsertItem(wxListItem
& info
) 
1108     wxConvertToMSWListItem(this, info
, item
); 
1110     // check whether it has any custom attributes 
1111     if ( info
.HasAttributes() ) 
1113         m_attrs
.Put(item
.iItem
, (wxObject 
*)new wxListItemAttr(*info
.GetAttributes())); 
1115         m_hasAnyAttr 
= TRUE
; 
1118     return (long) ListView_InsertItem(GetHwnd(), & item
); 
1121 long wxListCtrl::InsertItem(long index
, const wxString
& label
) 
1124     info
.m_text 
= label
; 
1125     info
.m_mask 
= wxLIST_MASK_TEXT
; 
1126     info
.m_itemId 
= index
; 
1127     return InsertItem(info
); 
1130 // Inserts an image item 
1131 long wxListCtrl::InsertItem(long index
, int imageIndex
) 
1134     info
.m_image 
= imageIndex
; 
1135     info
.m_mask 
= wxLIST_MASK_IMAGE
; 
1136     info
.m_itemId 
= index
; 
1137     return InsertItem(info
); 
1140 // Inserts an image/string item 
1141 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
) 
1144     info
.m_image 
= imageIndex
; 
1145     info
.m_text 
= label
; 
1146     info
.m_mask 
= wxLIST_MASK_IMAGE 
| wxLIST_MASK_TEXT
; 
1147     info
.m_itemId 
= index
; 
1148     return InsertItem(info
); 
1151 // For list view mode (only), inserts a column. 
1152 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
) 
1157     lvCol
.pszText 
= NULL
; 
1159     if ( item
.m_mask 
& wxLIST_MASK_TEXT 
) 
1161         lvCol
.mask 
|= LVCF_TEXT
; 
1162         lvCol
.pszText 
= WXSTRINGCAST item
.m_text
; 
1163         lvCol
.cchTextMax 
= 0; // Ignored 
1165     if ( item
.m_mask 
& wxLIST_MASK_FORMAT 
) 
1167         lvCol
.mask 
|= LVCF_FMT
; 
1169         if ( item
.m_format 
== wxLIST_FORMAT_LEFT 
) 
1170             lvCol
.fmt 
= LVCFMT_LEFT
; 
1171         if ( item
.m_format 
== wxLIST_FORMAT_RIGHT 
) 
1172             lvCol
.fmt 
= LVCFMT_RIGHT
; 
1173         if ( item
.m_format 
== wxLIST_FORMAT_CENTRE 
) 
1174             lvCol
.fmt 
= LVCFMT_CENTER
; 
1177     lvCol
.mask 
|= LVCF_WIDTH
; 
1178     if ( item
.m_mask 
& wxLIST_MASK_WIDTH 
) 
1180         if ( item
.m_width 
== wxLIST_AUTOSIZE
) 
1181             lvCol
.cx 
= LVSCW_AUTOSIZE
; 
1182         else if ( item
.m_width 
== wxLIST_AUTOSIZE_USEHEADER
) 
1183             lvCol
.cx 
= LVSCW_AUTOSIZE_USEHEADER
; 
1185             lvCol
.cx 
= item
.m_width
; 
1189         // always give some width to the new column: this one is compatible 
1194     lvCol
.mask 
|= LVCF_SUBITEM
; 
1195     lvCol
.iSubItem 
= col
; 
1197     bool success 
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1; 
1204         wxLogDebug(wxT("Failed to insert the column '%s' into listview!"), 
1211 long wxListCtrl::InsertColumn(long col
, 
1212                               const wxString
& heading
, 
1217     item
.m_mask 
= wxLIST_MASK_TEXT 
| wxLIST_MASK_FORMAT
; 
1218     item
.m_text 
= heading
; 
1221         item
.m_mask 
|= wxLIST_MASK_WIDTH
; 
1222         item
.m_width 
= width
; 
1224     item
.m_format 
= format
; 
1226     return InsertColumn(col
, item
); 
1229 // Scrolls the list control. If in icon, small icon or report view mode, 
1230 // x specifies the number of pixels to scroll. If in list view mode, x 
1231 // specifies the number of columns to scroll. 
1232 // If in icon, small icon or list view mode, y specifies the number of pixels 
1233 // to scroll. If in report view mode, y specifies the number of lines to scroll. 
1234 bool wxListCtrl::ScrollList(int dx
, int dy
) 
1236     return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0); 
1241 // fn is a function which takes 3 long arguments: item1, item2, data. 
1242 // item1 is the long data associated with a first item (NOT the index). 
1243 // item2 is the long data associated with a second item (NOT the index). 
1244 // data is the same value as passed to SortItems. 
1245 // The return value is a negative number if the first item should precede the second 
1246 // item, a positive number of the second item should precede the first, 
1247 // or zero if the two items are equivalent. 
1249 // data is arbitrary data to be passed to the sort function. 
1250 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
) 
1252     return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0); 
1255 // ---------------------------------------------------------------------------- 
1256 // message processing 
1257 // ---------------------------------------------------------------------------- 
1259 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
) 
1261     if (cmd 
== EN_UPDATE
) 
1263         wxCommandEvent 
event(wxEVT_COMMAND_TEXT_UPDATED
, id
); 
1264         event
.SetEventObject( this ); 
1265         ProcessCommand(event
); 
1268     else if (cmd 
== EN_KILLFOCUS
) 
1270         wxCommandEvent 
event(wxEVT_KILL_FOCUS
, id
); 
1271         event
.SetEventObject( this ); 
1272         ProcessCommand(event
); 
1279 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM 
*result
) 
1281     // prepare the event 
1282     // ----------------- 
1284     wxListEvent 
event(wxEVT_NULL
, m_windowId
); 
1285     wxEventType eventType 
= wxEVT_NULL
; 
1286     NMHDR 
*nmhdr 
= (NMHDR 
*)lParam
; 
1287     switch ( nmhdr
->code 
) 
1289         case LVN_BEGINRDRAG
: 
1290             eventType 
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
; 
1294             if ( eventType 
== wxEVT_NULL 
) 
1296                 eventType 
= wxEVT_COMMAND_LIST_BEGIN_DRAG
; 
1300                 NM_LISTVIEW 
*hdr 
= (NM_LISTVIEW 
*)lParam
; 
1301                 event
.m_itemIndex 
= hdr
->iItem
; 
1302                 event
.m_pointDrag
.x 
= hdr
->ptAction
.x
; 
1303                 event
.m_pointDrag
.y 
= hdr
->ptAction
.y
; 
1307         case LVN_BEGINLABELEDIT
: 
1309                 eventType 
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
; 
1310                 LV_DISPINFO 
*info 
= (LV_DISPINFO 
*)lParam
; 
1311                 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd()); 
1315         case LVN_COLUMNCLICK
: 
1317                 eventType 
= wxEVT_COMMAND_LIST_COL_CLICK
; 
1318                 NM_LISTVIEW
* hdr 
= (NM_LISTVIEW
*)lParam
; 
1319                 event
.m_itemIndex 
= -1; 
1320                 event
.m_col 
= hdr
->iSubItem
; 
1324         case LVN_DELETEALLITEMS
: 
1325             eventType 
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
; 
1326             event
.m_itemIndex 
= -1; 
1332         case LVN_DELETEITEM
: 
1334                 eventType 
= wxEVT_COMMAND_LIST_DELETE_ITEM
; 
1335                 NM_LISTVIEW
* hdr 
= (NM_LISTVIEW
*)lParam
; 
1336                 event
.m_itemIndex 
= hdr
->iItem
; 
1340                     delete (wxListItemAttr 
*)m_attrs
.Delete(hdr
->iItem
); 
1345         case LVN_ENDLABELEDIT
: 
1347                 eventType 
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
; 
1348                 LV_DISPINFO 
*info 
= (LV_DISPINFO 
*)lParam
; 
1349                 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
); 
1350                 if ( info
->item
.pszText 
== NULL 
|| info
->item
.iItem 
== -1 ) 
1355         case LVN_SETDISPINFO
: 
1357                 eventType 
= wxEVT_COMMAND_LIST_SET_INFO
; 
1358                 LV_DISPINFO 
*info 
= (LV_DISPINFO 
*)lParam
; 
1359                 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd()); 
1363         case LVN_GETDISPINFO
: 
1364                 // this provokes stack overflow: indeed, wxConvertFromMSWListItem() 
1365                 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave 
1369                 // TODO: some text buffering here, I think 
1370                 // TODO: API for getting Windows to retrieve values 
1372                 eventType 
= wxEVT_COMMAND_LIST_GET_INFO
; 
1373                 LV_DISPINFO 
*info 
= (LV_DISPINFO 
*)lParam
; 
1374                 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd()); 
1381         case LVN_INSERTITEM
: 
1383                 eventType 
= wxEVT_COMMAND_LIST_INSERT_ITEM
; 
1384                 NM_LISTVIEW
* hdr 
= (NM_LISTVIEW
*)lParam
; 
1385                 event
.m_itemIndex 
= hdr
->iItem
; 
1389         case LVN_ITEMCHANGED
: 
1391                 // This needs to be sent to wxListCtrl as a rather more 
1392                 // concrete event. For now, just detect a selection 
1394                 NM_LISTVIEW
* hdr 
= (NM_LISTVIEW
*)lParam
; 
1395                 if ( (hdr
->uNewState 
& LVIS_SELECTED
) && !(hdr
->uOldState 
& LVIS_SELECTED
) ) 
1397                     eventType 
= wxEVT_COMMAND_LIST_ITEM_SELECTED
; 
1398                     event
.m_itemIndex 
= hdr
->iItem
; 
1400                 else if ( !(hdr
->uNewState 
& LVIS_SELECTED
) && (hdr
->uOldState 
& LVIS_SELECTED
) ) 
1402                     eventType 
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
; 
1403                     event
.m_itemIndex 
= hdr
->iItem
; 
1412                 LV_KEYDOWN 
*info 
= (LV_KEYDOWN 
*)lParam
; 
1413                 WORD wVKey 
= info
->wVKey
; 
1415                 // get the current selection 
1416                 long lItem 
= GetNextItem(-1, 
1418                                          wxLIST_STATE_SELECTED
); 
1420                 // <Enter> or <Space> activate the selected item if any 
1421                 if ( lItem 
!= -1 && (wVKey 
== VK_RETURN 
|| wVKey 
== VK_SPACE
) ) 
1423                     // TODO this behaviour probably should be optional 
1424                     eventType 
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
; 
1425                     event
.m_itemIndex 
= lItem
; 
1429                     eventType 
= wxEVT_COMMAND_LIST_KEY_DOWN
; 
1430                     event
.m_code 
= wxCharCodeMSWToWX(wVKey
); 
1436             // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do 
1438             if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) ) 
1443             // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event 
1444             // if it happened on an item (and not on empty place) 
1446                 NM_LISTVIEW
* hdr 
= (NM_LISTVIEW
*)lParam
; 
1447                 if ( hdr
->iItem 
== -1 ) 
1453                 eventType 
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
; 
1454                 event
.m_itemIndex 
= hdr
->iItem
; 
1459         /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to 
1460            subclass and check for the actual WM_RBUTTONDOWN message, because 
1461            NM_RCLICK waits for the WM_RBUTTONUP message as well before firing off. 
1462            We want to have notify events for both down -and- up. */ 
1464             // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), don't do 
1466             if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) ) { 
1470             // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event 
1471             LV_HITTESTINFO lvhti
; 
1472             wxZeroMemory(lvhti
); 
1474             ::GetCursorPos(&(lvhti
.pt
)); 
1475             ::ScreenToClient(GetHwnd(),&(lvhti
.pt
)); 
1476             if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 ) 
1478                 if ( lvhti
.flags 
& LVHT_ONITEM 
) 
1480                     eventType 
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
; 
1481                     event
.m_itemIndex 
= lvhti
.iItem
; 
1488         case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ****** 
1490                 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do 
1492                 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) ) 
1497                 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event 
1498                 eventType 
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
; 
1499                 NMITEMACTIVATE
* hdr 
= (NMITEMACTIVATE
*)lParam
; 
1500                 event
.m_itemIndex 
= hdr
->iItem
; 
1505 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 
1508                 LPNMLVCUSTOMDRAW lplvcd 
= (LPNMLVCUSTOMDRAW
)lParam
; 
1509                 NMCUSTOMDRAW
& nmcd 
= lplvcd
->nmcd
; 
1510                 switch( nmcd
.dwDrawStage 
) 
1513                         // if we've got any items with non standard attributes, 
1514                         // notify us before painting each item 
1515                         *result 
= m_hasAnyAttr 
? CDRF_NOTIFYITEMDRAW
 
1519                     case CDDS_ITEMPREPAINT
: 
1521                             wxListItemAttr 
*attr 
= 
1522                                 (wxListItemAttr 
*)m_attrs
.Get(nmcd
.dwItemSpec
); 
1526                                 // nothing to do for this item 
1527                                 return CDRF_DODEFAULT
; 
1531                             wxColour colText
, colBack
; 
1532                             if ( attr
->HasFont() ) 
1534                                 wxFont font 
= attr
->GetFont(); 
1535                                 hFont 
= (HFONT
)font
.GetResourceHandle(); 
1542                             if ( attr
->HasTextColour() ) 
1544                                 colText 
= attr
->GetTextColour(); 
1548                                 colText 
= GetTextColour(); 
1551                             if ( attr
->HasBackgroundColour() ) 
1553                                 colBack 
= attr
->GetBackgroundColour(); 
1557                                 colBack 
= GetBackgroundColour(); 
1560                             // note that if we wanted to set colours for 
1561                             // individual columns (subitems), we would have 
1562                             // returned CDRF_NOTIFYSUBITEMREDRAW from here 
1565                                 ::SelectObject(nmcd
.hdc
, hFont
); 
1567                                 *result 
= CDRF_NEWFONT
; 
1571                                 *result 
= CDRF_DODEFAULT
; 
1574                             lplvcd
->clrText 
= wxColourToRGB(colText
); 
1575                             lplvcd
->clrTextBk 
= wxColourToRGB(colBack
); 
1581                         *result 
= CDRF_DODEFAULT
; 
1586 #endif // _WIN32_IE >= 0x300 
1589             return wxControl::MSWOnNotify(idCtrl
, lParam
, result
); 
1592     // process the event 
1593     // ----------------- 
1595     event
.SetEventObject( this ); 
1596     event
.SetEventType(eventType
); 
1598     if ( !GetEventHandler()->ProcessEvent(event
) ) 
1604     switch ( (int)nmhdr
->code 
) 
1606         case LVN_DELETEALLITEMS
: 
1607             // always return TRUE to suppress all additional LVN_DELETEITEM 
1608             // notifications - this makes deleting all items from a list ctrl 
1614         case LVN_GETDISPINFO
: 
1616                 LV_DISPINFO 
*info 
= (LV_DISPINFO 
*)lParam
; 
1617                 if ( info
->item
.mask 
& LVIF_TEXT 
) 
1619                     if ( !event
.m_item
.m_text
.IsNull() ) 
1621                         info
->item
.pszText 
= AddPool(event
.m_item
.m_text
); 
1622                         info
->item
.cchTextMax 
= wxStrlen(info
->item
.pszText
) + 1; 
1625                 //    wxConvertToMSWListItem(this, event.m_item, info->item); 
1628         case LVN_ENDLABELEDIT
: 
1630                 *result 
= event
.IsAllowed(); 
1635     *result 
= !event
.IsAllowed(); 
1640 wxChar 
*wxListCtrl::AddPool(const wxString
& str
) 
1642     // Remove the first element if 3 strings exist 
1643     if ( m_stringPool
.Number() == 3 ) 
1645         wxNode 
*node 
= m_stringPool
.First(); 
1646         delete[] (char *)node
->Data(); 
1649     wxNode 
*node 
= m_stringPool
.Add(WXSTRINGCAST str
); 
1650     return (wxChar 
*)node
->Data(); 
1653 // ---------------------------------------------------------------------------- 
1655 // ---------------------------------------------------------------------------- 
1657 // List item structure 
1658 wxListItem::wxListItem() 
1668     m_format 
= wxLIST_FORMAT_CENTRE
; 
1674 void wxListItem::Clear() 
1683     m_format 
= wxLIST_FORMAT_CENTRE
; 
1685     m_text 
= wxEmptyString
; 
1687     if (m_attr
) delete m_attr
; 
1691 void wxListItem::ClearAttributes() 
1693     if (m_attr
) delete m_attr
; 
1697 static void wxConvertFromMSWListItem(const wxListCtrl 
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
) 
1699     info
.m_data 
= lvItem
.lParam
; 
1702     info
.m_stateMask 
= 0; 
1703     info
.m_itemId 
= lvItem
.iItem
; 
1705     long oldMask 
= lvItem
.mask
; 
1707     bool needText 
= FALSE
; 
1708     if (getFullInfo 
!= 0) 
1710         if ( lvItem
.mask 
& LVIF_TEXT 
) 
1717             lvItem
.pszText 
= new wxChar
[513]; 
1718             lvItem
.cchTextMax 
= 512; 
1720         //    lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM; 
1721         lvItem
.mask 
|= LVIF_TEXT 
| LVIF_IMAGE 
| LVIF_PARAM
; 
1722         ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
); 
1725     if ( lvItem
.mask 
& LVIF_STATE 
) 
1727         info
.m_mask 
|= wxLIST_MASK_STATE
; 
1729         if ( lvItem
.stateMask 
& LVIS_CUT
) 
1731             info
.m_stateMask 
|= wxLIST_STATE_CUT
; 
1732             if ( lvItem
.state 
& LVIS_CUT 
) 
1733                 info
.m_state 
|= wxLIST_STATE_CUT
; 
1735         if ( lvItem
.stateMask 
& LVIS_DROPHILITED
) 
1737             info
.m_stateMask 
|= wxLIST_STATE_DROPHILITED
; 
1738             if ( lvItem
.state 
& LVIS_DROPHILITED 
) 
1739                 info
.m_state 
|= wxLIST_STATE_DROPHILITED
; 
1741         if ( lvItem
.stateMask 
& LVIS_FOCUSED
) 
1743             info
.m_stateMask 
|= wxLIST_STATE_FOCUSED
; 
1744             if ( lvItem
.state 
& LVIS_FOCUSED 
) 
1745                 info
.m_state 
|= wxLIST_STATE_FOCUSED
; 
1747         if ( lvItem
.stateMask 
& LVIS_SELECTED
) 
1749             info
.m_stateMask 
|= wxLIST_STATE_SELECTED
; 
1750             if ( lvItem
.state 
& LVIS_SELECTED 
) 
1751                 info
.m_state 
|= wxLIST_STATE_SELECTED
; 
1755     if ( lvItem
.mask 
& LVIF_TEXT 
) 
1757         info
.m_mask 
|= wxLIST_MASK_TEXT
; 
1758         info
.m_text 
= lvItem
.pszText
; 
1760     if ( lvItem
.mask 
& LVIF_IMAGE 
) 
1762         info
.m_mask 
|= wxLIST_MASK_IMAGE
; 
1763         info
.m_image 
= lvItem
.iImage
; 
1765     if ( lvItem
.mask 
& LVIF_PARAM 
) 
1766         info
.m_mask 
|= wxLIST_MASK_DATA
; 
1767     if ( lvItem
.mask 
& LVIF_DI_SETITEM 
) 
1768         info
.m_mask 
|= wxLIST_SET_ITEM
; 
1769     info
.m_col 
= lvItem
.iSubItem
; 
1774             delete[] lvItem
.pszText
; 
1776     lvItem
.mask 
= oldMask
; 
1779 static void wxConvertToMSWListItem(const wxListCtrl 
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
) 
1781     lvItem
.iItem 
= (int) info
.m_itemId
; 
1783     lvItem
.iImage 
= info
.m_image
; 
1784     lvItem
.lParam 
= info
.m_data
; 
1785     lvItem
.stateMask 
= 0; 
1788     lvItem
.iSubItem 
= info
.m_col
; 
1790     if (info
.m_mask 
& wxLIST_MASK_STATE
) 
1792         lvItem
.mask 
|= LVIF_STATE
; 
1793         if (info
.m_stateMask 
& wxLIST_STATE_CUT
) 
1795             lvItem
.stateMask 
|= LVIS_CUT
; 
1796             if (info
.m_state 
& wxLIST_STATE_CUT
) 
1797                 lvItem
.state 
|= LVIS_CUT
; 
1799         if (info
.m_stateMask 
& wxLIST_STATE_DROPHILITED
) 
1801             lvItem
.stateMask 
|= LVIS_DROPHILITED
; 
1802             if (info
.m_state 
& wxLIST_STATE_DROPHILITED
) 
1803                 lvItem
.state 
|= LVIS_DROPHILITED
; 
1805         if (info
.m_stateMask 
& wxLIST_STATE_FOCUSED
) 
1807             lvItem
.stateMask 
|= LVIS_FOCUSED
; 
1808             if (info
.m_state 
& wxLIST_STATE_FOCUSED
) 
1809                 lvItem
.state 
|= LVIS_FOCUSED
; 
1811         if (info
.m_stateMask 
& wxLIST_STATE_SELECTED
) 
1813             lvItem
.stateMask 
|= LVIS_SELECTED
; 
1814             if (info
.m_state 
& wxLIST_STATE_SELECTED
) 
1815                 lvItem
.state 
|= LVIS_SELECTED
; 
1819     if (info
.m_mask 
& wxLIST_MASK_TEXT
) 
1821         lvItem
.mask 
|= LVIF_TEXT
; 
1822         if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT 
) 
1824             lvItem
.pszText 
= LPSTR_TEXTCALLBACK
; 
1828             lvItem
.pszText 
= WXSTRINGCAST info
.m_text
; 
1829             if ( lvItem
.pszText 
) 
1830                 lvItem
.cchTextMax 
= info
.m_text
.Length(); 
1832                 lvItem
.cchTextMax 
= 0; 
1835     if (info
.m_mask 
& wxLIST_MASK_IMAGE
) 
1836         lvItem
.mask 
|= LVIF_IMAGE
; 
1837     if (info
.m_mask 
& wxLIST_MASK_DATA
) 
1838         lvItem
.mask 
|= LVIF_PARAM
; 
1841 // ---------------------------------------------------------------------------- 
1843 // ---------------------------------------------------------------------------- 
1845 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
) 
1847 wxListEvent::wxListEvent(wxEventType commandType
, int id
) 
1848            : wxNotifyEvent(commandType
, id
) 
1854     m_cancelled 
= FALSE
;