1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/listctrl.cpp
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"
32 #if wxUSE_LISTCTRL && defined(__WIN95__)
38 #include "wx/settings.h"
41 #include "wx/textctrl.h"
42 #include "wx/imaglist.h"
43 #include "wx/listctrl.h"
44 #include "wx/dcclient.h"
46 #include "wx/msw/private.h"
48 #if ((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
49 #include "wx/msw/gnuwin32/extra.h"
54 #include "wx/msw/missing.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // convert our state and mask flags to LV_ITEM constants
61 static void wxConvertToMSWFlags(long state
, long mask
, LV_ITEM
& lvItem
);
63 // convert wxListItem to LV_ITEM
64 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
65 const wxListItem
& info
, LV_ITEM
& lvItem
);
67 // convert LV_ITEM to wxListItem
68 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
70 /* const */ LV_ITEM
& lvItem
);
72 // convert our wxListItem to LV_COLUMN
73 static void wxConvertToMSWListCol(int col
, const wxListItem
& item
,
76 // ----------------------------------------------------------------------------
77 // private helper classes
78 // ----------------------------------------------------------------------------
80 // We have to handle both fooW and fooA notifications in several cases
81 // because of broken commctl.dll and/or unicows.dll. This class is used to
82 // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
83 // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
84 // by wxConvertToMSWListItem().
88 ~wxLV_ITEM() { delete m_buf
; }
89 operator LV_ITEM
&() const { return *m_item
; }
92 wxLV_ITEM(LV_ITEMW
&item
) : m_buf(NULL
), m_item(&item
) {}
93 wxLV_ITEM(LV_ITEMA
&item
)
95 m_item
= new LV_ITEM((LV_ITEM
&)item
);
96 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
98 m_buf
= new wxMB2WXbuf(wxConvLocal
.cMB2WX(item
.pszText
));
99 m_item
->pszText
= (wxChar
*)m_buf
->data();
108 wxLV_ITEM(LV_ITEMW
&item
)
110 m_item
= new LV_ITEM((LV_ITEM
&)item
);
111 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
113 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX(item
.pszText
));
114 m_item
->pszText
= (wxChar
*)m_buf
->data();
119 wxLV_ITEM(LV_ITEMA
&item
) : m_buf(NULL
), m_item(&item
) {}
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
133 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
134 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
135 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
136 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
137 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
138 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
139 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
140 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
141 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
142 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
143 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
144 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
145 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
146 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
147 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
148 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
149 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
150 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
151 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
152 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
154 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
155 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
156 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
158 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
160 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
161 EVT_PAINT(wxListCtrl::OnPaint
)
164 // ============================================================================
166 // ============================================================================
168 // ----------------------------------------------------------------------------
169 // wxListCtrl construction
170 // ----------------------------------------------------------------------------
172 void wxListCtrl::Init()
174 m_imageListNormal
= NULL
;
175 m_imageListSmall
= NULL
;
176 m_imageListState
= NULL
;
177 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
181 m_hasAnyAttr
= FALSE
;
184 bool wxListCtrl::Create(wxWindow
*parent
,
189 const wxValidator
& validator
,
190 const wxString
& name
)
193 SetValidator(validator
);
194 #endif // wxUSE_VALIDATORS
203 m_windowStyle
= style
;
216 m_windowId
= (id
== -1) ? NewControlId() : id
;
218 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
219 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
221 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
222 wstyle
|= WS_CLIPSIBLINGS
;
224 if ( wxStyleHasBorder(m_windowStyle
) )
226 m_baseStyle
= wstyle
;
228 if ( !DoCreateControl(x
, y
, width
, height
) )
232 parent
->AddChild(this);
237 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
239 DWORD wstyle
= m_baseStyle
;
242 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
244 // Even with extended styles, need to combine with WS_BORDER
245 // for them to look right.
249 long oldStyle
= 0; // Dummy
250 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
252 // Create the ListView control.
253 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
258 GetWinHwnd(GetParent()),
265 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
270 // for comctl32.dll v 4.70+ we want to have this attribute because it's
271 // prettier (and also because wxGTK does it like this)
272 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
274 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
275 0, LVS_EX_FULLROWSELECT
);
278 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
279 SetForegroundColour(GetParent()->GetForegroundColour());
286 void wxListCtrl::UpdateStyle()
290 // The new window view style
292 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
293 dwStyleNew
|= m_baseStyle
;
295 // Get the current window style.
296 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
298 // Only set the window style if the view bits have changed.
299 if ( dwStyleOld
!= dwStyleNew
)
301 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
306 void wxListCtrl::FreeAllAttrs(bool dontRecreate
)
310 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
312 delete (wxListItemAttr
*)node
->Data();
318 m_attrs
.Create(wxKEY_INTEGER
, 1000); // just as def ctor
321 m_hasAnyAttr
= FALSE
;
325 wxListCtrl::~wxListCtrl()
327 FreeAllAttrs(TRUE
/* no need to recreate hash any more */);
331 m_textCtrl
->SetHWND(0);
332 m_textCtrl
->UnsubclassWin();
337 if (m_ownsImageListNormal
) delete m_imageListNormal
;
338 if (m_ownsImageListSmall
) delete m_imageListSmall
;
339 if (m_ownsImageListState
) delete m_imageListState
;
342 // ----------------------------------------------------------------------------
343 // set/get/change style
344 // ----------------------------------------------------------------------------
346 // Add or remove a single window style
347 void wxListCtrl::SetSingleStyle(long style
, bool add
)
349 long flag
= GetWindowStyleFlag();
351 // Get rid of conflicting styles
354 if ( style
& wxLC_MASK_TYPE
)
355 flag
= flag
& ~wxLC_MASK_TYPE
;
356 if ( style
& wxLC_MASK_ALIGN
)
357 flag
= flag
& ~wxLC_MASK_ALIGN
;
358 if ( style
& wxLC_MASK_SORT
)
359 flag
= flag
& ~wxLC_MASK_SORT
;
375 m_windowStyle
= flag
;
380 // Set the whole window style
381 void wxListCtrl::SetWindowStyleFlag(long flag
)
383 m_windowStyle
= flag
;
388 // Can be just a single style, or a bitlist
389 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
392 if ( style
& wxLC_ICON
)
394 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
395 oldStyle
-= LVS_SMALLICON
;
396 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
397 oldStyle
-= LVS_REPORT
;
398 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
399 oldStyle
-= LVS_LIST
;
403 if ( style
& wxLC_SMALL_ICON
)
405 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
406 oldStyle
-= LVS_ICON
;
407 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
408 oldStyle
-= LVS_REPORT
;
409 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
410 oldStyle
-= LVS_LIST
;
411 wstyle
|= LVS_SMALLICON
;
414 if ( style
& wxLC_LIST
)
416 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
417 oldStyle
-= LVS_ICON
;
418 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
419 oldStyle
-= LVS_REPORT
;
420 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
421 oldStyle
-= LVS_SMALLICON
;
425 if ( style
& wxLC_REPORT
)
427 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
428 oldStyle
-= LVS_ICON
;
429 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
430 oldStyle
-= LVS_LIST
;
431 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
432 oldStyle
-= LVS_SMALLICON
;
434 wstyle
|= LVS_REPORT
;
437 if ( style
& wxLC_ALIGN_LEFT
)
439 if ( oldStyle
& LVS_ALIGNTOP
)
440 oldStyle
-= LVS_ALIGNTOP
;
441 wstyle
|= LVS_ALIGNLEFT
;
444 if ( style
& wxLC_ALIGN_TOP
)
446 if ( oldStyle
& LVS_ALIGNLEFT
)
447 oldStyle
-= LVS_ALIGNLEFT
;
448 wstyle
|= LVS_ALIGNTOP
;
451 if ( style
& wxLC_AUTOARRANGE
)
452 wstyle
|= LVS_AUTOARRANGE
;
454 if ( style
& wxLC_NO_SORT_HEADER
)
455 wstyle
|= LVS_NOSORTHEADER
;
457 if ( style
& wxLC_NO_HEADER
)
458 wstyle
|= LVS_NOCOLUMNHEADER
;
460 if ( style
& wxLC_EDIT_LABELS
)
461 wstyle
|= LVS_EDITLABELS
;
463 if ( style
& wxLC_SINGLE_SEL
)
464 wstyle
|= LVS_SINGLESEL
;
466 if ( style
& wxLC_SORT_ASCENDING
)
468 if ( oldStyle
& LVS_SORTDESCENDING
)
469 oldStyle
-= LVS_SORTDESCENDING
;
470 wstyle
|= LVS_SORTASCENDING
;
473 if ( style
& wxLC_SORT_DESCENDING
)
475 if ( oldStyle
& LVS_SORTASCENDING
)
476 oldStyle
-= LVS_SORTASCENDING
;
477 wstyle
|= LVS_SORTDESCENDING
;
480 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
481 if ( style
& wxLC_VIRTUAL
)
483 int ver
= wxTheApp
->GetComCtl32Version();
486 wxLogWarning(_("Please install a newer version of comctl32.dll\n(at least version 4.70 is required but you have %d.%02d)\nor this program won't operate correctly."),
487 ver
/ 100, ver
% 100);
490 wstyle
|= LVS_OWNERDATA
;
497 // ----------------------------------------------------------------------------
499 // ----------------------------------------------------------------------------
501 // Sets the foreground, i.e. text, colour
502 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
504 if ( !wxWindow::SetForegroundColour(col
) )
507 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
512 // Sets the background colour
513 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
515 if ( !wxWindow::SetBackgroundColour(col
) )
518 // we set the same colour for both the "empty" background and the items
520 COLORREF color
= wxColourToRGB(col
);
521 ListView_SetBkColor(GetHwnd(), color
);
522 ListView_SetTextBkColor(GetHwnd(), color
);
527 // Gets information about this column
528 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
533 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
535 lvCol
.mask
|= LVCF_TEXT
;
536 lvCol
.pszText
= new wxChar
[513];
537 lvCol
.cchTextMax
= 512;
540 bool success
= ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0;
542 // item.m_subItem = lvCol.iSubItem;
543 item
.m_width
= lvCol
.cx
;
545 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
547 item
.m_text
= lvCol
.pszText
;
548 delete[] lvCol
.pszText
;
551 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
553 if (lvCol
.fmt
== LVCFMT_LEFT
)
554 item
.m_format
= wxLIST_FORMAT_LEFT
;
555 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
556 item
.m_format
= wxLIST_FORMAT_RIGHT
;
557 else if (lvCol
.fmt
== LVCFMT_CENTER
)
558 item
.m_format
= wxLIST_FORMAT_CENTRE
;
564 // Sets information about this column
565 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
568 wxConvertToMSWListCol(col
, item
, lvCol
);
570 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
573 // Gets the column width
574 int wxListCtrl::GetColumnWidth(int col
) const
576 return ListView_GetColumnWidth(GetHwnd(), col
);
579 // Sets the column width
580 bool wxListCtrl::SetColumnWidth(int col
, int width
)
583 if ( m_windowStyle
& wxLC_LIST
)
587 if ( width2
== wxLIST_AUTOSIZE
)
588 width2
= LVSCW_AUTOSIZE
;
589 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
590 width2
= LVSCW_AUTOSIZE_USEHEADER
;
592 return ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0;
595 // Gets the number of items that can fit vertically in the
596 // visible area of the list control (list or report view)
597 // or the total number of items in the list control (icon
598 // or small icon view)
599 int wxListCtrl::GetCountPerPage() const
601 return ListView_GetCountPerPage(GetHwnd());
604 // Gets the edit control for editing labels.
605 wxTextCtrl
* wxListCtrl::GetEditControl() const
610 // Gets information about the item
611 bool wxListCtrl::GetItem(wxListItem
& info
) const
614 wxZeroMemory(lvItem
);
616 lvItem
.iItem
= info
.m_itemId
;
617 lvItem
.iSubItem
= info
.m_col
;
619 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
621 lvItem
.mask
|= LVIF_TEXT
;
622 lvItem
.pszText
= new wxChar
[513];
623 lvItem
.cchTextMax
= 512;
627 lvItem
.pszText
= NULL
;
630 if (info
.m_mask
& wxLIST_MASK_DATA
)
631 lvItem
.mask
|= LVIF_PARAM
;
633 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
634 lvItem
.mask
|= LVIF_IMAGE
;
636 if ( info
.m_mask
& wxLIST_MASK_STATE
)
638 lvItem
.mask
|= LVIF_STATE
;
639 // the other bits are hardly interesting anyhow
640 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
643 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
646 wxLogError(_("Couldn't retrieve information about list control item %d."),
651 // give NULL as hwnd as we already have everything we need
652 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
656 delete[] lvItem
.pszText
;
661 // Sets information about the item
662 bool wxListCtrl::SetItem(wxListItem
& info
)
665 wxConvertToMSWListItem(this, info
, item
);
667 // we could be changing only the attribute in which case we don't need to
668 // call ListView_SetItem() at all
672 if ( !ListView_SetItem(GetHwnd(), &item
) )
674 wxLogDebug(_T("ListView_SetItem() failed"));
680 // we need to update the item immediately to show the new image
681 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
683 // check whether it has any custom attributes
684 if ( info
.HasAttributes() )
686 wxListItemAttr
*attr
= (wxListItemAttr
*)m_attrs
.Get(item
.iItem
);
689 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
691 *attr
= *info
.GetAttributes();
695 // if the colour has changed, we must redraw the item
701 // we need this to make the change visible right now
702 RefreshItem(item
.iItem
);
708 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
712 info
.m_mask
= wxLIST_MASK_TEXT
;
713 info
.m_itemId
= index
;
717 info
.m_image
= imageId
;
718 info
.m_mask
|= wxLIST_MASK_IMAGE
;
720 return SetItem(info
);
724 // Gets the item state
725 int wxListCtrl::GetItemState(long item
, long stateMask
) const
729 info
.m_mask
= wxLIST_MASK_STATE
;
730 info
.m_stateMask
= stateMask
;
731 info
.m_itemId
= item
;
739 // Sets the item state
740 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
742 // NB: don't use SetItem() here as it doesn't work with the virtual list
745 wxZeroMemory(lvItem
);
747 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
749 // for the virtual list controls we need to refresh the previously focused
750 // item manually when changing focus without changing selection
751 // programmatically because otherwise it keeps its focus rectangle until
752 // next repaint (yet another comctl32 bug)
755 (stateMask
& wxLIST_STATE_FOCUSED
) &&
756 (state
& wxLIST_STATE_FOCUSED
) )
758 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
765 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
766 (WPARAM
)item
, (LPARAM
)&lvItem
) )
768 wxLogLastError(_T("ListView_SetItemState"));
773 if ( focusOld
!= -1 )
775 // no need to refresh the item if it was previously selected, it would
776 // only result in annoying flicker
777 if ( !(GetItemState(focusOld
,
778 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
780 RefreshItem(focusOld
);
787 // Sets the item image
788 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
792 info
.m_mask
= wxLIST_MASK_IMAGE
;
793 info
.m_image
= image
;
794 info
.m_itemId
= item
;
796 return SetItem(info
);
799 // Gets the item text
800 wxString
wxListCtrl::GetItemText(long item
) const
804 info
.m_mask
= wxLIST_MASK_TEXT
;
805 info
.m_itemId
= item
;
812 // Sets the item text
813 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
817 info
.m_mask
= wxLIST_MASK_TEXT
;
818 info
.m_itemId
= item
;
824 // Gets the item data
825 long wxListCtrl::GetItemData(long item
) const
829 info
.m_mask
= wxLIST_MASK_DATA
;
830 info
.m_itemId
= item
;
837 // Sets the item data
838 bool wxListCtrl::SetItemData(long item
, long data
)
842 info
.m_mask
= wxLIST_MASK_DATA
;
843 info
.m_itemId
= item
;
846 return SetItem(info
);
849 // Gets the item rectangle
850 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
855 if ( code
== wxLIST_RECT_BOUNDS
)
856 codeWin
= LVIR_BOUNDS
;
857 else if ( code
== wxLIST_RECT_ICON
)
859 else if ( code
== wxLIST_RECT_LABEL
)
860 codeWin
= LVIR_LABEL
;
863 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
865 codeWin
= LVIR_BOUNDS
;
869 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
) != 0;
871 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
874 rect
.x
= rectWin
.left
;
875 rect
.y
= rectWin
.top
;
876 rect
.width
= rectWin
.right
- rectWin
.left
;
877 rect
.height
= rectWin
.bottom
- rectWin
.top
;
882 // Gets the item position
883 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
887 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
889 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
893 // Sets the item position.
894 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
896 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
899 // Gets the number of items in the list control
900 int wxListCtrl::GetItemCount() const
902 return ListView_GetItemCount(GetHwnd());
905 // Retrieves the spacing between icons in pixels.
906 // If small is TRUE, gets the spacing for the small icon
907 // view, otherwise the large icon view.
908 int wxListCtrl::GetItemSpacing(bool isSmall
) const
910 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
913 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
916 info
.m_itemId
= item
;
917 info
.SetTextColour( col
);
921 wxColour
wxListCtrl::GetItemTextColour( long item
) const
924 info
.m_itemId
= item
;
926 return info
.GetTextColour();
929 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
932 info
.m_itemId
= item
;
933 info
.SetBackgroundColour( col
);
937 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
940 info
.m_itemId
= item
;
942 return info
.GetBackgroundColour();
945 // Gets the number of selected items in the list control
946 int wxListCtrl::GetSelectedItemCount() const
948 return ListView_GetSelectedCount(GetHwnd());
951 // Gets the text colour of the listview
952 wxColour
wxListCtrl::GetTextColour() const
954 COLORREF ref
= ListView_GetTextColor(GetHwnd());
955 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
959 // Sets the text colour of the listview
960 void wxListCtrl::SetTextColour(const wxColour
& col
)
962 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
965 // Gets the index of the topmost visible item when in
966 // list or report view
967 long wxListCtrl::GetTopItem() const
969 return (long) ListView_GetTopIndex(GetHwnd());
972 // Searches for an item, starting from 'item'.
973 // 'geometry' is one of
974 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
975 // 'state' is a state bit flag, one or more of
976 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
977 // item can be -1 to find the first item that matches the
979 // Returns the item or -1 if unsuccessful.
980 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
984 if ( geom
== wxLIST_NEXT_ABOVE
)
986 if ( geom
== wxLIST_NEXT_ALL
)
988 if ( geom
== wxLIST_NEXT_BELOW
)
990 if ( geom
== wxLIST_NEXT_LEFT
)
991 flags
|= LVNI_TOLEFT
;
992 if ( geom
== wxLIST_NEXT_RIGHT
)
993 flags
|= LVNI_TORIGHT
;
995 if ( state
& wxLIST_STATE_CUT
)
997 if ( state
& wxLIST_STATE_DROPHILITED
)
998 flags
|= LVNI_DROPHILITED
;
999 if ( state
& wxLIST_STATE_FOCUSED
)
1000 flags
|= LVNI_FOCUSED
;
1001 if ( state
& wxLIST_STATE_SELECTED
)
1002 flags
|= LVNI_SELECTED
;
1004 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1008 wxImageList
*wxListCtrl::GetImageList(int which
) const
1010 if ( which
== wxIMAGE_LIST_NORMAL
)
1012 return m_imageListNormal
;
1014 else if ( which
== wxIMAGE_LIST_SMALL
)
1016 return m_imageListSmall
;
1018 else if ( which
== wxIMAGE_LIST_STATE
)
1020 return m_imageListState
;
1025 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1028 if ( which
== wxIMAGE_LIST_NORMAL
)
1030 flags
= LVSIL_NORMAL
;
1031 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1032 m_imageListNormal
= imageList
;
1033 m_ownsImageListNormal
= FALSE
;
1035 else if ( which
== wxIMAGE_LIST_SMALL
)
1037 flags
= LVSIL_SMALL
;
1038 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1039 m_imageListSmall
= imageList
;
1040 m_ownsImageListSmall
= FALSE
;
1042 else if ( which
== wxIMAGE_LIST_STATE
)
1044 flags
= LVSIL_STATE
;
1045 if (m_ownsImageListState
) delete m_imageListState
;
1046 m_imageListState
= imageList
;
1047 m_ownsImageListState
= FALSE
;
1049 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1052 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1054 SetImageList(imageList
, which
);
1055 if ( which
== wxIMAGE_LIST_NORMAL
)
1056 m_ownsImageListNormal
= TRUE
;
1057 else if ( which
== wxIMAGE_LIST_SMALL
)
1058 m_ownsImageListSmall
= TRUE
;
1059 else if ( which
== wxIMAGE_LIST_STATE
)
1060 m_ownsImageListState
= TRUE
;
1063 // ----------------------------------------------------------------------------
1065 // ----------------------------------------------------------------------------
1067 // Arranges the items
1068 bool wxListCtrl::Arrange(int flag
)
1071 if ( flag
== wxLIST_ALIGN_LEFT
)
1072 code
= LVA_ALIGNLEFT
;
1073 else if ( flag
== wxLIST_ALIGN_TOP
)
1074 code
= LVA_ALIGNTOP
;
1075 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1077 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1078 code
= LVA_SNAPTOGRID
;
1080 return (ListView_Arrange(GetHwnd(), code
) != 0);
1084 bool wxListCtrl::DeleteItem(long item
)
1086 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1088 wxLogLastError(_T("ListView_DeleteItem"));
1092 // the virtual list control doesn't refresh itself correctly, help it
1095 // we need to refresh all the lines below the one which was deleted
1097 if ( item
> 0 && GetItemCount() )
1099 GetItemRect(item
- 1, rectItem
);
1104 rectItem
.height
= 0;
1107 wxRect rectWin
= GetRect();
1108 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1109 rectWin
.y
= rectItem
.GetBottom();
1111 RefreshRect(rectWin
);
1117 // Deletes all items
1118 bool wxListCtrl::DeleteAllItems()
1120 return ListView_DeleteAllItems(GetHwnd()) != 0;
1123 // Deletes all items
1124 bool wxListCtrl::DeleteAllColumns()
1126 while ( m_colCount
> 0 )
1128 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1130 wxLogLastError(wxT("ListView_DeleteColumn"));
1138 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1144 bool wxListCtrl::DeleteColumn(int col
)
1146 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1148 if ( success
&& (m_colCount
> 0) )
1153 // Clears items, and columns if there are any.
1154 void wxListCtrl::ClearAll()
1157 if ( m_colCount
> 0 )
1161 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1163 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1165 // VS: ListView_EditLabel requires that the list has focus.
1167 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
1171 m_textCtrl
->SetHWND(0);
1172 m_textCtrl
->UnsubclassWin();
1177 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1178 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1179 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1184 // End label editing, optionally cancelling the edit
1185 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1187 wxFAIL_MSG( _T("not implemented") );
1192 // Ensures this item is visible
1193 bool wxListCtrl::EnsureVisible(long item
)
1195 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0;
1198 // Find an item whose label matches this string, starting from the item after 'start'
1199 // or the beginning if 'start' is -1.
1200 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1202 LV_FINDINFO findInfo
;
1204 findInfo
.flags
= LVFI_STRING
;
1206 findInfo
.flags
|= LVFI_PARTIAL
;
1209 // ListView_FindItem() excludes the first item from search and to look
1210 // through all the items you need to start from -1 which is unnatural and
1211 // inconsistent with the generic version - so we adjust the index
1214 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1217 // Find an item whose data matches this data, starting from the item after 'start'
1218 // or the beginning if 'start' is -1.
1219 long wxListCtrl::FindItem(long start
, long data
)
1221 LV_FINDINFO findInfo
;
1223 findInfo
.flags
= LVFI_PARAM
;
1224 findInfo
.lParam
= data
;
1226 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1229 // Find an item nearest this position in the specified direction, starting from
1230 // the item after 'start' or the beginning if 'start' is -1.
1231 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1233 LV_FINDINFO findInfo
;
1235 findInfo
.flags
= LVFI_NEARESTXY
;
1236 findInfo
.pt
.x
= pt
.x
;
1237 findInfo
.pt
.y
= pt
.y
;
1238 findInfo
.vkDirection
= VK_RIGHT
;
1240 if ( direction
== wxLIST_FIND_UP
)
1241 findInfo
.vkDirection
= VK_UP
;
1242 else if ( direction
== wxLIST_FIND_DOWN
)
1243 findInfo
.vkDirection
= VK_DOWN
;
1244 else if ( direction
== wxLIST_FIND_LEFT
)
1245 findInfo
.vkDirection
= VK_LEFT
;
1246 else if ( direction
== wxLIST_FIND_RIGHT
)
1247 findInfo
.vkDirection
= VK_RIGHT
;
1249 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1252 // Determines which item (if any) is at the specified point,
1253 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1254 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1256 LV_HITTESTINFO hitTestInfo
;
1257 hitTestInfo
.pt
.x
= (int) point
.x
;
1258 hitTestInfo
.pt
.y
= (int) point
.y
;
1260 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1263 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1264 flags
|= wxLIST_HITTEST_ABOVE
;
1265 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1266 flags
|= wxLIST_HITTEST_BELOW
;
1267 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1268 flags
|= wxLIST_HITTEST_NOWHERE
;
1269 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1270 flags
|= wxLIST_HITTEST_ONITEMICON
;
1271 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1272 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1273 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1274 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1275 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1276 flags
|= wxLIST_HITTEST_TOLEFT
;
1277 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1278 flags
|= wxLIST_HITTEST_TORIGHT
;
1280 return (long) hitTestInfo
.iItem
;
1283 // Inserts an item, returning the index of the new item if successful,
1285 long wxListCtrl::InsertItem(wxListItem
& info
)
1287 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1290 wxConvertToMSWListItem(this, info
, item
);
1292 // check whether it has any custom attributes
1293 if ( info
.HasAttributes() )
1296 wxListItemAttr
*attr
;
1297 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
1301 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1303 else *attr
= *info
.GetAttributes();
1305 m_hasAnyAttr
= TRUE
;
1308 return (long) ListView_InsertItem(GetHwnd(), & item
);
1311 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1314 info
.m_text
= label
;
1315 info
.m_mask
= wxLIST_MASK_TEXT
;
1316 info
.m_itemId
= index
;
1317 return InsertItem(info
);
1320 // Inserts an image item
1321 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1324 info
.m_image
= imageIndex
;
1325 info
.m_mask
= wxLIST_MASK_IMAGE
;
1326 info
.m_itemId
= index
;
1327 return InsertItem(info
);
1330 // Inserts an image/string item
1331 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1334 info
.m_image
= imageIndex
;
1335 info
.m_text
= label
;
1336 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1337 info
.m_itemId
= index
;
1338 return InsertItem(info
);
1341 // For list view mode (only), inserts a column.
1342 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1345 wxConvertToMSWListCol(col
, item
, lvCol
);
1347 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1349 // always give some width to the new column: this one is compatible
1350 // with the generic version
1351 lvCol
.mask
|= LVCF_WIDTH
;
1355 // when we insert a column which can contain an image, we must specify this
1356 // flag right now as doing it later in SetColumn() has no effect
1358 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1359 // way to dynamically set/clear the bitmap as the column without a bitmap
1360 // on the left looks ugly (there is a hole)
1362 // unfortunately with my version of comctl32.dll (5.80), the left column
1363 // image is always on the left and it seems that it's a "feature" - I
1364 // didn't find any way to work around it in any case
1365 if ( lvCol
.mask
& LVCF_IMAGE
)
1367 lvCol
.mask
|= LVCF_FMT
;
1368 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
;
1371 bool success
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
) != -1;
1378 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1385 long wxListCtrl::InsertColumn(long col
,
1386 const wxString
& heading
,
1391 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1392 item
.m_text
= heading
;
1395 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1396 item
.m_width
= width
;
1398 item
.m_format
= format
;
1400 return InsertColumn(col
, item
);
1403 // Scrolls the list control. If in icon, small icon or report view mode,
1404 // x specifies the number of pixels to scroll. If in list view mode, x
1405 // specifies the number of columns to scroll.
1406 // If in icon, small icon or list view mode, y specifies the number of pixels
1407 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1408 bool wxListCtrl::ScrollList(int dx
, int dy
)
1410 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1415 // fn is a function which takes 3 long arguments: item1, item2, data.
1416 // item1 is the long data associated with a first item (NOT the index).
1417 // item2 is the long data associated with a second item (NOT the index).
1418 // data is the same value as passed to SortItems.
1419 // The return value is a negative number if the first item should precede the second
1420 // item, a positive number of the second item should precede the first,
1421 // or zero if the two items are equivalent.
1423 // data is arbitrary data to be passed to the sort function.
1425 // FIXME: this is horrible and MT-unsafe and everything else but I don't have
1426 // time for anything better right now (VZ)
1427 static long gs_sortData
= 0;
1428 static wxListCtrl
*gs_sortCtrl
= NULL
;
1429 static wxListCtrlCompare gs_sortFunction
= NULL
;
1431 int wxCMPFUNC_CONV
wxListCtrlCompareFn(const void *arg1
, const void *arg2
)
1433 int n1
= *(const int *)arg1
,
1434 n2
= *(const int *)arg2
;
1436 return gs_sortFunction(gs_sortCtrl
->GetItemData(n1
),
1437 gs_sortCtrl
->GetItemData(n2
),
1441 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1443 // sort the attributes too
1447 count
= GetItemCount();
1448 int *aItems
= new int[count
];
1449 for ( n
= 0; n
< count
; n
++ )
1456 gs_sortFunction
= fn
;
1458 qsort(aItems
, count
, sizeof(int), wxListCtrlCompareFn
);
1462 gs_sortFunction
= NULL
;
1464 wxHashTable
attrsNew(wxKEY_INTEGER
, 1000);
1465 for ( n
= 0; n
< count
; n
++ )
1467 wxObject
*attr
= m_attrs
.Delete(aItems
[n
]);
1470 attrsNew
.Put(n
, attr
);
1480 if ( !ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
)fn
, data
) )
1482 wxLogDebug(_T("ListView_SortItems() failed"));
1492 // ----------------------------------------------------------------------------
1493 // message processing
1494 // ----------------------------------------------------------------------------
1496 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1498 if (cmd
== EN_UPDATE
)
1500 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1501 event
.SetEventObject( this );
1502 ProcessCommand(event
);
1505 else if (cmd
== EN_KILLFOCUS
)
1507 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1508 event
.SetEventObject( this );
1509 ProcessCommand(event
);
1516 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1518 // prepare the event
1519 // -----------------
1521 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1522 event
.SetEventObject(this);
1524 wxEventType eventType
= wxEVT_NULL
;
1526 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1528 // if your compiler is as broken as this, you should really change it: this
1529 // code is needed for normal operation! #ifdef below is only useful for
1530 // automatic rebuilds which are done with a very old compiler version
1531 #ifdef HDN_BEGINTRACKA
1533 // check for messages from the header (in report view)
1534 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1536 // is it a message from the header?
1537 if ( nmhdr
->hwndFrom
== hwndHdr
)
1539 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1541 event
.m_itemIndex
= -1;
1543 switch ( nmhdr
->code
)
1545 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1546 // TRACK messages even to ANSI programs: on my system I get
1547 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1549 // work around is to simply catch both versions and hope that it
1550 // works (why should this message exist in ANSI and Unicode is
1551 // beyond me as it doesn't deal with strings at all...)
1552 case HDN_BEGINTRACKA
:
1553 case HDN_BEGINTRACKW
:
1554 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1559 if ( eventType
== wxEVT_NULL
)
1560 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1565 if ( eventType
== wxEVT_NULL
)
1566 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1567 event
.m_col
= nmHDR
->iItem
;
1572 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1575 // find the column clicked: we have to search for it
1576 // ourselves as the notification message doesn't provide
1579 // where did the click occur?
1581 if ( !::GetCursorPos(&ptClick
) )
1583 wxLogLastError(_T("GetCursorPos"));
1586 if ( !::ScreenToClient(hwndHdr
, &ptClick
) )
1588 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1591 event
.m_pointDrag
.x
= ptClick
.x
;
1592 event
.m_pointDrag
.y
= ptClick
.y
;
1594 int colCount
= Header_GetItemCount(hwndHdr
);
1597 for ( int col
= 0; col
< colCount
; col
++ )
1599 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1601 if ( ::PtInRect(&rect
, ptClick
) )
1612 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1616 #endif // defined(HDN_BEGINTRACKA)
1617 if ( nmhdr
->hwndFrom
== GetHwnd() )
1619 // almost all messages use NM_LISTVIEW
1620 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1622 // this is true for almost all events
1623 event
.m_item
.m_data
= nmLV
->lParam
;
1625 switch ( nmhdr
->code
)
1627 case LVN_BEGINRDRAG
:
1628 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1632 if ( eventType
== wxEVT_NULL
)
1634 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1637 event
.m_itemIndex
= nmLV
->iItem
;
1638 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1639 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1642 // NB: we have to handle both *A and *W versions here because some
1643 // versions of comctl32.dll send ANSI message to an Unicode app
1644 case LVN_BEGINLABELEDITA
:
1646 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1647 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1648 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1649 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1652 case LVN_BEGINLABELEDITW
:
1654 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1655 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1656 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1657 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1661 case LVN_ENDLABELEDITA
:
1663 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1664 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1665 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1666 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1667 ((LV_ITEM
)item
).iItem
== -1 )
1670 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1673 case LVN_ENDLABELEDITW
:
1675 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1676 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1677 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1678 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1679 ((LV_ITEM
)item
).iItem
== -1 )
1682 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1686 case LVN_COLUMNCLICK
:
1687 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1688 event
.m_itemIndex
= -1;
1689 event
.m_col
= nmLV
->iSubItem
;
1692 case LVN_DELETEALLITEMS
:
1693 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1694 event
.m_itemIndex
= -1;
1700 case LVN_DELETEITEM
:
1701 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1702 event
.m_itemIndex
= nmLV
->iItem
;
1706 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1710 case LVN_SETDISPINFO
:
1712 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1713 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1714 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
1718 case LVN_INSERTITEM
:
1719 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1720 event
.m_itemIndex
= nmLV
->iItem
;
1723 case LVN_ITEMCHANGED
:
1724 // we translate this catch all message into more interesting
1725 // (and more easy to process) wxWindows events
1727 // first of all, we deal with the state change events only
1728 if ( nmLV
->uChanged
& LVIF_STATE
)
1730 // temp vars for readability
1731 const UINT stOld
= nmLV
->uOldState
;
1732 const UINT stNew
= nmLV
->uNewState
;
1734 // has the focus changed?
1735 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
1737 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
1738 event
.m_itemIndex
= nmLV
->iItem
;
1741 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
1743 if ( eventType
!= wxEVT_NULL
)
1745 // focus and selection have both changed: send the
1746 // focus event from here and the selection one
1748 event
.SetEventType(eventType
);
1749 (void)GetEventHandler()->ProcessEvent(event
);
1751 else // no focus event to send
1753 // then need to set m_itemIndex as it wasn't done
1755 event
.m_itemIndex
= nmLV
->iItem
;
1758 eventType
= stNew
& LVIS_SELECTED
1759 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1760 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1764 if ( eventType
== wxEVT_NULL
)
1766 // not an interesting event for us
1774 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1775 WORD wVKey
= info
->wVKey
;
1777 // get the current selection
1778 long lItem
= GetNextItem(-1,
1780 wxLIST_STATE_SELECTED
);
1782 // <Enter> or <Space> activate the selected item if any (but
1783 // not with Shift and/or Ctrl as then they have a predefined
1784 // meaning for the list view)
1786 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
1787 !(wxIsShiftDown() || wxIsCtrlDown()) )
1789 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1793 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1795 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1796 // value which should be used as is
1797 int code
= wxCharCodeMSWToWX(wVKey
);
1798 event
.m_code
= code
? code
: wVKey
;
1802 event
.m_item
.m_itemId
= lItem
;
1806 // fill the other fields too
1807 event
.m_item
.m_text
= GetItemText(lItem
);
1808 event
.m_item
.m_data
= GetItemData(lItem
);
1814 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1816 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1821 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1822 // if it happened on an item (and not on empty place)
1823 if ( nmLV
->iItem
== -1 )
1829 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1830 event
.m_itemIndex
= nmLV
->iItem
;
1831 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1832 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1836 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1837 // don't do anything else
1838 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1843 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1844 LV_HITTESTINFO lvhti
;
1845 wxZeroMemory(lvhti
);
1847 ::GetCursorPos(&(lvhti
.pt
));
1848 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1849 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1851 if ( lvhti
.flags
& LVHT_ONITEM
)
1853 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1854 event
.m_itemIndex
= lvhti
.iItem
;
1855 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
1856 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
1861 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1862 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
1864 *result
= OnCustomDraw(lParam
);
1867 #endif // _WIN32_IE >= 0x300
1869 case LVN_ODCACHEHINT
:
1871 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
1873 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
1875 // we get some really stupid cache hints like ones for items in
1876 // range 0..0 for an empty control or, after deleting an item,
1877 // for items in invalid range - filter this garbage out
1878 if ( cacheHint
->iFrom
< cacheHint
->iTo
)
1880 event
.m_oldItemIndex
= cacheHint
->iFrom
;
1882 long iMax
= GetItemCount();
1883 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
1893 case LVN_GETDISPINFO
:
1896 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1898 LV_ITEM
& lvi
= info
->item
;
1899 long item
= lvi
.iItem
;
1901 if ( lvi
.mask
& LVIF_TEXT
)
1903 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
1904 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
1907 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1908 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
1909 if ( lvi
.mask
& LVIF_IMAGE
)
1911 lvi
.iImage
= OnGetItemImage(item
);
1915 // a little dose of healthy paranoia: as we never use
1916 // LVM_SETCALLBACKMASK we're not supposed to get these ones
1917 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
1918 _T("we don't support state callbacks yet!") );
1925 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1930 // where did this one come from?
1934 // process the event
1935 // -----------------
1937 event
.SetEventType(eventType
);
1939 if ( !GetEventHandler()->ProcessEvent(event
) )
1945 switch ( nmhdr
->code
)
1947 case LVN_DELETEALLITEMS
:
1948 // always return TRUE to suppress all additional LVN_DELETEITEM
1949 // notifications - this makes deleting all items from a list ctrl
1955 case LVN_ENDLABELEDITA
:
1956 case LVN_ENDLABELEDITW
:
1957 // logic here is inversed compared to all the other messages
1958 *result
= event
.IsAllowed();
1963 *result
= !event
.IsAllowed();
1968 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1970 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
1972 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1973 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1974 switch ( nmcd
.dwDrawStage
)
1977 // if we've got any items with non standard attributes,
1978 // notify us before painting each item
1980 // for virtual controls, always suppose that we have attributes as
1981 // there is no way to check for this
1982 return IsVirtual() || m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1985 case CDDS_ITEMPREPAINT
:
1987 size_t item
= (size_t)nmcd
.dwItemSpec
;
1988 if ( item
>= (size_t)GetItemCount() )
1990 // we get this message with item == 0 for an empty control,
1991 // we must ignore it as calling OnGetItemAttr() would be
1993 return CDRF_DODEFAULT
;
1996 wxListItemAttr
*attr
=
1997 IsVirtual() ? OnGetItemAttr(item
)
1998 : (wxListItemAttr
*)m_attrs
.Get(item
);
2002 // nothing to do for this item
2003 return CDRF_DODEFAULT
;
2007 wxColour colText
, colBack
;
2008 if ( attr
->HasFont() )
2010 wxFont font
= attr
->GetFont();
2011 hFont
= (HFONT
)font
.GetResourceHandle();
2018 if ( attr
->HasTextColour() )
2020 colText
= attr
->GetTextColour();
2024 colText
= GetTextColour();
2027 if ( attr
->HasBackgroundColour() )
2029 colBack
= attr
->GetBackgroundColour();
2033 colBack
= GetBackgroundColour();
2036 lplvcd
->clrText
= wxColourToRGB(colText
);
2037 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
2039 // note that if we wanted to set colours for
2040 // individual columns (subitems), we would have
2041 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2044 ::SelectObject(nmcd
.hdc
, hFont
);
2046 return CDRF_NEWFONT
;
2049 // fall through to return CDRF_DODEFAULT
2052 return CDRF_DODEFAULT
;
2056 #endif // NM_CUSTOMDRAW supported
2058 // Necessary for drawing hrules and vrules, if specified
2059 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2063 wxControl::OnPaint(event
);
2065 // Reset the device origin since it may have been set
2066 dc
.SetDeviceOrigin(0, 0);
2068 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
2069 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
2071 if (!drawHRules
&& !drawVRules
)
2073 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
2076 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2078 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2080 wxSize clientSize
= GetClientSize();
2084 int itemCount
= GetItemCount();
2088 long top
= GetTopItem();
2089 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2091 if (GetItemRect(i
, itemRect
))
2093 cy
= itemRect
.GetTop();
2094 if (i
!= 0) // Don't draw the first one
2096 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2099 if (i
== itemCount
- 1)
2101 cy
= itemRect
.GetBottom();
2102 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2108 if (drawVRules
&& (i
> -1))
2110 wxRect firstItemRect
;
2111 GetItemRect(0, firstItemRect
);
2113 if (GetItemRect(i
, itemRect
))
2116 int x
= itemRect
.GetX();
2117 for (col
= 0; col
< GetColumnCount(); col
++)
2119 int colWidth
= GetColumnWidth(col
);
2121 dc
.DrawLine(x
, firstItemRect
.GetY() - 2, x
, itemRect
.GetBottom());
2127 // ----------------------------------------------------------------------------
2128 // virtual list controls
2129 // ----------------------------------------------------------------------------
2131 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2133 // this is a pure virtual function, in fact - which is not really pure
2134 // because the controls which are not virtual don't need to implement it
2135 wxFAIL_MSG( _T("not supposed to be called") );
2137 return wxEmptyString
;
2140 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2143 wxFAIL_MSG( _T("not supposed to be called") );
2148 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2150 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2151 _T("invalid item index in OnGetItemAttr()") );
2153 // no attributes by default
2157 void wxListCtrl::SetItemCount(long count
)
2159 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2161 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
, 0) )
2163 wxLogLastError(_T("ListView_SetItemCount"));
2167 void wxListCtrl::RefreshItem(long item
)
2169 // strangely enough, ListView_Update() results in much more flicker here
2170 // than a dumb Refresh() -- why?
2172 if ( !ListView_Update(GetHwnd(), item
) )
2174 wxLogLastError(_T("ListView_Update"));
2178 GetItemRect(item
, rect
);
2183 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2185 wxRect rect1
, rect2
;
2186 GetItemRect(itemFrom
, rect1
);
2187 GetItemRect(itemTo
, rect2
);
2189 wxRect rect
= rect1
;
2190 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2195 // ----------------------------------------------------------------------------
2197 // ----------------------------------------------------------------------------
2199 // List item structure
2200 wxListItem::wxListItem()
2210 m_format
= wxLIST_FORMAT_CENTRE
;
2216 void wxListItem::Clear()
2225 m_format
= wxLIST_FORMAT_CENTRE
;
2227 m_text
= wxEmptyString
;
2229 if (m_attr
) delete m_attr
;
2233 void wxListItem::ClearAttributes()
2235 if (m_attr
) delete m_attr
;
2239 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2243 info
.m_data
= lvItem
.lParam
;
2246 info
.m_stateMask
= 0;
2247 info
.m_itemId
= lvItem
.iItem
;
2249 long oldMask
= lvItem
.mask
;
2251 bool needText
= FALSE
;
2252 if (hwndListCtrl
!= 0)
2254 if ( lvItem
.mask
& LVIF_TEXT
)
2261 lvItem
.pszText
= new wxChar
[513];
2262 lvItem
.cchTextMax
= 512;
2264 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2265 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2268 if ( lvItem
.mask
& LVIF_STATE
)
2270 info
.m_mask
|= wxLIST_MASK_STATE
;
2272 if ( lvItem
.stateMask
& LVIS_CUT
)
2274 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2275 if ( lvItem
.state
& LVIS_CUT
)
2276 info
.m_state
|= wxLIST_STATE_CUT
;
2278 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2280 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2281 if ( lvItem
.state
& LVIS_DROPHILITED
)
2282 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2284 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2286 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2287 if ( lvItem
.state
& LVIS_FOCUSED
)
2288 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2290 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2292 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2293 if ( lvItem
.state
& LVIS_SELECTED
)
2294 info
.m_state
|= wxLIST_STATE_SELECTED
;
2298 if ( lvItem
.mask
& LVIF_TEXT
)
2300 info
.m_mask
|= wxLIST_MASK_TEXT
;
2301 info
.m_text
= lvItem
.pszText
;
2303 if ( lvItem
.mask
& LVIF_IMAGE
)
2305 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2306 info
.m_image
= lvItem
.iImage
;
2308 if ( lvItem
.mask
& LVIF_PARAM
)
2309 info
.m_mask
|= wxLIST_MASK_DATA
;
2310 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2311 info
.m_mask
|= wxLIST_SET_ITEM
;
2312 info
.m_col
= lvItem
.iSubItem
;
2317 delete[] lvItem
.pszText
;
2319 lvItem
.mask
= oldMask
;
2322 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2324 if (stateMask
& wxLIST_STATE_CUT
)
2326 lvItem
.stateMask
|= LVIS_CUT
;
2327 if (state
& wxLIST_STATE_CUT
)
2328 lvItem
.state
|= LVIS_CUT
;
2330 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2332 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2333 if (state
& wxLIST_STATE_DROPHILITED
)
2334 lvItem
.state
|= LVIS_DROPHILITED
;
2336 if (stateMask
& wxLIST_STATE_FOCUSED
)
2338 lvItem
.stateMask
|= LVIS_FOCUSED
;
2339 if (state
& wxLIST_STATE_FOCUSED
)
2340 lvItem
.state
|= LVIS_FOCUSED
;
2342 if (stateMask
& wxLIST_STATE_SELECTED
)
2344 lvItem
.stateMask
|= LVIS_SELECTED
;
2345 if (state
& wxLIST_STATE_SELECTED
)
2346 lvItem
.state
|= LVIS_SELECTED
;
2350 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2351 const wxListItem
& info
,
2354 lvItem
.iItem
= (int) info
.m_itemId
;
2356 lvItem
.iImage
= info
.m_image
;
2357 lvItem
.lParam
= info
.m_data
;
2358 lvItem
.stateMask
= 0;
2361 lvItem
.iSubItem
= info
.m_col
;
2363 if (info
.m_mask
& wxLIST_MASK_STATE
)
2365 lvItem
.mask
|= LVIF_STATE
;
2367 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2370 if (info
.m_mask
& wxLIST_MASK_TEXT
)
2372 lvItem
.mask
|= LVIF_TEXT
;
2373 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
2375 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
2379 // pszText is not const, hence the cast
2380 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
2381 if ( lvItem
.pszText
)
2382 lvItem
.cchTextMax
= info
.m_text
.Length();
2384 lvItem
.cchTextMax
= 0;
2387 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
2388 lvItem
.mask
|= LVIF_IMAGE
;
2389 if (info
.m_mask
& wxLIST_MASK_DATA
)
2390 lvItem
.mask
|= LVIF_PARAM
;
2393 static void wxConvertToMSWListCol(int WXUNUSED(col
), const wxListItem
& item
,
2396 wxZeroMemory(lvCol
);
2398 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
2400 lvCol
.mask
|= LVCF_TEXT
;
2401 lvCol
.pszText
= (wxChar
*)item
.m_text
.c_str(); // cast is safe
2404 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
2406 lvCol
.mask
|= LVCF_FMT
;
2408 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
2409 lvCol
.fmt
= LVCFMT_LEFT
;
2410 else if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
2411 lvCol
.fmt
= LVCFMT_RIGHT
;
2412 else if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
2413 lvCol
.fmt
= LVCFMT_CENTER
;
2416 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
2418 lvCol
.mask
|= LVCF_WIDTH
;
2419 if ( item
.m_width
== wxLIST_AUTOSIZE
)
2420 lvCol
.cx
= LVSCW_AUTOSIZE
;
2421 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2422 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
2424 lvCol
.cx
= item
.m_width
;
2427 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2428 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2429 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
2431 if ( wxTheApp
->GetComCtl32Version() >= 470 )
2433 lvCol
.mask
|= LVCF_IMAGE
;
2434 lvCol
.iImage
= item
.m_image
;
2436 //else: it doesn't support item images anyhow
2441 #endif // wxUSE_LISTCTRL