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"
56 (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)
59 #ifndef LVM_SETEXTENDEDLISTVIEWSTYLE
60 #define LVM_SETEXTENDEDLISTVIEWSTYLE (0x1000 + 54)
63 #ifndef LVS_EX_FULLROWSELECT
64 #define LVS_EX_FULLROWSELECT 0x00000020
68 #define LVS_OWNERDATA 0x1000
72 #define LVM_FIRST 0x1000
76 #define HDM_FIRST 0x1200
79 // mingw32/cygwin don't have declarations for comctl32.dll 4.70+ stuff
81 typedef struct tagNMLVCACHEHINT
88 #define NM_CACHEHINT NMLVCACHEHINT
91 #ifndef LVN_ODCACHEHINT
92 #define LVN_ODCACHEHINT (-113)
95 #ifndef ListView_GetHeader
96 #define ListView_GetHeader(w) (HWND)SendMessage((w),LVM_GETHEADER,0,0)
100 #define LVM_GETHEADER (LVM_FIRST+31)
103 #ifndef Header_GetItemRect
104 #define Header_GetItemRect(w,i,r) \
105 (BOOL)SendMessage((w),HDM_GETITEMRECT,(WPARAM)(i),(LPARAM)(r))
108 #ifndef HDM_GETITEMRECT
109 #define HDM_GETITEMRECT (HDM_FIRST+7)
113 #define LVCF_IMAGE 0x0010
116 #ifndef LVCFMT_BITMAP_ON_RIGHT
117 #define LVCFMT_BITMAP_ON_RIGHT 0x1000
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
124 // convert our state and mask flags to LV_ITEM constants
125 static void wxConvertToMSWFlags(long state
, long mask
, LV_ITEM
& lvItem
);
127 // convert wxListItem to LV_ITEM
128 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
129 const wxListItem
& info
, LV_ITEM
& lvItem
);
131 // convert LV_ITEM to wxListItem
132 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
134 /* const */ LV_ITEM
& lvItem
);
136 // convert our wxListItem to LV_COLUMN
137 static void wxConvertToMSWListCol(int col
, const wxListItem
& item
,
140 // ----------------------------------------------------------------------------
141 // private helper classes
142 // ----------------------------------------------------------------------------
144 // We have to handle both fooW and fooA notifications in several cases
145 // because of broken commctl.dll and/or unicows.dll. This class is used to
146 // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
147 // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
148 // by wxConvertToMSWListItem().
152 ~wxLV_ITEM() { delete m_buf
; }
153 operator LV_ITEM
&() const { return *m_item
; }
156 wxLV_ITEM(LV_ITEMW
&item
) : m_buf(NULL
), m_item(&item
) {}
157 wxLV_ITEM(LV_ITEMA
&item
)
159 m_item
= new LV_ITEM((LV_ITEM
&)item
);
160 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
162 m_buf
= new wxMB2WXbuf(wxConvLocal
.cMB2WX(item
.pszText
));
163 m_item
->pszText
= (wxChar
*)m_buf
->data();
172 wxLV_ITEM(LV_ITEMW
&item
)
174 m_item
= new LV_ITEM((LV_ITEM
&)item
);
175 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
177 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX(item
.pszText
));
178 m_item
->pszText
= (wxChar
*)m_buf
->data();
183 wxLV_ITEM(LV_ITEMA
&item
) : m_buf(NULL
), m_item(&item
) {}
191 // ----------------------------------------------------------------------------
193 // ----------------------------------------------------------------------------
195 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
196 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
197 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
198 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
199 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
200 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
201 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
202 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
203 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
204 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
205 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
206 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
207 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
208 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
209 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
210 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
211 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
212 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
213 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
214 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
215 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
216 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
218 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
219 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
220 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
222 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
224 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
225 EVT_PAINT(wxListCtrl::OnPaint
)
228 // ============================================================================
230 // ============================================================================
232 // ----------------------------------------------------------------------------
233 // wxListCtrl construction
234 // ----------------------------------------------------------------------------
236 void wxListCtrl::Init()
238 m_imageListNormal
= NULL
;
239 m_imageListSmall
= NULL
;
240 m_imageListState
= NULL
;
241 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
245 m_hasAnyAttr
= FALSE
;
248 bool wxListCtrl::Create(wxWindow
*parent
,
253 const wxValidator
& validator
,
254 const wxString
& name
)
257 SetValidator(validator
);
258 #endif // wxUSE_VALIDATORS
267 m_windowStyle
= style
;
280 m_windowId
= (id
== -1) ? NewControlId() : id
;
282 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
283 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
285 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
286 wstyle
|= WS_CLIPSIBLINGS
;
288 if ( wxStyleHasBorder(m_windowStyle
) )
290 m_baseStyle
= wstyle
;
292 if ( !DoCreateControl(x
, y
, width
, height
) )
296 parent
->AddChild(this);
301 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
303 DWORD wstyle
= m_baseStyle
;
306 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
308 // Even with extended styles, need to combine with WS_BORDER
309 // for them to look right.
313 long oldStyle
= 0; // Dummy
314 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
316 // Create the ListView control.
317 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
322 GetWinHwnd(GetParent()),
329 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
334 // for comctl32.dll v 4.70+ we want to have this attribute because it's
335 // prettier (and also because wxGTK does it like this)
336 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
338 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
339 0, LVS_EX_FULLROWSELECT
);
342 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
343 SetForegroundColour(GetParent()->GetForegroundColour());
350 void wxListCtrl::UpdateStyle()
354 // The new window view style
356 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
357 dwStyleNew
|= m_baseStyle
;
359 // Get the current window style.
360 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
362 // Only set the window style if the view bits have changed.
363 if ( dwStyleOld
!= dwStyleNew
)
365 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
370 void wxListCtrl::FreeAllAttrs(bool dontRecreate
)
374 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
376 delete (wxListItemAttr
*)node
->Data();
382 m_attrs
.Create(wxKEY_INTEGER
, 1000); // just as def ctor
385 m_hasAnyAttr
= FALSE
;
389 wxListCtrl::~wxListCtrl()
391 FreeAllAttrs(TRUE
/* no need to recreate hash any more */);
395 m_textCtrl
->SetHWND(0);
396 m_textCtrl
->UnsubclassWin();
401 if (m_ownsImageListNormal
) delete m_imageListNormal
;
402 if (m_ownsImageListSmall
) delete m_imageListSmall
;
403 if (m_ownsImageListState
) delete m_imageListState
;
406 // ----------------------------------------------------------------------------
407 // set/get/change style
408 // ----------------------------------------------------------------------------
410 // Add or remove a single window style
411 void wxListCtrl::SetSingleStyle(long style
, bool add
)
413 long flag
= GetWindowStyleFlag();
415 // Get rid of conflicting styles
418 if ( style
& wxLC_MASK_TYPE
)
419 flag
= flag
& ~wxLC_MASK_TYPE
;
420 if ( style
& wxLC_MASK_ALIGN
)
421 flag
= flag
& ~wxLC_MASK_ALIGN
;
422 if ( style
& wxLC_MASK_SORT
)
423 flag
= flag
& ~wxLC_MASK_SORT
;
439 m_windowStyle
= flag
;
444 // Set the whole window style
445 void wxListCtrl::SetWindowStyleFlag(long flag
)
447 m_windowStyle
= flag
;
452 // Can be just a single style, or a bitlist
453 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
456 if ( style
& wxLC_ICON
)
458 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
459 oldStyle
-= LVS_SMALLICON
;
460 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
461 oldStyle
-= LVS_REPORT
;
462 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
463 oldStyle
-= LVS_LIST
;
467 if ( style
& wxLC_SMALL_ICON
)
469 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
470 oldStyle
-= LVS_ICON
;
471 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
472 oldStyle
-= LVS_REPORT
;
473 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
474 oldStyle
-= LVS_LIST
;
475 wstyle
|= LVS_SMALLICON
;
478 if ( style
& wxLC_LIST
)
480 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
481 oldStyle
-= LVS_ICON
;
482 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
483 oldStyle
-= LVS_REPORT
;
484 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
485 oldStyle
-= LVS_SMALLICON
;
489 if ( style
& wxLC_REPORT
)
491 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
492 oldStyle
-= LVS_ICON
;
493 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
494 oldStyle
-= LVS_LIST
;
495 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
496 oldStyle
-= LVS_SMALLICON
;
498 wstyle
|= LVS_REPORT
;
501 if ( style
& wxLC_ALIGN_LEFT
)
503 if ( oldStyle
& LVS_ALIGNTOP
)
504 oldStyle
-= LVS_ALIGNTOP
;
505 wstyle
|= LVS_ALIGNLEFT
;
508 if ( style
& wxLC_ALIGN_TOP
)
510 if ( oldStyle
& LVS_ALIGNLEFT
)
511 oldStyle
-= LVS_ALIGNLEFT
;
512 wstyle
|= LVS_ALIGNTOP
;
515 if ( style
& wxLC_AUTOARRANGE
)
516 wstyle
|= LVS_AUTOARRANGE
;
518 if ( style
& wxLC_NO_SORT_HEADER
)
519 wstyle
|= LVS_NOSORTHEADER
;
521 if ( style
& wxLC_NO_HEADER
)
522 wstyle
|= LVS_NOCOLUMNHEADER
;
524 if ( style
& wxLC_EDIT_LABELS
)
525 wstyle
|= LVS_EDITLABELS
;
527 if ( style
& wxLC_SINGLE_SEL
)
528 wstyle
|= LVS_SINGLESEL
;
530 if ( style
& wxLC_SORT_ASCENDING
)
532 if ( oldStyle
& LVS_SORTDESCENDING
)
533 oldStyle
-= LVS_SORTDESCENDING
;
534 wstyle
|= LVS_SORTASCENDING
;
537 if ( style
& wxLC_SORT_DESCENDING
)
539 if ( oldStyle
& LVS_SORTASCENDING
)
540 oldStyle
-= LVS_SORTASCENDING
;
541 wstyle
|= LVS_SORTDESCENDING
;
544 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
545 if ( style
& wxLC_VIRTUAL
)
547 int ver
= wxTheApp
->GetComCtl32Version();
550 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."),
551 ver
/ 100, ver
% 100);
554 wstyle
|= LVS_OWNERDATA
;
561 // ----------------------------------------------------------------------------
563 // ----------------------------------------------------------------------------
565 // Sets the foreground, i.e. text, colour
566 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
568 if ( !wxWindow::SetForegroundColour(col
) )
571 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
576 // Sets the background colour
577 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
579 if ( !wxWindow::SetBackgroundColour(col
) )
582 // we set the same colour for both the "empty" background and the items
584 COLORREF color
= wxColourToRGB(col
);
585 ListView_SetBkColor(GetHwnd(), color
);
586 ListView_SetTextBkColor(GetHwnd(), color
);
591 // Gets information about this column
592 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
597 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
599 lvCol
.mask
|= LVCF_TEXT
;
600 lvCol
.pszText
= new wxChar
[513];
601 lvCol
.cchTextMax
= 512;
604 bool success
= ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0;
606 // item.m_subItem = lvCol.iSubItem;
607 item
.m_width
= lvCol
.cx
;
609 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
611 item
.m_text
= lvCol
.pszText
;
612 delete[] lvCol
.pszText
;
615 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
617 if (lvCol
.fmt
== LVCFMT_LEFT
)
618 item
.m_format
= wxLIST_FORMAT_LEFT
;
619 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
620 item
.m_format
= wxLIST_FORMAT_RIGHT
;
621 else if (lvCol
.fmt
== LVCFMT_CENTER
)
622 item
.m_format
= wxLIST_FORMAT_CENTRE
;
628 // Sets information about this column
629 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
632 wxConvertToMSWListCol(col
, item
, lvCol
);
634 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
637 // Gets the column width
638 int wxListCtrl::GetColumnWidth(int col
) const
640 return ListView_GetColumnWidth(GetHwnd(), col
);
643 // Sets the column width
644 bool wxListCtrl::SetColumnWidth(int col
, int width
)
647 if ( m_windowStyle
& wxLC_LIST
)
651 if ( width2
== wxLIST_AUTOSIZE
)
652 width2
= LVSCW_AUTOSIZE
;
653 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
654 width2
= LVSCW_AUTOSIZE_USEHEADER
;
656 return ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0;
659 // Gets the number of items that can fit vertically in the
660 // visible area of the list control (list or report view)
661 // or the total number of items in the list control (icon
662 // or small icon view)
663 int wxListCtrl::GetCountPerPage() const
665 return ListView_GetCountPerPage(GetHwnd());
668 // Gets the edit control for editing labels.
669 wxTextCtrl
* wxListCtrl::GetEditControl() const
674 // Gets information about the item
675 bool wxListCtrl::GetItem(wxListItem
& info
) const
678 wxZeroMemory(lvItem
);
680 lvItem
.iItem
= info
.m_itemId
;
681 lvItem
.iSubItem
= info
.m_col
;
683 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
685 lvItem
.mask
|= LVIF_TEXT
;
686 lvItem
.pszText
= new wxChar
[513];
687 lvItem
.cchTextMax
= 512;
691 lvItem
.pszText
= NULL
;
694 if (info
.m_mask
& wxLIST_MASK_DATA
)
695 lvItem
.mask
|= LVIF_PARAM
;
697 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
698 lvItem
.mask
|= LVIF_IMAGE
;
700 if ( info
.m_mask
& wxLIST_MASK_STATE
)
702 lvItem
.mask
|= LVIF_STATE
;
703 // the other bits are hardly interesting anyhow
704 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
707 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
710 wxLogError(_("Couldn't retrieve information about list control item %d."),
715 // give NULL as hwnd as we already have everything we need
716 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
720 delete[] lvItem
.pszText
;
725 // Sets information about the item
726 bool wxListCtrl::SetItem(wxListItem
& info
)
729 wxConvertToMSWListItem(this, info
, item
);
731 // we could be changing only the attribute in which case we don't need to
732 // call ListView_SetItem() at all
736 if ( !ListView_SetItem(GetHwnd(), &item
) )
738 wxLogDebug(_T("ListView_SetItem() failed"));
744 // we need to update the item immediately to show the new image
745 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
747 // check whether it has any custom attributes
748 if ( info
.HasAttributes() )
750 wxListItemAttr
*attr
= (wxListItemAttr
*)m_attrs
.Get(item
.iItem
);
753 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
755 *attr
= *info
.GetAttributes();
759 // if the colour has changed, we must redraw the item
765 // we need this to make the change visible right now
766 RefreshItem(item
.iItem
);
772 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
776 info
.m_mask
= wxLIST_MASK_TEXT
;
777 info
.m_itemId
= index
;
781 info
.m_image
= imageId
;
782 info
.m_mask
|= wxLIST_MASK_IMAGE
;
784 return SetItem(info
);
788 // Gets the item state
789 int wxListCtrl::GetItemState(long item
, long stateMask
) const
793 info
.m_mask
= wxLIST_MASK_STATE
;
794 info
.m_stateMask
= stateMask
;
795 info
.m_itemId
= item
;
803 // Sets the item state
804 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
806 // NB: don't use SetItem() here as it doesn't work with the virtual list
809 wxZeroMemory(lvItem
);
811 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
813 // for the virtual list controls we need to refresh the previously focused
814 // item manually when changing focus without changing selection
815 // programmatically because otherwise it keeps its focus rectangle until
816 // next repaint (yet another comctl32 bug)
819 (stateMask
& wxLIST_STATE_FOCUSED
) &&
820 (state
& wxLIST_STATE_FOCUSED
) )
822 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
829 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
830 (WPARAM
)item
, (LPARAM
)&lvItem
) )
832 wxLogLastError(_T("ListView_SetItemState"));
837 if ( focusOld
!= -1 )
839 // no need to refresh the item if it was previously selected, it would
840 // only result in annoying flicker
841 if ( !(GetItemState(focusOld
,
842 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
844 RefreshItem(focusOld
);
851 // Sets the item image
852 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
856 info
.m_mask
= wxLIST_MASK_IMAGE
;
857 info
.m_image
= image
;
858 info
.m_itemId
= item
;
860 return SetItem(info
);
863 // Gets the item text
864 wxString
wxListCtrl::GetItemText(long item
) const
868 info
.m_mask
= wxLIST_MASK_TEXT
;
869 info
.m_itemId
= item
;
876 // Sets the item text
877 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
881 info
.m_mask
= wxLIST_MASK_TEXT
;
882 info
.m_itemId
= item
;
888 // Gets the item data
889 long wxListCtrl::GetItemData(long item
) const
893 info
.m_mask
= wxLIST_MASK_DATA
;
894 info
.m_itemId
= item
;
901 // Sets the item data
902 bool wxListCtrl::SetItemData(long item
, long data
)
906 info
.m_mask
= wxLIST_MASK_DATA
;
907 info
.m_itemId
= item
;
910 return SetItem(info
);
913 // Gets the item rectangle
914 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
919 if ( code
== wxLIST_RECT_BOUNDS
)
920 codeWin
= LVIR_BOUNDS
;
921 else if ( code
== wxLIST_RECT_ICON
)
923 else if ( code
== wxLIST_RECT_LABEL
)
924 codeWin
= LVIR_LABEL
;
927 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
929 codeWin
= LVIR_BOUNDS
;
933 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
) != 0;
935 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
938 rect
.x
= rectWin
.left
;
939 rect
.y
= rectWin
.top
;
940 rect
.width
= rectWin
.right
- rectWin
.left
;
941 rect
.height
= rectWin
.bottom
- rectWin
.top
;
946 // Gets the item position
947 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
951 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
953 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
957 // Sets the item position.
958 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
960 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
963 // Gets the number of items in the list control
964 int wxListCtrl::GetItemCount() const
966 return ListView_GetItemCount(GetHwnd());
969 // Retrieves the spacing between icons in pixels.
970 // If small is TRUE, gets the spacing for the small icon
971 // view, otherwise the large icon view.
972 int wxListCtrl::GetItemSpacing(bool isSmall
) const
974 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
977 // Gets the number of selected items in the list control
978 int wxListCtrl::GetSelectedItemCount() const
980 return ListView_GetSelectedCount(GetHwnd());
983 // Gets the text colour of the listview
984 wxColour
wxListCtrl::GetTextColour() const
986 COLORREF ref
= ListView_GetTextColor(GetHwnd());
987 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
991 // Sets the text colour of the listview
992 void wxListCtrl::SetTextColour(const wxColour
& col
)
994 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
997 // Gets the index of the topmost visible item when in
998 // list or report view
999 long wxListCtrl::GetTopItem() const
1001 return (long) ListView_GetTopIndex(GetHwnd());
1004 // Searches for an item, starting from 'item'.
1005 // 'geometry' is one of
1006 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1007 // 'state' is a state bit flag, one or more of
1008 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1009 // item can be -1 to find the first item that matches the
1011 // Returns the item or -1 if unsuccessful.
1012 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1016 if ( geom
== wxLIST_NEXT_ABOVE
)
1017 flags
|= LVNI_ABOVE
;
1018 if ( geom
== wxLIST_NEXT_ALL
)
1020 if ( geom
== wxLIST_NEXT_BELOW
)
1021 flags
|= LVNI_BELOW
;
1022 if ( geom
== wxLIST_NEXT_LEFT
)
1023 flags
|= LVNI_TOLEFT
;
1024 if ( geom
== wxLIST_NEXT_RIGHT
)
1025 flags
|= LVNI_TORIGHT
;
1027 if ( state
& wxLIST_STATE_CUT
)
1029 if ( state
& wxLIST_STATE_DROPHILITED
)
1030 flags
|= LVNI_DROPHILITED
;
1031 if ( state
& wxLIST_STATE_FOCUSED
)
1032 flags
|= LVNI_FOCUSED
;
1033 if ( state
& wxLIST_STATE_SELECTED
)
1034 flags
|= LVNI_SELECTED
;
1036 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1040 wxImageList
*wxListCtrl::GetImageList(int which
) const
1042 if ( which
== wxIMAGE_LIST_NORMAL
)
1044 return m_imageListNormal
;
1046 else if ( which
== wxIMAGE_LIST_SMALL
)
1048 return m_imageListSmall
;
1050 else if ( which
== wxIMAGE_LIST_STATE
)
1052 return m_imageListState
;
1057 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1060 if ( which
== wxIMAGE_LIST_NORMAL
)
1062 flags
= LVSIL_NORMAL
;
1063 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1064 m_imageListNormal
= imageList
;
1065 m_ownsImageListNormal
= FALSE
;
1067 else if ( which
== wxIMAGE_LIST_SMALL
)
1069 flags
= LVSIL_SMALL
;
1070 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1071 m_imageListSmall
= imageList
;
1072 m_ownsImageListSmall
= FALSE
;
1074 else if ( which
== wxIMAGE_LIST_STATE
)
1076 flags
= LVSIL_STATE
;
1077 if (m_ownsImageListState
) delete m_imageListState
;
1078 m_imageListState
= imageList
;
1079 m_ownsImageListState
= FALSE
;
1081 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1084 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1086 SetImageList(imageList
, which
);
1087 if ( which
== wxIMAGE_LIST_NORMAL
)
1088 m_ownsImageListNormal
= TRUE
;
1089 else if ( which
== wxIMAGE_LIST_SMALL
)
1090 m_ownsImageListSmall
= TRUE
;
1091 else if ( which
== wxIMAGE_LIST_STATE
)
1092 m_ownsImageListState
= TRUE
;
1095 // ----------------------------------------------------------------------------
1097 // ----------------------------------------------------------------------------
1099 // Arranges the items
1100 bool wxListCtrl::Arrange(int flag
)
1103 if ( flag
== wxLIST_ALIGN_LEFT
)
1104 code
= LVA_ALIGNLEFT
;
1105 else if ( flag
== wxLIST_ALIGN_TOP
)
1106 code
= LVA_ALIGNTOP
;
1107 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1109 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1110 code
= LVA_SNAPTOGRID
;
1112 return (ListView_Arrange(GetHwnd(), code
) != 0);
1116 bool wxListCtrl::DeleteItem(long item
)
1118 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1120 wxLogLastError(_T("ListView_DeleteItem"));
1124 // the virtual list control doesn't refresh itself correctly, help it
1127 // we need to refresh all the lines below the one which was deleted
1129 if ( item
> 0 && GetItemCount() )
1131 GetItemRect(item
- 1, rectItem
);
1136 rectItem
.height
= 0;
1139 wxRect rectWin
= GetRect();
1140 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1141 rectWin
.y
= rectItem
.GetBottom();
1143 RefreshRect(rectWin
);
1149 // Deletes all items
1150 bool wxListCtrl::DeleteAllItems()
1152 return ListView_DeleteAllItems(GetHwnd()) != 0;
1155 // Deletes all items
1156 bool wxListCtrl::DeleteAllColumns()
1158 while ( m_colCount
> 0 )
1160 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1162 wxLogLastError(wxT("ListView_DeleteColumn"));
1170 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1176 bool wxListCtrl::DeleteColumn(int col
)
1178 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1180 if ( success
&& (m_colCount
> 0) )
1185 // Clears items, and columns if there are any.
1186 void wxListCtrl::ClearAll()
1189 if ( m_colCount
> 0 )
1193 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1195 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1197 // VS: ListView_EditLabel requires that the list has focus.
1199 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
1203 m_textCtrl
->SetHWND(0);
1204 m_textCtrl
->UnsubclassWin();
1209 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1210 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1211 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1216 // End label editing, optionally cancelling the edit
1217 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1219 wxFAIL_MSG( _T("not implemented") );
1224 // Ensures this item is visible
1225 bool wxListCtrl::EnsureVisible(long item
)
1227 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0;
1230 // Find an item whose label matches this string, starting from the item after 'start'
1231 // or the beginning if 'start' is -1.
1232 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1234 LV_FINDINFO findInfo
;
1236 findInfo
.flags
= LVFI_STRING
;
1238 findInfo
.flags
|= LVFI_PARTIAL
;
1241 // ListView_FindItem() excludes the first item from search and to look
1242 // through all the items you need to start from -1 which is unnatural and
1243 // inconsistent with the generic version - so we adjust the index
1246 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1249 // Find an item whose data matches this data, starting from the item after 'start'
1250 // or the beginning if 'start' is -1.
1251 long wxListCtrl::FindItem(long start
, long data
)
1253 LV_FINDINFO findInfo
;
1255 findInfo
.flags
= LVFI_PARAM
;
1256 findInfo
.lParam
= data
;
1258 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1261 // Find an item nearest this position in the specified direction, starting from
1262 // the item after 'start' or the beginning if 'start' is -1.
1263 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1265 LV_FINDINFO findInfo
;
1267 findInfo
.flags
= LVFI_NEARESTXY
;
1268 findInfo
.pt
.x
= pt
.x
;
1269 findInfo
.pt
.y
= pt
.y
;
1270 findInfo
.vkDirection
= VK_RIGHT
;
1272 if ( direction
== wxLIST_FIND_UP
)
1273 findInfo
.vkDirection
= VK_UP
;
1274 else if ( direction
== wxLIST_FIND_DOWN
)
1275 findInfo
.vkDirection
= VK_DOWN
;
1276 else if ( direction
== wxLIST_FIND_LEFT
)
1277 findInfo
.vkDirection
= VK_LEFT
;
1278 else if ( direction
== wxLIST_FIND_RIGHT
)
1279 findInfo
.vkDirection
= VK_RIGHT
;
1281 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1284 // Determines which item (if any) is at the specified point,
1285 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1286 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1288 LV_HITTESTINFO hitTestInfo
;
1289 hitTestInfo
.pt
.x
= (int) point
.x
;
1290 hitTestInfo
.pt
.y
= (int) point
.y
;
1292 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1295 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1296 flags
|= wxLIST_HITTEST_ABOVE
;
1297 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1298 flags
|= wxLIST_HITTEST_BELOW
;
1299 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1300 flags
|= wxLIST_HITTEST_NOWHERE
;
1301 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1302 flags
|= wxLIST_HITTEST_ONITEMICON
;
1303 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1304 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1305 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1306 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1307 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1308 flags
|= wxLIST_HITTEST_TOLEFT
;
1309 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1310 flags
|= wxLIST_HITTEST_TORIGHT
;
1312 return (long) hitTestInfo
.iItem
;
1315 // Inserts an item, returning the index of the new item if successful,
1317 long wxListCtrl::InsertItem(wxListItem
& info
)
1319 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1322 wxConvertToMSWListItem(this, info
, item
);
1324 // check whether it has any custom attributes
1325 if ( info
.HasAttributes() )
1328 wxListItemAttr
*attr
;
1329 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
1333 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1335 else *attr
= *info
.GetAttributes();
1337 m_hasAnyAttr
= TRUE
;
1340 return (long) ListView_InsertItem(GetHwnd(), & item
);
1343 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1346 info
.m_text
= label
;
1347 info
.m_mask
= wxLIST_MASK_TEXT
;
1348 info
.m_itemId
= index
;
1349 return InsertItem(info
);
1352 // Inserts an image item
1353 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1356 info
.m_image
= imageIndex
;
1357 info
.m_mask
= wxLIST_MASK_IMAGE
;
1358 info
.m_itemId
= index
;
1359 return InsertItem(info
);
1362 // Inserts an image/string item
1363 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1366 info
.m_image
= imageIndex
;
1367 info
.m_text
= label
;
1368 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1369 info
.m_itemId
= index
;
1370 return InsertItem(info
);
1373 // For list view mode (only), inserts a column.
1374 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1377 wxConvertToMSWListCol(col
, item
, lvCol
);
1379 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1381 // always give some width to the new column: this one is compatible
1382 // with the generic version
1383 lvCol
.mask
|= LVCF_WIDTH
;
1387 // when we insert a column which can contain an image, we must specify this
1388 // flag right now as doing it later in SetColumn() has no effect
1390 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1391 // way to dynamically set/clear the bitmap as the column without a bitmap
1392 // on the left looks ugly (there is a hole)
1394 // unfortunately with my version of comctl32.dll (5.80), the left column
1395 // image is always on the left and it seems that it's a "feature" - I
1396 // didn't find any way to work around it in any case
1397 if ( lvCol
.mask
& LVCF_IMAGE
)
1399 lvCol
.mask
|= LVCF_FMT
;
1400 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
;
1403 bool success
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
) != -1;
1410 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1417 long wxListCtrl::InsertColumn(long col
,
1418 const wxString
& heading
,
1423 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1424 item
.m_text
= heading
;
1427 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1428 item
.m_width
= width
;
1430 item
.m_format
= format
;
1432 return InsertColumn(col
, item
);
1435 // Scrolls the list control. If in icon, small icon or report view mode,
1436 // x specifies the number of pixels to scroll. If in list view mode, x
1437 // specifies the number of columns to scroll.
1438 // If in icon, small icon or list view mode, y specifies the number of pixels
1439 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1440 bool wxListCtrl::ScrollList(int dx
, int dy
)
1442 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1447 // fn is a function which takes 3 long arguments: item1, item2, data.
1448 // item1 is the long data associated with a first item (NOT the index).
1449 // item2 is the long data associated with a second item (NOT the index).
1450 // data is the same value as passed to SortItems.
1451 // The return value is a negative number if the first item should precede the second
1452 // item, a positive number of the second item should precede the first,
1453 // or zero if the two items are equivalent.
1455 // data is arbitrary data to be passed to the sort function.
1457 // FIXME: this is horrible and MT-unsafe and everything else but I don't have
1458 // time for anything better right now (VZ)
1459 static long gs_sortData
= 0;
1460 static wxListCtrl
*gs_sortCtrl
= NULL
;
1461 static wxListCtrlCompare gs_sortFunction
= NULL
;
1463 int wxCMPFUNC_CONV
wxListCtrlCompareFn(const void *arg1
, const void *arg2
)
1465 int n1
= *(const int *)arg1
,
1466 n2
= *(const int *)arg2
;
1468 return gs_sortFunction(gs_sortCtrl
->GetItemData(n1
),
1469 gs_sortCtrl
->GetItemData(n2
),
1473 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1475 // sort the attributes too
1479 count
= GetItemCount();
1480 int *aItems
= new int[count
];
1481 for ( n
= 0; n
< count
; n
++ )
1488 gs_sortFunction
= fn
;
1490 qsort(aItems
, count
, sizeof(int), wxListCtrlCompareFn
);
1494 gs_sortFunction
= NULL
;
1496 wxHashTable
attrsNew(wxKEY_INTEGER
, 1000);
1497 for ( n
= 0; n
< count
; n
++ )
1499 wxObject
*attr
= m_attrs
.Delete(aItems
[n
]);
1502 attrsNew
.Put(n
, attr
);
1512 if ( !ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
)fn
, data
) )
1514 wxLogDebug(_T("ListView_SortItems() failed"));
1524 // ----------------------------------------------------------------------------
1525 // message processing
1526 // ----------------------------------------------------------------------------
1528 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1530 if (cmd
== EN_UPDATE
)
1532 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1533 event
.SetEventObject( this );
1534 ProcessCommand(event
);
1537 else if (cmd
== EN_KILLFOCUS
)
1539 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1540 event
.SetEventObject( this );
1541 ProcessCommand(event
);
1548 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1550 // prepare the event
1551 // -----------------
1553 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1554 event
.SetEventObject(this);
1556 wxEventType eventType
= wxEVT_NULL
;
1558 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1560 // if your compiler is as broken as this, you should really change it: this
1561 // code is needed for normal operation! #ifdef below is only useful for
1562 // automatic rebuilds which are done with a very old compiler version
1563 #ifdef HDN_BEGINTRACKA
1565 // check for messages from the header (in report view)
1566 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1568 // is it a message from the header?
1569 if ( nmhdr
->hwndFrom
== hwndHdr
)
1571 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1573 event
.m_itemIndex
= -1;
1575 switch ( nmhdr
->code
)
1577 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1578 // TRACK messages even to ANSI programs: on my system I get
1579 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1581 // work around is to simply catch both versions and hope that it
1582 // works (why should this message exist in ANSI and Unicode is
1583 // beyond me as it doesn't deal with strings at all...)
1584 case HDN_BEGINTRACKA
:
1585 case HDN_BEGINTRACKW
:
1586 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1591 if ( eventType
== wxEVT_NULL
)
1592 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1597 if ( eventType
== wxEVT_NULL
)
1598 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1599 event
.m_col
= nmHDR
->iItem
;
1604 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1607 // find the column clicked: we have to search for it
1608 // ourselves as the notification message doesn't provide
1611 // where did the click occur?
1613 if ( !::GetCursorPos(&ptClick
) )
1615 wxLogLastError(_T("GetCursorPos"));
1618 if ( !::ScreenToClient(hwndHdr
, &ptClick
) )
1620 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1623 event
.m_pointDrag
.x
= ptClick
.x
;
1624 event
.m_pointDrag
.y
= ptClick
.y
;
1626 int colCount
= Header_GetItemCount(hwndHdr
);
1629 for ( int col
= 0; col
< colCount
; col
++ )
1631 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1633 if ( ::PtInRect(&rect
, ptClick
) )
1644 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1648 #endif // defined(HDN_BEGINTRACKA)
1649 if ( nmhdr
->hwndFrom
== GetHwnd() )
1651 // almost all messages use NM_LISTVIEW
1652 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1654 // this is true for almost all events
1655 event
.m_item
.m_data
= nmLV
->lParam
;
1657 switch ( nmhdr
->code
)
1659 case LVN_BEGINRDRAG
:
1660 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1664 if ( eventType
== wxEVT_NULL
)
1666 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1669 event
.m_itemIndex
= nmLV
->iItem
;
1670 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1671 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1674 // NB: we have to handle both *A and *W versions here because some
1675 // versions of comctl32.dll send ANSI message to an Unicode app
1676 case LVN_BEGINLABELEDITA
:
1678 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1679 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1680 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1681 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1684 case LVN_BEGINLABELEDITW
:
1686 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1687 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1688 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1689 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1693 case LVN_ENDLABELEDITA
:
1695 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1696 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1697 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1698 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1699 ((LV_ITEM
)item
).iItem
== -1 )
1702 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1705 case LVN_ENDLABELEDITW
:
1707 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1708 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1709 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1710 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1711 ((LV_ITEM
)item
).iItem
== -1 )
1714 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1718 case LVN_COLUMNCLICK
:
1719 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1720 event
.m_itemIndex
= -1;
1721 event
.m_col
= nmLV
->iSubItem
;
1724 case LVN_DELETEALLITEMS
:
1725 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1726 event
.m_itemIndex
= -1;
1732 case LVN_DELETEITEM
:
1733 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1734 event
.m_itemIndex
= nmLV
->iItem
;
1738 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1742 case LVN_SETDISPINFO
:
1744 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1745 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1746 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
1750 case LVN_INSERTITEM
:
1751 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1752 event
.m_itemIndex
= nmLV
->iItem
;
1755 case LVN_ITEMCHANGED
:
1756 // we translate this catch all message into more interesting
1757 // (and more easy to process) wxWindows events
1759 // first of all, we deal with the state change events only
1760 if ( nmLV
->uChanged
& LVIF_STATE
)
1762 // temp vars for readability
1763 const UINT stOld
= nmLV
->uOldState
;
1764 const UINT stNew
= nmLV
->uNewState
;
1766 // has the focus changed?
1767 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
1769 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
1770 event
.m_itemIndex
= nmLV
->iItem
;
1773 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
1775 if ( eventType
!= wxEVT_NULL
)
1777 // focus and selection have both changed: send the
1778 // focus event from here and the selection one
1780 event
.SetEventType(eventType
);
1781 (void)GetEventHandler()->ProcessEvent(event
);
1783 else // no focus event to send
1785 // then need to set m_itemIndex as it wasn't done
1787 event
.m_itemIndex
= nmLV
->iItem
;
1790 eventType
= stNew
& LVIS_SELECTED
1791 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1792 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1796 if ( eventType
== wxEVT_NULL
)
1798 // not an interesting event for us
1806 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1807 WORD wVKey
= info
->wVKey
;
1809 // get the current selection
1810 long lItem
= GetNextItem(-1,
1812 wxLIST_STATE_SELECTED
);
1814 // <Enter> or <Space> activate the selected item if any (but
1815 // not with Shift and/or Ctrl as then they have a predefined
1816 // meaning for the list view)
1818 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
1819 !(wxIsShiftDown() || wxIsCtrlDown()) )
1821 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1825 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1827 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1828 // value which should be used as is
1829 int code
= wxCharCodeMSWToWX(wVKey
);
1830 event
.m_code
= code
? code
: wVKey
;
1834 event
.m_item
.m_itemId
= lItem
;
1838 // fill the other fields too
1839 event
.m_item
.m_text
= GetItemText(lItem
);
1840 event
.m_item
.m_data
= GetItemData(lItem
);
1846 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1848 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1853 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1854 // if it happened on an item (and not on empty place)
1855 if ( nmLV
->iItem
== -1 )
1861 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1862 event
.m_itemIndex
= nmLV
->iItem
;
1863 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1864 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1868 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1869 // don't do anything else
1870 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1875 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1876 LV_HITTESTINFO lvhti
;
1877 wxZeroMemory(lvhti
);
1879 ::GetCursorPos(&(lvhti
.pt
));
1880 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1881 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1883 if ( lvhti
.flags
& LVHT_ONITEM
)
1885 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1886 event
.m_itemIndex
= lvhti
.iItem
;
1887 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
1888 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
1893 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1894 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
1896 *result
= OnCustomDraw(lParam
);
1899 #endif // _WIN32_IE >= 0x300
1901 case LVN_ODCACHEHINT
:
1903 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
1905 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
1907 // we get some really stupid cache hints like ones for items in
1908 // range 0..0 for an empty control or, after deleting an item,
1909 // for items in invalid range - filter this garbage out
1910 if ( cacheHint
->iFrom
< cacheHint
->iTo
)
1912 event
.m_oldItemIndex
= cacheHint
->iFrom
;
1914 long iMax
= GetItemCount();
1915 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
1925 case LVN_GETDISPINFO
:
1928 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1930 LV_ITEM
& lvi
= info
->item
;
1931 long item
= lvi
.iItem
;
1933 if ( lvi
.mask
& LVIF_TEXT
)
1935 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
1936 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
1939 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1940 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
1941 if ( lvi
.mask
& LVIF_IMAGE
)
1943 lvi
.iImage
= OnGetItemImage(item
);
1947 // a little dose of healthy paranoia: as we never use
1948 // LVM_SETCALLBACKMASK we're not supposed to get these ones
1949 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
1950 _T("we don't support state callbacks yet!") );
1957 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1962 // where did this one come from?
1966 // process the event
1967 // -----------------
1969 event
.SetEventType(eventType
);
1971 if ( !GetEventHandler()->ProcessEvent(event
) )
1977 switch ( nmhdr
->code
)
1979 case LVN_DELETEALLITEMS
:
1980 // always return TRUE to suppress all additional LVN_DELETEITEM
1981 // notifications - this makes deleting all items from a list ctrl
1987 case LVN_ENDLABELEDITA
:
1988 case LVN_ENDLABELEDITW
:
1989 // logic here is inversed compared to all the other messages
1990 *result
= event
.IsAllowed();
1995 *result
= !event
.IsAllowed();
2000 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
2002 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
2004 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
2005 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
2006 switch ( nmcd
.dwDrawStage
)
2009 // if we've got any items with non standard attributes,
2010 // notify us before painting each item
2012 // for virtual controls, always suppose that we have attributes as
2013 // there is no way to check for this
2014 return IsVirtual() || m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
2017 case CDDS_ITEMPREPAINT
:
2019 size_t item
= (size_t)nmcd
.dwItemSpec
;
2020 if ( item
>= (size_t)GetItemCount() )
2022 // we get this message with item == 0 for an empty control,
2023 // we must ignore it as calling OnGetItemAttr() would be
2025 return CDRF_DODEFAULT
;
2028 wxListItemAttr
*attr
=
2029 IsVirtual() ? OnGetItemAttr(item
)
2030 : (wxListItemAttr
*)m_attrs
.Get(item
);
2034 // nothing to do for this item
2035 return CDRF_DODEFAULT
;
2039 wxColour colText
, colBack
;
2040 if ( attr
->HasFont() )
2042 wxFont font
= attr
->GetFont();
2043 hFont
= (HFONT
)font
.GetResourceHandle();
2050 if ( attr
->HasTextColour() )
2052 colText
= attr
->GetTextColour();
2056 colText
= GetTextColour();
2059 if ( attr
->HasBackgroundColour() )
2061 colBack
= attr
->GetBackgroundColour();
2065 colBack
= GetBackgroundColour();
2068 lplvcd
->clrText
= wxColourToRGB(colText
);
2069 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
2071 // note that if we wanted to set colours for
2072 // individual columns (subitems), we would have
2073 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2076 ::SelectObject(nmcd
.hdc
, hFont
);
2078 return CDRF_NEWFONT
;
2081 // fall through to return CDRF_DODEFAULT
2084 return CDRF_DODEFAULT
;
2088 #endif // NM_CUSTOMDRAW supported
2090 // Necessary for drawing hrules and vrules, if specified
2091 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2095 wxControl::OnPaint(event
);
2097 // Reset the device origin since it may have been set
2098 dc
.SetDeviceOrigin(0, 0);
2100 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
2101 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
2103 if (!drawHRules
&& !drawVRules
)
2105 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
2108 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2110 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2112 wxSize clientSize
= GetClientSize();
2116 int itemCount
= GetItemCount();
2120 long top
= GetTopItem();
2121 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2123 if (GetItemRect(i
, itemRect
))
2125 cy
= itemRect
.GetTop();
2126 if (i
!= 0) // Don't draw the first one
2128 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2131 if (i
== itemCount
- 1)
2133 cy
= itemRect
.GetBottom();
2134 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2140 if (drawVRules
&& (i
> -1))
2142 wxRect firstItemRect
;
2143 GetItemRect(0, firstItemRect
);
2145 if (GetItemRect(i
, itemRect
))
2148 int x
= itemRect
.GetX();
2149 for (col
= 0; col
< GetColumnCount(); col
++)
2151 int colWidth
= GetColumnWidth(col
);
2153 dc
.DrawLine(x
, firstItemRect
.GetY() - 2, x
, itemRect
.GetBottom());
2159 // ----------------------------------------------------------------------------
2160 // virtual list controls
2161 // ----------------------------------------------------------------------------
2163 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2165 // this is a pure virtual function, in fact - which is not really pure
2166 // because the controls which are not virtual don't need to implement it
2167 wxFAIL_MSG( _T("not supposed to be called") );
2169 return wxEmptyString
;
2172 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2175 wxFAIL_MSG( _T("not supposed to be called") );
2180 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2182 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2183 _T("invalid item index in OnGetItemAttr()") );
2185 // no attributes by default
2189 void wxListCtrl::SetItemCount(long count
)
2191 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2193 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
, 0) )
2195 wxLogLastError(_T("ListView_SetItemCount"));
2199 void wxListCtrl::RefreshItem(long item
)
2201 // strangely enough, ListView_Update() results in much more flicker here
2202 // than a dumb Refresh() -- why?
2204 if ( !ListView_Update(GetHwnd(), item
) )
2206 wxLogLastError(_T("ListView_Update"));
2210 GetItemRect(item
, rect
);
2215 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2217 wxRect rect1
, rect2
;
2218 GetItemRect(itemFrom
, rect1
);
2219 GetItemRect(itemTo
, rect2
);
2221 wxRect rect
= rect1
;
2222 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2227 // ----------------------------------------------------------------------------
2229 // ----------------------------------------------------------------------------
2231 // List item structure
2232 wxListItem::wxListItem()
2242 m_format
= wxLIST_FORMAT_CENTRE
;
2248 void wxListItem::Clear()
2257 m_format
= wxLIST_FORMAT_CENTRE
;
2259 m_text
= wxEmptyString
;
2261 if (m_attr
) delete m_attr
;
2265 void wxListItem::ClearAttributes()
2267 if (m_attr
) delete m_attr
;
2271 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2275 info
.m_data
= lvItem
.lParam
;
2278 info
.m_stateMask
= 0;
2279 info
.m_itemId
= lvItem
.iItem
;
2281 long oldMask
= lvItem
.mask
;
2283 bool needText
= FALSE
;
2284 if (hwndListCtrl
!= 0)
2286 if ( lvItem
.mask
& LVIF_TEXT
)
2293 lvItem
.pszText
= new wxChar
[513];
2294 lvItem
.cchTextMax
= 512;
2296 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2297 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2300 if ( lvItem
.mask
& LVIF_STATE
)
2302 info
.m_mask
|= wxLIST_MASK_STATE
;
2304 if ( lvItem
.stateMask
& LVIS_CUT
)
2306 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2307 if ( lvItem
.state
& LVIS_CUT
)
2308 info
.m_state
|= wxLIST_STATE_CUT
;
2310 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2312 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2313 if ( lvItem
.state
& LVIS_DROPHILITED
)
2314 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2316 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2318 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2319 if ( lvItem
.state
& LVIS_FOCUSED
)
2320 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2322 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2324 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2325 if ( lvItem
.state
& LVIS_SELECTED
)
2326 info
.m_state
|= wxLIST_STATE_SELECTED
;
2330 if ( lvItem
.mask
& LVIF_TEXT
)
2332 info
.m_mask
|= wxLIST_MASK_TEXT
;
2333 info
.m_text
= lvItem
.pszText
;
2335 if ( lvItem
.mask
& LVIF_IMAGE
)
2337 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2338 info
.m_image
= lvItem
.iImage
;
2340 if ( lvItem
.mask
& LVIF_PARAM
)
2341 info
.m_mask
|= wxLIST_MASK_DATA
;
2342 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2343 info
.m_mask
|= wxLIST_SET_ITEM
;
2344 info
.m_col
= lvItem
.iSubItem
;
2349 delete[] lvItem
.pszText
;
2351 lvItem
.mask
= oldMask
;
2354 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2356 if (stateMask
& wxLIST_STATE_CUT
)
2358 lvItem
.stateMask
|= LVIS_CUT
;
2359 if (state
& wxLIST_STATE_CUT
)
2360 lvItem
.state
|= LVIS_CUT
;
2362 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2364 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2365 if (state
& wxLIST_STATE_DROPHILITED
)
2366 lvItem
.state
|= LVIS_DROPHILITED
;
2368 if (stateMask
& wxLIST_STATE_FOCUSED
)
2370 lvItem
.stateMask
|= LVIS_FOCUSED
;
2371 if (state
& wxLIST_STATE_FOCUSED
)
2372 lvItem
.state
|= LVIS_FOCUSED
;
2374 if (stateMask
& wxLIST_STATE_SELECTED
)
2376 lvItem
.stateMask
|= LVIS_SELECTED
;
2377 if (state
& wxLIST_STATE_SELECTED
)
2378 lvItem
.state
|= LVIS_SELECTED
;
2382 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2383 const wxListItem
& info
,
2386 lvItem
.iItem
= (int) info
.m_itemId
;
2388 lvItem
.iImage
= info
.m_image
;
2389 lvItem
.lParam
= info
.m_data
;
2390 lvItem
.stateMask
= 0;
2393 lvItem
.iSubItem
= info
.m_col
;
2395 if (info
.m_mask
& wxLIST_MASK_STATE
)
2397 lvItem
.mask
|= LVIF_STATE
;
2399 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2402 if (info
.m_mask
& wxLIST_MASK_TEXT
)
2404 lvItem
.mask
|= LVIF_TEXT
;
2405 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
2407 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
2411 // pszText is not const, hence the cast
2412 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
2413 if ( lvItem
.pszText
)
2414 lvItem
.cchTextMax
= info
.m_text
.Length();
2416 lvItem
.cchTextMax
= 0;
2419 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
2420 lvItem
.mask
|= LVIF_IMAGE
;
2421 if (info
.m_mask
& wxLIST_MASK_DATA
)
2422 lvItem
.mask
|= LVIF_PARAM
;
2425 static void wxConvertToMSWListCol(int WXUNUSED(col
), const wxListItem
& item
,
2428 wxZeroMemory(lvCol
);
2430 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
2432 lvCol
.mask
|= LVCF_TEXT
;
2433 lvCol
.pszText
= (wxChar
*)item
.m_text
.c_str(); // cast is safe
2436 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
2438 lvCol
.mask
|= LVCF_FMT
;
2440 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
2441 lvCol
.fmt
= LVCFMT_LEFT
;
2442 else if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
2443 lvCol
.fmt
= LVCFMT_RIGHT
;
2444 else if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
2445 lvCol
.fmt
= LVCFMT_CENTER
;
2448 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
2450 lvCol
.mask
|= LVCF_WIDTH
;
2451 if ( item
.m_width
== wxLIST_AUTOSIZE
)
2452 lvCol
.cx
= LVSCW_AUTOSIZE
;
2453 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2454 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
2456 lvCol
.cx
= item
.m_width
;
2459 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2460 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2461 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
2463 if ( wxTheApp
->GetComCtl32Version() >= 470 )
2465 lvCol
.mask
|= LVCF_IMAGE
;
2466 lvCol
.iImage
= item
.m_image
;
2468 //else: it doesn't support item images anyhow
2473 #endif // wxUSE_LISTCTRL