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 #if defined(__GNUWIN32__) && !defined(LV_ITEM) \
121 && !wxCHECK_W32API_VERSION( 0, 5 )
122 typedef struct _LVITEMW
{
132 #if (_WIN32_IE >= 0x0300)
136 typedef LV_ITEM LV_ITEMA
;
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
143 // convert our state and mask flags to LV_ITEM constants
144 static void wxConvertToMSWFlags(long state
, long mask
, LV_ITEM
& lvItem
);
146 // convert wxListItem to LV_ITEM
147 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
148 const wxListItem
& info
, LV_ITEM
& lvItem
);
150 // convert LV_ITEM to wxListItem
151 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
153 /* const */ LV_ITEM
& lvItem
);
155 // convert our wxListItem to LV_COLUMN
156 static void wxConvertToMSWListCol(int col
, const wxListItem
& item
,
159 // ----------------------------------------------------------------------------
160 // private helper classes
161 // ----------------------------------------------------------------------------
163 // We have to handle both fooW and fooA notifications in several cases
164 // because of broken commctl.dll and/or unicows.dll. This class is used to
165 // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
166 // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
167 // by wxConvertToMSWListItem().
171 ~wxLV_ITEM() { delete m_buf
; }
172 operator LV_ITEM
&() const { return *m_item
; }
175 wxLV_ITEM(LV_ITEMW
&item
) : m_buf(NULL
), m_item(&item
) {}
176 wxLV_ITEM(LV_ITEMA
&item
)
178 m_item
= new LV_ITEM((LV_ITEM
&)item
);
179 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
181 m_buf
= new wxMB2WXbuf(wxConvLocal
.cMB2WX(item
.pszText
));
182 m_item
->pszText
= (wxChar
*)m_buf
->data();
191 wxLV_ITEM(LV_ITEMW
&item
)
193 m_item
= new LV_ITEM((LV_ITEM
&)item
);
194 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
196 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX(item
.pszText
));
197 m_item
->pszText
= (wxChar
*)m_buf
->data();
202 wxLV_ITEM(LV_ITEMA
&item
) : m_buf(NULL
), m_item(&item
) {}
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
215 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
216 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
217 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
218 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
219 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
220 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
221 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
222 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
223 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
224 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
225 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
226 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
227 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
228 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
229 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
230 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
231 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
232 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
233 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
234 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
235 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
237 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
238 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
239 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
241 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
243 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
244 EVT_PAINT(wxListCtrl::OnPaint
)
247 // ============================================================================
249 // ============================================================================
251 // ----------------------------------------------------------------------------
252 // wxListCtrl construction
253 // ----------------------------------------------------------------------------
255 void wxListCtrl::Init()
257 m_imageListNormal
= NULL
;
258 m_imageListSmall
= NULL
;
259 m_imageListState
= NULL
;
260 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
264 m_hasAnyAttr
= FALSE
;
267 bool wxListCtrl::Create(wxWindow
*parent
,
272 const wxValidator
& validator
,
273 const wxString
& name
)
276 SetValidator(validator
);
277 #endif // wxUSE_VALIDATORS
286 m_windowStyle
= style
;
299 m_windowId
= (id
== -1) ? NewControlId() : id
;
301 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
302 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
304 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
305 wstyle
|= WS_CLIPSIBLINGS
;
307 if ( wxStyleHasBorder(m_windowStyle
) )
309 m_baseStyle
= wstyle
;
311 if ( !DoCreateControl(x
, y
, width
, height
) )
315 parent
->AddChild(this);
320 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
322 DWORD wstyle
= m_baseStyle
;
325 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
327 // Even with extended styles, need to combine with WS_BORDER
328 // for them to look right.
332 long oldStyle
= 0; // Dummy
333 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
335 // Create the ListView control.
336 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
341 GetWinHwnd(GetParent()),
348 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
353 // for comctl32.dll v 4.70+ we want to have this attribute because it's
354 // prettier (and also because wxGTK does it like this)
355 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
357 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
358 0, LVS_EX_FULLROWSELECT
);
361 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
362 SetForegroundColour(GetParent()->GetForegroundColour());
369 void wxListCtrl::UpdateStyle()
373 // The new window view style
375 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
376 dwStyleNew
|= m_baseStyle
;
378 // Get the current window style.
379 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
381 // Only set the window style if the view bits have changed.
382 if ( dwStyleOld
!= dwStyleNew
)
384 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
389 void wxListCtrl::FreeAllAttrs(bool dontRecreate
)
393 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
395 delete (wxListItemAttr
*)node
->Data();
401 m_attrs
.Create(wxKEY_INTEGER
, 1000); // just as def ctor
404 m_hasAnyAttr
= FALSE
;
408 wxListCtrl::~wxListCtrl()
410 FreeAllAttrs(TRUE
/* no need to recreate hash any more */);
414 m_textCtrl
->SetHWND(0);
415 m_textCtrl
->UnsubclassWin();
420 if (m_ownsImageListNormal
) delete m_imageListNormal
;
421 if (m_ownsImageListSmall
) delete m_imageListSmall
;
422 if (m_ownsImageListState
) delete m_imageListState
;
425 // ----------------------------------------------------------------------------
426 // set/get/change style
427 // ----------------------------------------------------------------------------
429 // Add or remove a single window style
430 void wxListCtrl::SetSingleStyle(long style
, bool add
)
432 long flag
= GetWindowStyleFlag();
434 // Get rid of conflicting styles
437 if ( style
& wxLC_MASK_TYPE
)
438 flag
= flag
& ~wxLC_MASK_TYPE
;
439 if ( style
& wxLC_MASK_ALIGN
)
440 flag
= flag
& ~wxLC_MASK_ALIGN
;
441 if ( style
& wxLC_MASK_SORT
)
442 flag
= flag
& ~wxLC_MASK_SORT
;
458 m_windowStyle
= flag
;
463 // Set the whole window style
464 void wxListCtrl::SetWindowStyleFlag(long flag
)
466 m_windowStyle
= flag
;
471 // Can be just a single style, or a bitlist
472 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
475 if ( style
& wxLC_ICON
)
477 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
478 oldStyle
-= LVS_SMALLICON
;
479 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
480 oldStyle
-= LVS_REPORT
;
481 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
482 oldStyle
-= LVS_LIST
;
486 if ( style
& wxLC_SMALL_ICON
)
488 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
489 oldStyle
-= LVS_ICON
;
490 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
491 oldStyle
-= LVS_REPORT
;
492 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
493 oldStyle
-= LVS_LIST
;
494 wstyle
|= LVS_SMALLICON
;
497 if ( style
& wxLC_LIST
)
499 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
500 oldStyle
-= LVS_ICON
;
501 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
502 oldStyle
-= LVS_REPORT
;
503 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
504 oldStyle
-= LVS_SMALLICON
;
508 if ( style
& wxLC_REPORT
)
510 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
511 oldStyle
-= LVS_ICON
;
512 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
513 oldStyle
-= LVS_LIST
;
514 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
515 oldStyle
-= LVS_SMALLICON
;
517 wstyle
|= LVS_REPORT
;
520 if ( style
& wxLC_ALIGN_LEFT
)
522 if ( oldStyle
& LVS_ALIGNTOP
)
523 oldStyle
-= LVS_ALIGNTOP
;
524 wstyle
|= LVS_ALIGNLEFT
;
527 if ( style
& wxLC_ALIGN_TOP
)
529 if ( oldStyle
& LVS_ALIGNLEFT
)
530 oldStyle
-= LVS_ALIGNLEFT
;
531 wstyle
|= LVS_ALIGNTOP
;
534 if ( style
& wxLC_AUTOARRANGE
)
535 wstyle
|= LVS_AUTOARRANGE
;
537 if ( style
& wxLC_NO_SORT_HEADER
)
538 wstyle
|= LVS_NOSORTHEADER
;
540 if ( style
& wxLC_NO_HEADER
)
541 wstyle
|= LVS_NOCOLUMNHEADER
;
543 if ( style
& wxLC_EDIT_LABELS
)
544 wstyle
|= LVS_EDITLABELS
;
546 if ( style
& wxLC_SINGLE_SEL
)
547 wstyle
|= LVS_SINGLESEL
;
549 if ( style
& wxLC_SORT_ASCENDING
)
551 if ( oldStyle
& LVS_SORTDESCENDING
)
552 oldStyle
-= LVS_SORTDESCENDING
;
553 wstyle
|= LVS_SORTASCENDING
;
556 if ( style
& wxLC_SORT_DESCENDING
)
558 if ( oldStyle
& LVS_SORTASCENDING
)
559 oldStyle
-= LVS_SORTASCENDING
;
560 wstyle
|= LVS_SORTDESCENDING
;
563 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
564 if ( style
& wxLC_VIRTUAL
)
566 int ver
= wxTheApp
->GetComCtl32Version();
569 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."),
570 ver
/ 100, ver
% 100);
573 wstyle
|= LVS_OWNERDATA
;
580 // ----------------------------------------------------------------------------
582 // ----------------------------------------------------------------------------
584 // Sets the foreground, i.e. text, colour
585 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
587 if ( !wxWindow::SetForegroundColour(col
) )
590 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
595 // Sets the background colour
596 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
598 if ( !wxWindow::SetBackgroundColour(col
) )
601 // we set the same colour for both the "empty" background and the items
603 COLORREF color
= wxColourToRGB(col
);
604 ListView_SetBkColor(GetHwnd(), color
);
605 ListView_SetTextBkColor(GetHwnd(), color
);
610 // Gets information about this column
611 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
616 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
618 lvCol
.mask
|= LVCF_TEXT
;
619 lvCol
.pszText
= new wxChar
[513];
620 lvCol
.cchTextMax
= 512;
623 bool success
= ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0;
625 // item.m_subItem = lvCol.iSubItem;
626 item
.m_width
= lvCol
.cx
;
628 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
630 item
.m_text
= lvCol
.pszText
;
631 delete[] lvCol
.pszText
;
634 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
636 if (lvCol
.fmt
== LVCFMT_LEFT
)
637 item
.m_format
= wxLIST_FORMAT_LEFT
;
638 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
639 item
.m_format
= wxLIST_FORMAT_RIGHT
;
640 else if (lvCol
.fmt
== LVCFMT_CENTER
)
641 item
.m_format
= wxLIST_FORMAT_CENTRE
;
647 // Sets information about this column
648 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
651 wxConvertToMSWListCol(col
, item
, lvCol
);
653 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
656 // Gets the column width
657 int wxListCtrl::GetColumnWidth(int col
) const
659 return ListView_GetColumnWidth(GetHwnd(), col
);
662 // Sets the column width
663 bool wxListCtrl::SetColumnWidth(int col
, int width
)
666 if ( m_windowStyle
& wxLC_LIST
)
670 if ( width2
== wxLIST_AUTOSIZE
)
671 width2
= LVSCW_AUTOSIZE
;
672 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
673 width2
= LVSCW_AUTOSIZE_USEHEADER
;
675 return ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0;
678 // Gets the number of items that can fit vertically in the
679 // visible area of the list control (list or report view)
680 // or the total number of items in the list control (icon
681 // or small icon view)
682 int wxListCtrl::GetCountPerPage() const
684 return ListView_GetCountPerPage(GetHwnd());
687 // Gets the edit control for editing labels.
688 wxTextCtrl
* wxListCtrl::GetEditControl() const
693 // Gets information about the item
694 bool wxListCtrl::GetItem(wxListItem
& info
) const
697 wxZeroMemory(lvItem
);
699 lvItem
.iItem
= info
.m_itemId
;
700 lvItem
.iSubItem
= info
.m_col
;
702 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
704 lvItem
.mask
|= LVIF_TEXT
;
705 lvItem
.pszText
= new wxChar
[513];
706 lvItem
.cchTextMax
= 512;
710 lvItem
.pszText
= NULL
;
713 if (info
.m_mask
& wxLIST_MASK_DATA
)
714 lvItem
.mask
|= LVIF_PARAM
;
716 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
717 lvItem
.mask
|= LVIF_IMAGE
;
719 if ( info
.m_mask
& wxLIST_MASK_STATE
)
721 lvItem
.mask
|= LVIF_STATE
;
722 // the other bits are hardly interesting anyhow
723 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
726 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
729 wxLogError(_("Couldn't retrieve information about list control item %d."),
734 // give NULL as hwnd as we already have everything we need
735 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
739 delete[] lvItem
.pszText
;
744 // Sets information about the item
745 bool wxListCtrl::SetItem(wxListItem
& info
)
748 wxConvertToMSWListItem(this, info
, item
);
750 // we could be changing only the attribute in which case we don't need to
751 // call ListView_SetItem() at all
755 if ( !ListView_SetItem(GetHwnd(), &item
) )
757 wxLogDebug(_T("ListView_SetItem() failed"));
763 // we need to update the item immediately to show the new image
764 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
766 // check whether it has any custom attributes
767 if ( info
.HasAttributes() )
769 wxListItemAttr
*attr
= (wxListItemAttr
*)m_attrs
.Get(item
.iItem
);
772 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
774 *attr
= *info
.GetAttributes();
778 // if the colour has changed, we must redraw the item
784 // we need this to make the change visible right now
785 RefreshItem(item
.iItem
);
791 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
795 info
.m_mask
= wxLIST_MASK_TEXT
;
796 info
.m_itemId
= index
;
800 info
.m_image
= imageId
;
801 info
.m_mask
|= wxLIST_MASK_IMAGE
;
803 return SetItem(info
);
807 // Gets the item state
808 int wxListCtrl::GetItemState(long item
, long stateMask
) const
812 info
.m_mask
= wxLIST_MASK_STATE
;
813 info
.m_stateMask
= stateMask
;
814 info
.m_itemId
= item
;
822 // Sets the item state
823 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
825 // NB: don't use SetItem() here as it doesn't work with the virtual list
828 wxZeroMemory(lvItem
);
830 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
832 // for the virtual list controls we need to refresh the previously focused
833 // item manually when changing focus without changing selection
834 // programmatically because otherwise it keeps its focus rectangle until
835 // next repaint (yet another comctl32 bug)
838 (stateMask
& wxLIST_STATE_FOCUSED
) &&
839 (state
& wxLIST_STATE_FOCUSED
) )
841 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
848 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
849 (WPARAM
)item
, (LPARAM
)&lvItem
) )
851 wxLogLastError(_T("ListView_SetItemState"));
856 if ( focusOld
!= -1 )
858 // no need to refresh the item if it was previously selected, it would
859 // only result in annoying flicker
860 if ( !(GetItemState(focusOld
,
861 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
863 RefreshItem(focusOld
);
870 // Sets the item image
871 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
875 info
.m_mask
= wxLIST_MASK_IMAGE
;
876 info
.m_image
= image
;
877 info
.m_itemId
= item
;
879 return SetItem(info
);
882 // Gets the item text
883 wxString
wxListCtrl::GetItemText(long item
) const
887 info
.m_mask
= wxLIST_MASK_TEXT
;
888 info
.m_itemId
= item
;
895 // Sets the item text
896 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
900 info
.m_mask
= wxLIST_MASK_TEXT
;
901 info
.m_itemId
= item
;
907 // Gets the item data
908 long wxListCtrl::GetItemData(long item
) const
912 info
.m_mask
= wxLIST_MASK_DATA
;
913 info
.m_itemId
= item
;
920 // Sets the item data
921 bool wxListCtrl::SetItemData(long item
, long data
)
925 info
.m_mask
= wxLIST_MASK_DATA
;
926 info
.m_itemId
= item
;
929 return SetItem(info
);
932 // Gets the item rectangle
933 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
938 if ( code
== wxLIST_RECT_BOUNDS
)
939 codeWin
= LVIR_BOUNDS
;
940 else if ( code
== wxLIST_RECT_ICON
)
942 else if ( code
== wxLIST_RECT_LABEL
)
943 codeWin
= LVIR_LABEL
;
946 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
948 codeWin
= LVIR_BOUNDS
;
952 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
) != 0;
954 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
957 rect
.x
= rectWin
.left
;
958 rect
.y
= rectWin
.top
;
959 rect
.width
= rectWin
.right
- rectWin
.left
;
960 rect
.height
= rectWin
.bottom
- rectWin
.top
;
965 // Gets the item position
966 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
970 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
972 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
976 // Sets the item position.
977 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
979 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
982 // Gets the number of items in the list control
983 int wxListCtrl::GetItemCount() const
985 return ListView_GetItemCount(GetHwnd());
988 // Retrieves the spacing between icons in pixels.
989 // If small is TRUE, gets the spacing for the small icon
990 // view, otherwise the large icon view.
991 int wxListCtrl::GetItemSpacing(bool isSmall
) const
993 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
996 // Gets the number of selected items in the list control
997 int wxListCtrl::GetSelectedItemCount() const
999 return ListView_GetSelectedCount(GetHwnd());
1002 // Gets the text colour of the listview
1003 wxColour
wxListCtrl::GetTextColour() const
1005 COLORREF ref
= ListView_GetTextColor(GetHwnd());
1006 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
1010 // Sets the text colour of the listview
1011 void wxListCtrl::SetTextColour(const wxColour
& col
)
1013 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
1016 // Gets the index of the topmost visible item when in
1017 // list or report view
1018 long wxListCtrl::GetTopItem() const
1020 return (long) ListView_GetTopIndex(GetHwnd());
1023 // Searches for an item, starting from 'item'.
1024 // 'geometry' is one of
1025 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1026 // 'state' is a state bit flag, one or more of
1027 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1028 // item can be -1 to find the first item that matches the
1030 // Returns the item or -1 if unsuccessful.
1031 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1035 if ( geom
== wxLIST_NEXT_ABOVE
)
1036 flags
|= LVNI_ABOVE
;
1037 if ( geom
== wxLIST_NEXT_ALL
)
1039 if ( geom
== wxLIST_NEXT_BELOW
)
1040 flags
|= LVNI_BELOW
;
1041 if ( geom
== wxLIST_NEXT_LEFT
)
1042 flags
|= LVNI_TOLEFT
;
1043 if ( geom
== wxLIST_NEXT_RIGHT
)
1044 flags
|= LVNI_TORIGHT
;
1046 if ( state
& wxLIST_STATE_CUT
)
1048 if ( state
& wxLIST_STATE_DROPHILITED
)
1049 flags
|= LVNI_DROPHILITED
;
1050 if ( state
& wxLIST_STATE_FOCUSED
)
1051 flags
|= LVNI_FOCUSED
;
1052 if ( state
& wxLIST_STATE_SELECTED
)
1053 flags
|= LVNI_SELECTED
;
1055 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1059 wxImageList
*wxListCtrl::GetImageList(int which
) const
1061 if ( which
== wxIMAGE_LIST_NORMAL
)
1063 return m_imageListNormal
;
1065 else if ( which
== wxIMAGE_LIST_SMALL
)
1067 return m_imageListSmall
;
1069 else if ( which
== wxIMAGE_LIST_STATE
)
1071 return m_imageListState
;
1076 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1079 if ( which
== wxIMAGE_LIST_NORMAL
)
1081 flags
= LVSIL_NORMAL
;
1082 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1083 m_imageListNormal
= imageList
;
1084 m_ownsImageListNormal
= FALSE
;
1086 else if ( which
== wxIMAGE_LIST_SMALL
)
1088 flags
= LVSIL_SMALL
;
1089 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1090 m_imageListSmall
= imageList
;
1091 m_ownsImageListSmall
= FALSE
;
1093 else if ( which
== wxIMAGE_LIST_STATE
)
1095 flags
= LVSIL_STATE
;
1096 if (m_ownsImageListState
) delete m_imageListState
;
1097 m_imageListState
= imageList
;
1098 m_ownsImageListState
= FALSE
;
1100 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1103 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1105 SetImageList(imageList
, which
);
1106 if ( which
== wxIMAGE_LIST_NORMAL
)
1107 m_ownsImageListNormal
= TRUE
;
1108 else if ( which
== wxIMAGE_LIST_SMALL
)
1109 m_ownsImageListSmall
= TRUE
;
1110 else if ( which
== wxIMAGE_LIST_STATE
)
1111 m_ownsImageListState
= TRUE
;
1114 // ----------------------------------------------------------------------------
1116 // ----------------------------------------------------------------------------
1118 // Arranges the items
1119 bool wxListCtrl::Arrange(int flag
)
1122 if ( flag
== wxLIST_ALIGN_LEFT
)
1123 code
= LVA_ALIGNLEFT
;
1124 else if ( flag
== wxLIST_ALIGN_TOP
)
1125 code
= LVA_ALIGNTOP
;
1126 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1128 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1129 code
= LVA_SNAPTOGRID
;
1131 return (ListView_Arrange(GetHwnd(), code
) != 0);
1135 bool wxListCtrl::DeleteItem(long item
)
1137 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1139 wxLogLastError(_T("ListView_DeleteItem"));
1143 // the virtual list control doesn't refresh itself correctly, help it
1146 // we need to refresh all the lines below the one which was deleted
1148 if ( item
> 0 && GetItemCount() )
1150 GetItemRect(item
- 1, rectItem
);
1155 rectItem
.height
= 0;
1158 wxRect rectWin
= GetRect();
1159 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1160 rectWin
.y
= rectItem
.GetBottom();
1162 RefreshRect(rectWin
);
1168 // Deletes all items
1169 bool wxListCtrl::DeleteAllItems()
1171 return ListView_DeleteAllItems(GetHwnd()) != 0;
1174 // Deletes all items
1175 bool wxListCtrl::DeleteAllColumns()
1177 while ( m_colCount
> 0 )
1179 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1181 wxLogLastError(wxT("ListView_DeleteColumn"));
1189 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1195 bool wxListCtrl::DeleteColumn(int col
)
1197 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1199 if ( success
&& (m_colCount
> 0) )
1204 // Clears items, and columns if there are any.
1205 void wxListCtrl::ClearAll()
1208 if ( m_colCount
> 0 )
1212 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1214 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1216 // VS: ListView_EditLabel requires that the list has focus.
1218 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
1222 m_textCtrl
->SetHWND(0);
1223 m_textCtrl
->UnsubclassWin();
1228 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1229 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1230 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1235 // End label editing, optionally cancelling the edit
1236 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1238 wxFAIL_MSG( _T("not implemented") );
1243 // Ensures this item is visible
1244 bool wxListCtrl::EnsureVisible(long item
)
1246 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0;
1249 // Find an item whose label matches this string, starting from the item after 'start'
1250 // or the beginning if 'start' is -1.
1251 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1253 LV_FINDINFO findInfo
;
1255 findInfo
.flags
= LVFI_STRING
;
1257 findInfo
.flags
|= LVFI_PARTIAL
;
1260 // ListView_FindItem() excludes the first item from search and to look
1261 // through all the items you need to start from -1 which is unnatural and
1262 // inconsistent with the generic version - so we adjust the index
1265 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1268 // Find an item whose data matches this data, starting from the item after 'start'
1269 // or the beginning if 'start' is -1.
1270 long wxListCtrl::FindItem(long start
, long data
)
1272 LV_FINDINFO findInfo
;
1274 findInfo
.flags
= LVFI_PARAM
;
1275 findInfo
.lParam
= data
;
1277 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1280 // Find an item nearest this position in the specified direction, starting from
1281 // the item after 'start' or the beginning if 'start' is -1.
1282 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1284 LV_FINDINFO findInfo
;
1286 findInfo
.flags
= LVFI_NEARESTXY
;
1287 findInfo
.pt
.x
= pt
.x
;
1288 findInfo
.pt
.y
= pt
.y
;
1289 findInfo
.vkDirection
= VK_RIGHT
;
1291 if ( direction
== wxLIST_FIND_UP
)
1292 findInfo
.vkDirection
= VK_UP
;
1293 else if ( direction
== wxLIST_FIND_DOWN
)
1294 findInfo
.vkDirection
= VK_DOWN
;
1295 else if ( direction
== wxLIST_FIND_LEFT
)
1296 findInfo
.vkDirection
= VK_LEFT
;
1297 else if ( direction
== wxLIST_FIND_RIGHT
)
1298 findInfo
.vkDirection
= VK_RIGHT
;
1300 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1303 // Determines which item (if any) is at the specified point,
1304 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1305 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1307 LV_HITTESTINFO hitTestInfo
;
1308 hitTestInfo
.pt
.x
= (int) point
.x
;
1309 hitTestInfo
.pt
.y
= (int) point
.y
;
1311 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1314 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1315 flags
|= wxLIST_HITTEST_ABOVE
;
1316 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1317 flags
|= wxLIST_HITTEST_BELOW
;
1318 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1319 flags
|= wxLIST_HITTEST_NOWHERE
;
1320 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1321 flags
|= wxLIST_HITTEST_ONITEMICON
;
1322 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1323 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1324 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1325 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1326 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1327 flags
|= wxLIST_HITTEST_TOLEFT
;
1328 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1329 flags
|= wxLIST_HITTEST_TORIGHT
;
1331 return (long) hitTestInfo
.iItem
;
1334 // Inserts an item, returning the index of the new item if successful,
1336 long wxListCtrl::InsertItem(wxListItem
& info
)
1338 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1341 wxConvertToMSWListItem(this, info
, item
);
1343 // check whether it has any custom attributes
1344 if ( info
.HasAttributes() )
1347 wxListItemAttr
*attr
;
1348 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
1352 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1354 else *attr
= *info
.GetAttributes();
1356 m_hasAnyAttr
= TRUE
;
1359 return (long) ListView_InsertItem(GetHwnd(), & item
);
1362 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1365 info
.m_text
= label
;
1366 info
.m_mask
= wxLIST_MASK_TEXT
;
1367 info
.m_itemId
= index
;
1368 return InsertItem(info
);
1371 // Inserts an image item
1372 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1375 info
.m_image
= imageIndex
;
1376 info
.m_mask
= wxLIST_MASK_IMAGE
;
1377 info
.m_itemId
= index
;
1378 return InsertItem(info
);
1381 // Inserts an image/string item
1382 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1385 info
.m_image
= imageIndex
;
1386 info
.m_text
= label
;
1387 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1388 info
.m_itemId
= index
;
1389 return InsertItem(info
);
1392 // For list view mode (only), inserts a column.
1393 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1396 wxConvertToMSWListCol(col
, item
, lvCol
);
1398 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1400 // always give some width to the new column: this one is compatible
1401 // with the generic version
1402 lvCol
.mask
|= LVCF_WIDTH
;
1406 // when we insert a column which can contain an image, we must specify this
1407 // flag right now as doing it later in SetColumn() has no effect
1409 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1410 // way to dynamically set/clear the bitmap as the column without a bitmap
1411 // on the left looks ugly (there is a hole)
1413 // unfortunately with my version of comctl32.dll (5.80), the left column
1414 // image is always on the left and it seems that it's a "feature" - I
1415 // didn't find any way to work around it in any case
1416 if ( lvCol
.mask
& LVCF_IMAGE
)
1418 lvCol
.mask
|= LVCF_FMT
;
1419 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
;
1422 bool success
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
) != -1;
1429 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1436 long wxListCtrl::InsertColumn(long col
,
1437 const wxString
& heading
,
1442 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1443 item
.m_text
= heading
;
1446 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1447 item
.m_width
= width
;
1449 item
.m_format
= format
;
1451 return InsertColumn(col
, item
);
1454 // Scrolls the list control. If in icon, small icon or report view mode,
1455 // x specifies the number of pixels to scroll. If in list view mode, x
1456 // specifies the number of columns to scroll.
1457 // If in icon, small icon or list view mode, y specifies the number of pixels
1458 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1459 bool wxListCtrl::ScrollList(int dx
, int dy
)
1461 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1466 // fn is a function which takes 3 long arguments: item1, item2, data.
1467 // item1 is the long data associated with a first item (NOT the index).
1468 // item2 is the long data associated with a second item (NOT the index).
1469 // data is the same value as passed to SortItems.
1470 // The return value is a negative number if the first item should precede the second
1471 // item, a positive number of the second item should precede the first,
1472 // or zero if the two items are equivalent.
1474 // data is arbitrary data to be passed to the sort function.
1476 // FIXME: this is horrible and MT-unsafe and everything else but I don't have
1477 // time for anything better right now (VZ)
1478 static long gs_sortData
= 0;
1479 static wxListCtrl
*gs_sortCtrl
= NULL
;
1480 static wxListCtrlCompare gs_sortFunction
= NULL
;
1482 int wxCMPFUNC_CONV
wxListCtrlCompareFn(const void *arg1
, const void *arg2
)
1484 int n1
= *(const int *)arg1
,
1485 n2
= *(const int *)arg2
;
1487 return gs_sortFunction(gs_sortCtrl
->GetItemData(n1
),
1488 gs_sortCtrl
->GetItemData(n2
),
1492 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1494 // sort the attributes too
1498 count
= GetItemCount();
1499 int *aItems
= new int[count
];
1500 for ( n
= 0; n
< count
; n
++ )
1507 gs_sortFunction
= fn
;
1509 qsort(aItems
, count
, sizeof(int), wxListCtrlCompareFn
);
1513 gs_sortFunction
= NULL
;
1515 wxHashTable
attrsNew(wxKEY_INTEGER
, 1000);
1516 for ( n
= 0; n
< count
; n
++ )
1518 wxObject
*attr
= m_attrs
.Delete(aItems
[n
]);
1521 attrsNew
.Put(n
, attr
);
1531 if ( !ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
)fn
, data
) )
1533 wxLogDebug(_T("ListView_SortItems() failed"));
1543 // ----------------------------------------------------------------------------
1544 // message processing
1545 // ----------------------------------------------------------------------------
1547 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1549 if (cmd
== EN_UPDATE
)
1551 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1552 event
.SetEventObject( this );
1553 ProcessCommand(event
);
1556 else if (cmd
== EN_KILLFOCUS
)
1558 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1559 event
.SetEventObject( this );
1560 ProcessCommand(event
);
1567 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1569 // prepare the event
1570 // -----------------
1572 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1573 event
.SetEventObject(this);
1575 wxEventType eventType
= wxEVT_NULL
;
1577 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1579 // if your compiler is as broken as this, you should really change it: this
1580 // code is needed for normal operation! #ifdef below is only useful for
1581 // automatic rebuilds which are done with a very old compiler version
1582 #ifdef HDN_BEGINTRACKA
1584 // check for messages from the header (in report view)
1585 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1587 // is it a message from the header?
1588 if ( nmhdr
->hwndFrom
== hwndHdr
)
1590 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1592 event
.m_itemIndex
= -1;
1594 switch ( nmhdr
->code
)
1596 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1597 // TRACK messages even to ANSI programs: on my system I get
1598 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1600 // work around is to simply catch both versions and hope that it
1601 // works (why should this message exist in ANSI and Unicode is
1602 // beyond me as it doesn't deal with strings at all...)
1603 case HDN_BEGINTRACKA
:
1604 case HDN_BEGINTRACKW
:
1605 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1610 if ( eventType
== wxEVT_NULL
)
1611 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1616 if ( eventType
== wxEVT_NULL
)
1617 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1618 event
.m_col
= nmHDR
->iItem
;
1623 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1626 // find the column clicked: we have to search for it
1627 // ourselves as the notification message doesn't provide
1630 // where did the click occur?
1632 if ( !::GetCursorPos(&ptClick
) )
1634 wxLogLastError(_T("GetCursorPos"));
1637 if ( !::ScreenToClient(hwndHdr
, &ptClick
) )
1639 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1642 event
.m_pointDrag
.x
= ptClick
.x
;
1643 event
.m_pointDrag
.y
= ptClick
.y
;
1645 int colCount
= Header_GetItemCount(hwndHdr
);
1648 for ( int col
= 0; col
< colCount
; col
++ )
1650 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1652 if ( ::PtInRect(&rect
, ptClick
) )
1663 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1667 #endif // defined(HDN_BEGINTRACKA)
1668 if ( nmhdr
->hwndFrom
== GetHwnd() )
1670 // almost all messages use NM_LISTVIEW
1671 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1673 // this is true for almost all events
1674 event
.m_item
.m_data
= nmLV
->lParam
;
1676 switch ( nmhdr
->code
)
1678 case LVN_BEGINRDRAG
:
1679 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1683 if ( eventType
== wxEVT_NULL
)
1685 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1688 event
.m_itemIndex
= nmLV
->iItem
;
1689 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1690 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1693 // NB: we have to handle both *A and *W versions here because some
1694 // versions of comctl32.dll send ANSI message to an Unicode app
1695 case LVN_BEGINLABELEDITA
:
1697 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1698 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1699 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1700 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1703 case LVN_BEGINLABELEDITW
:
1705 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1706 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1707 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1708 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1712 case LVN_ENDLABELEDITA
:
1714 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1715 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1716 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1717 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1718 ((LV_ITEM
)item
).iItem
== -1 )
1721 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1724 case LVN_ENDLABELEDITW
:
1726 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1727 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1728 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1729 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1730 ((LV_ITEM
)item
).iItem
== -1 )
1733 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1737 case LVN_COLUMNCLICK
:
1738 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1739 event
.m_itemIndex
= -1;
1740 event
.m_col
= nmLV
->iSubItem
;
1743 case LVN_DELETEALLITEMS
:
1744 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1745 event
.m_itemIndex
= -1;
1751 case LVN_DELETEITEM
:
1752 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1753 event
.m_itemIndex
= nmLV
->iItem
;
1757 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1761 case LVN_SETDISPINFO
:
1763 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1764 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1765 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
1769 case LVN_INSERTITEM
:
1770 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1771 event
.m_itemIndex
= nmLV
->iItem
;
1774 case LVN_ITEMCHANGED
:
1775 // we translate this catch all message into more interesting
1776 // (and more easy to process) wxWindows events
1778 // first of all, we deal with the state change events only
1779 if ( nmLV
->uChanged
& LVIF_STATE
)
1781 // temp vars for readability
1782 const UINT stOld
= nmLV
->uOldState
;
1783 const UINT stNew
= nmLV
->uNewState
;
1785 // has the focus changed?
1786 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
1788 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
1789 event
.m_itemIndex
= nmLV
->iItem
;
1792 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
1794 if ( eventType
!= wxEVT_NULL
)
1796 // focus and selection have both changed: send the
1797 // focus event from here and the selection one
1799 event
.SetEventType(eventType
);
1800 (void)GetEventHandler()->ProcessEvent(event
);
1802 else // no focus event to send
1804 // then need to set m_itemIndex as it wasn't done
1806 event
.m_itemIndex
= nmLV
->iItem
;
1809 eventType
= stNew
& LVIS_SELECTED
1810 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1811 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1815 if ( eventType
== wxEVT_NULL
)
1817 // not an interesting event for us
1825 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1826 WORD wVKey
= info
->wVKey
;
1828 // get the current selection
1829 long lItem
= GetNextItem(-1,
1831 wxLIST_STATE_SELECTED
);
1833 // <Enter> or <Space> activate the selected item if any (but
1834 // not with Shift and/or Ctrl as then they have a predefined
1835 // meaning for the list view)
1837 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
1838 !(wxIsShiftDown() || wxIsCtrlDown()) )
1840 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1844 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1846 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1847 // value which should be used as is
1848 int code
= wxCharCodeMSWToWX(wVKey
);
1849 event
.m_code
= code
? code
: wVKey
;
1853 event
.m_item
.m_itemId
= lItem
;
1857 // fill the other fields too
1858 event
.m_item
.m_text
= GetItemText(lItem
);
1859 event
.m_item
.m_data
= GetItemData(lItem
);
1865 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1867 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1872 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1873 // if it happened on an item (and not on empty place)
1874 if ( nmLV
->iItem
== -1 )
1880 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1881 event
.m_itemIndex
= nmLV
->iItem
;
1882 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1883 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1887 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1888 // don't do anything else
1889 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1894 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1895 LV_HITTESTINFO lvhti
;
1896 wxZeroMemory(lvhti
);
1898 ::GetCursorPos(&(lvhti
.pt
));
1899 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1900 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1902 if ( lvhti
.flags
& LVHT_ONITEM
)
1904 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1905 event
.m_itemIndex
= lvhti
.iItem
;
1906 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
1907 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
1912 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1913 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
1915 *result
= OnCustomDraw(lParam
);
1918 #endif // _WIN32_IE >= 0x300
1920 case LVN_ODCACHEHINT
:
1922 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
1924 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
1926 // we get some really stupid cache hints like ones for items in
1927 // range 0..0 for an empty control or, after deleting an item,
1928 // for items in invalid range - filter this garbage out
1929 if ( cacheHint
->iFrom
< cacheHint
->iTo
)
1931 event
.m_oldItemIndex
= cacheHint
->iFrom
;
1933 long iMax
= GetItemCount();
1934 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
1944 case LVN_GETDISPINFO
:
1947 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1949 LV_ITEM
& lvi
= info
->item
;
1950 long item
= lvi
.iItem
;
1952 if ( lvi
.mask
& LVIF_TEXT
)
1954 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
1955 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
1958 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1959 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
1960 if ( lvi
.mask
& LVIF_IMAGE
)
1962 lvi
.iImage
= OnGetItemImage(item
);
1966 // a little dose of healthy paranoia: as we never use
1967 // LVM_SETCALLBACKMASK we're not supposed to get these ones
1968 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
1969 _T("we don't support state callbacks yet!") );
1976 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1981 // where did this one come from?
1985 // process the event
1986 // -----------------
1988 event
.SetEventType(eventType
);
1990 if ( !GetEventHandler()->ProcessEvent(event
) )
1996 switch ( nmhdr
->code
)
1998 case LVN_DELETEALLITEMS
:
1999 // always return TRUE to suppress all additional LVN_DELETEITEM
2000 // notifications - this makes deleting all items from a list ctrl
2006 case LVN_ENDLABELEDITA
:
2007 case LVN_ENDLABELEDITW
:
2008 // logic here is inversed compared to all the other messages
2009 *result
= event
.IsAllowed();
2014 *result
= !event
.IsAllowed();
2019 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
2021 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
2023 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
2024 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
2025 switch ( nmcd
.dwDrawStage
)
2028 // if we've got any items with non standard attributes,
2029 // notify us before painting each item
2031 // for virtual controls, always suppose that we have attributes as
2032 // there is no way to check for this
2033 return IsVirtual() || m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
2036 case CDDS_ITEMPREPAINT
:
2038 size_t item
= (size_t)nmcd
.dwItemSpec
;
2039 if ( item
>= (size_t)GetItemCount() )
2041 // we get this message with item == 0 for an empty control,
2042 // we must ignore it as calling OnGetItemAttr() would be
2044 return CDRF_DODEFAULT
;
2047 wxListItemAttr
*attr
=
2048 IsVirtual() ? OnGetItemAttr(item
)
2049 : (wxListItemAttr
*)m_attrs
.Get(item
);
2053 // nothing to do for this item
2054 return CDRF_DODEFAULT
;
2058 wxColour colText
, colBack
;
2059 if ( attr
->HasFont() )
2061 wxFont font
= attr
->GetFont();
2062 hFont
= (HFONT
)font
.GetResourceHandle();
2069 if ( attr
->HasTextColour() )
2071 colText
= attr
->GetTextColour();
2075 colText
= GetTextColour();
2078 if ( attr
->HasBackgroundColour() )
2080 colBack
= attr
->GetBackgroundColour();
2084 colBack
= GetBackgroundColour();
2087 lplvcd
->clrText
= wxColourToRGB(colText
);
2088 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
2090 // note that if we wanted to set colours for
2091 // individual columns (subitems), we would have
2092 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2095 ::SelectObject(nmcd
.hdc
, hFont
);
2097 return CDRF_NEWFONT
;
2100 // fall through to return CDRF_DODEFAULT
2103 return CDRF_DODEFAULT
;
2107 #endif // NM_CUSTOMDRAW supported
2109 // Necessary for drawing hrules and vrules, if specified
2110 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2114 wxControl::OnPaint(event
);
2116 // Reset the device origin since it may have been set
2117 dc
.SetDeviceOrigin(0, 0);
2119 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
2120 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
2122 if (!drawHRules
&& !drawVRules
)
2124 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
2127 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2129 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2131 wxSize clientSize
= GetClientSize();
2135 int itemCount
= GetItemCount();
2139 long top
= GetTopItem();
2140 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2142 if (GetItemRect(i
, itemRect
))
2144 cy
= itemRect
.GetTop();
2145 if (i
!= 0) // Don't draw the first one
2147 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2150 if (i
== itemCount
- 1)
2152 cy
= itemRect
.GetBottom();
2153 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2159 if (drawVRules
&& (i
> -1))
2161 wxRect firstItemRect
;
2162 GetItemRect(0, firstItemRect
);
2164 if (GetItemRect(i
, itemRect
))
2167 int x
= itemRect
.GetX();
2168 for (col
= 0; col
< GetColumnCount(); col
++)
2170 int colWidth
= GetColumnWidth(col
);
2172 dc
.DrawLine(x
, firstItemRect
.GetY() - 2, x
, itemRect
.GetBottom());
2178 // ----------------------------------------------------------------------------
2179 // virtual list controls
2180 // ----------------------------------------------------------------------------
2182 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2184 // this is a pure virtual function, in fact - which is not really pure
2185 // because the controls which are not virtual don't need to implement it
2186 wxFAIL_MSG( _T("not supposed to be called") );
2188 return wxEmptyString
;
2191 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2194 wxFAIL_MSG( _T("not supposed to be called") );
2199 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2201 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2202 _T("invalid item index in OnGetItemAttr()") );
2204 // no attributes by default
2208 void wxListCtrl::SetItemCount(long count
)
2210 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2212 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
, 0) )
2214 wxLogLastError(_T("ListView_SetItemCount"));
2218 void wxListCtrl::RefreshItem(long item
)
2220 // strangely enough, ListView_Update() results in much more flicker here
2221 // than a dumb Refresh() -- why?
2223 if ( !ListView_Update(GetHwnd(), item
) )
2225 wxLogLastError(_T("ListView_Update"));
2229 GetItemRect(item
, rect
);
2234 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2236 wxRect rect1
, rect2
;
2237 GetItemRect(itemFrom
, rect1
);
2238 GetItemRect(itemTo
, rect2
);
2240 wxRect rect
= rect1
;
2241 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2246 // ----------------------------------------------------------------------------
2248 // ----------------------------------------------------------------------------
2250 // List item structure
2251 wxListItem::wxListItem()
2261 m_format
= wxLIST_FORMAT_CENTRE
;
2267 void wxListItem::Clear()
2276 m_format
= wxLIST_FORMAT_CENTRE
;
2278 m_text
= wxEmptyString
;
2280 if (m_attr
) delete m_attr
;
2284 void wxListItem::ClearAttributes()
2286 if (m_attr
) delete m_attr
;
2290 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2294 info
.m_data
= lvItem
.lParam
;
2297 info
.m_stateMask
= 0;
2298 info
.m_itemId
= lvItem
.iItem
;
2300 long oldMask
= lvItem
.mask
;
2302 bool needText
= FALSE
;
2303 if (hwndListCtrl
!= 0)
2305 if ( lvItem
.mask
& LVIF_TEXT
)
2312 lvItem
.pszText
= new wxChar
[513];
2313 lvItem
.cchTextMax
= 512;
2315 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2316 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2319 if ( lvItem
.mask
& LVIF_STATE
)
2321 info
.m_mask
|= wxLIST_MASK_STATE
;
2323 if ( lvItem
.stateMask
& LVIS_CUT
)
2325 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2326 if ( lvItem
.state
& LVIS_CUT
)
2327 info
.m_state
|= wxLIST_STATE_CUT
;
2329 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2331 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2332 if ( lvItem
.state
& LVIS_DROPHILITED
)
2333 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2335 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2337 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2338 if ( lvItem
.state
& LVIS_FOCUSED
)
2339 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2341 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2343 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2344 if ( lvItem
.state
& LVIS_SELECTED
)
2345 info
.m_state
|= wxLIST_STATE_SELECTED
;
2349 if ( lvItem
.mask
& LVIF_TEXT
)
2351 info
.m_mask
|= wxLIST_MASK_TEXT
;
2352 info
.m_text
= lvItem
.pszText
;
2354 if ( lvItem
.mask
& LVIF_IMAGE
)
2356 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2357 info
.m_image
= lvItem
.iImage
;
2359 if ( lvItem
.mask
& LVIF_PARAM
)
2360 info
.m_mask
|= wxLIST_MASK_DATA
;
2361 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2362 info
.m_mask
|= wxLIST_SET_ITEM
;
2363 info
.m_col
= lvItem
.iSubItem
;
2368 delete[] lvItem
.pszText
;
2370 lvItem
.mask
= oldMask
;
2373 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2375 if (stateMask
& wxLIST_STATE_CUT
)
2377 lvItem
.stateMask
|= LVIS_CUT
;
2378 if (state
& wxLIST_STATE_CUT
)
2379 lvItem
.state
|= LVIS_CUT
;
2381 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2383 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2384 if (state
& wxLIST_STATE_DROPHILITED
)
2385 lvItem
.state
|= LVIS_DROPHILITED
;
2387 if (stateMask
& wxLIST_STATE_FOCUSED
)
2389 lvItem
.stateMask
|= LVIS_FOCUSED
;
2390 if (state
& wxLIST_STATE_FOCUSED
)
2391 lvItem
.state
|= LVIS_FOCUSED
;
2393 if (stateMask
& wxLIST_STATE_SELECTED
)
2395 lvItem
.stateMask
|= LVIS_SELECTED
;
2396 if (state
& wxLIST_STATE_SELECTED
)
2397 lvItem
.state
|= LVIS_SELECTED
;
2401 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2402 const wxListItem
& info
,
2405 lvItem
.iItem
= (int) info
.m_itemId
;
2407 lvItem
.iImage
= info
.m_image
;
2408 lvItem
.lParam
= info
.m_data
;
2409 lvItem
.stateMask
= 0;
2412 lvItem
.iSubItem
= info
.m_col
;
2414 if (info
.m_mask
& wxLIST_MASK_STATE
)
2416 lvItem
.mask
|= LVIF_STATE
;
2418 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2421 if (info
.m_mask
& wxLIST_MASK_TEXT
)
2423 lvItem
.mask
|= LVIF_TEXT
;
2424 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
2426 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
2430 // pszText is not const, hence the cast
2431 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
2432 if ( lvItem
.pszText
)
2433 lvItem
.cchTextMax
= info
.m_text
.Length();
2435 lvItem
.cchTextMax
= 0;
2438 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
2439 lvItem
.mask
|= LVIF_IMAGE
;
2440 if (info
.m_mask
& wxLIST_MASK_DATA
)
2441 lvItem
.mask
|= LVIF_PARAM
;
2444 static void wxConvertToMSWListCol(int WXUNUSED(col
), const wxListItem
& item
,
2447 wxZeroMemory(lvCol
);
2449 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
2451 lvCol
.mask
|= LVCF_TEXT
;
2452 lvCol
.pszText
= (wxChar
*)item
.m_text
.c_str(); // cast is safe
2455 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
2457 lvCol
.mask
|= LVCF_FMT
;
2459 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
2460 lvCol
.fmt
= LVCFMT_LEFT
;
2461 else if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
2462 lvCol
.fmt
= LVCFMT_RIGHT
;
2463 else if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
2464 lvCol
.fmt
= LVCFMT_CENTER
;
2467 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
2469 lvCol
.mask
|= LVCF_WIDTH
;
2470 if ( item
.m_width
== wxLIST_AUTOSIZE
)
2471 lvCol
.cx
= LVSCW_AUTOSIZE
;
2472 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2473 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
2475 lvCol
.cx
= item
.m_width
;
2478 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2479 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2480 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
2482 if ( wxTheApp
->GetComCtl32Version() >= 470 )
2484 lvCol
.mask
|= LVCF_IMAGE
;
2485 lvCol
.iImage
= item
.m_image
;
2487 //else: it doesn't support item images anyhow
2492 #endif // wxUSE_LISTCTRL