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 #if defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 0, 5 )
141 typedef struct tagNMLVDISPINFOA
{
144 } NMLVDISPINFOA
, FAR
*LPNMLVDISPINFOA
;
145 #define _LV_DISPINFOA tagNMLVDISPINFOA
146 #define LV_DISPINFOA NMLVDISPINFOA
149 typedef struct tagNMLVDISPINFOW
{
152 } NMLVDISPINFOW
, FAR
*LPNMLVDISPINFOW
;
153 #define _LV_DISPINFOW tagNMLVDISPINFOW
154 #define LV_DISPINFOW NMLVDISPINFOW
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 // convert our state and mask flags to LV_ITEM constants
163 static void wxConvertToMSWFlags(long state
, long mask
, LV_ITEM
& lvItem
);
165 // convert wxListItem to LV_ITEM
166 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
167 const wxListItem
& info
, LV_ITEM
& lvItem
);
169 // convert LV_ITEM to wxListItem
170 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
172 /* const */ LV_ITEM
& lvItem
);
174 // convert our wxListItem to LV_COLUMN
175 static void wxConvertToMSWListCol(int col
, const wxListItem
& item
,
178 // ----------------------------------------------------------------------------
179 // private helper classes
180 // ----------------------------------------------------------------------------
182 // We have to handle both fooW and fooA notifications in several cases
183 // because of broken commctl.dll and/or unicows.dll. This class is used to
184 // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
185 // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
186 // by wxConvertToMSWListItem().
190 ~wxLV_ITEM() { delete m_buf
; }
191 operator LV_ITEM
&() const { return *m_item
; }
194 wxLV_ITEM(LV_ITEMW
&item
) : m_buf(NULL
), m_item(&item
) {}
195 wxLV_ITEM(LV_ITEMA
&item
)
197 m_item
= new LV_ITEM((LV_ITEM
&)item
);
198 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
200 m_buf
= new wxMB2WXbuf(wxConvLocal
.cMB2WX(item
.pszText
));
201 m_item
->pszText
= (wxChar
*)m_buf
->data();
210 wxLV_ITEM(LV_ITEMW
&item
)
212 m_item
= new LV_ITEM((LV_ITEM
&)item
);
213 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
215 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX(item
.pszText
));
216 m_item
->pszText
= (wxChar
*)m_buf
->data();
221 wxLV_ITEM(LV_ITEMA
&item
) : m_buf(NULL
), m_item(&item
) {}
229 // ----------------------------------------------------------------------------
231 // ----------------------------------------------------------------------------
233 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
234 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
235 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
236 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
237 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
238 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
239 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
240 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
241 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
242 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
248 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
249 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
250 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
251 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
252 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
253 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
254 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
256 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
257 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
258 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
260 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
262 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
263 EVT_PAINT(wxListCtrl::OnPaint
)
266 // ============================================================================
268 // ============================================================================
270 // ----------------------------------------------------------------------------
271 // wxListCtrl construction
272 // ----------------------------------------------------------------------------
274 void wxListCtrl::Init()
276 m_imageListNormal
= NULL
;
277 m_imageListSmall
= NULL
;
278 m_imageListState
= NULL
;
279 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
283 m_hasAnyAttr
= FALSE
;
286 bool wxListCtrl::Create(wxWindow
*parent
,
291 const wxValidator
& validator
,
292 const wxString
& name
)
295 SetValidator(validator
);
296 #endif // wxUSE_VALIDATORS
305 m_windowStyle
= style
;
318 m_windowId
= (id
== -1) ? NewControlId() : id
;
320 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
321 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
323 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
324 wstyle
|= WS_CLIPSIBLINGS
;
326 if ( wxStyleHasBorder(m_windowStyle
) )
328 m_baseStyle
= wstyle
;
330 if ( !DoCreateControl(x
, y
, width
, height
) )
334 parent
->AddChild(this);
339 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
341 DWORD wstyle
= m_baseStyle
;
344 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
346 // Even with extended styles, need to combine with WS_BORDER
347 // for them to look right.
351 long oldStyle
= 0; // Dummy
352 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
354 // Create the ListView control.
355 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
360 GetWinHwnd(GetParent()),
367 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
372 // for comctl32.dll v 4.70+ we want to have this attribute because it's
373 // prettier (and also because wxGTK does it like this)
374 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
376 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
377 0, LVS_EX_FULLROWSELECT
);
380 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
381 SetForegroundColour(GetParent()->GetForegroundColour());
388 void wxListCtrl::UpdateStyle()
392 // The new window view style
394 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
395 dwStyleNew
|= m_baseStyle
;
397 // Get the current window style.
398 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
400 // Only set the window style if the view bits have changed.
401 if ( dwStyleOld
!= dwStyleNew
)
403 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
408 void wxListCtrl::FreeAllAttrs(bool dontRecreate
)
412 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
414 delete (wxListItemAttr
*)node
->Data();
420 m_attrs
.Create(wxKEY_INTEGER
, 1000); // just as def ctor
423 m_hasAnyAttr
= FALSE
;
427 wxListCtrl::~wxListCtrl()
429 FreeAllAttrs(TRUE
/* no need to recreate hash any more */);
433 m_textCtrl
->SetHWND(0);
434 m_textCtrl
->UnsubclassWin();
439 if (m_ownsImageListNormal
) delete m_imageListNormal
;
440 if (m_ownsImageListSmall
) delete m_imageListSmall
;
441 if (m_ownsImageListState
) delete m_imageListState
;
444 // ----------------------------------------------------------------------------
445 // set/get/change style
446 // ----------------------------------------------------------------------------
448 // Add or remove a single window style
449 void wxListCtrl::SetSingleStyle(long style
, bool add
)
451 long flag
= GetWindowStyleFlag();
453 // Get rid of conflicting styles
456 if ( style
& wxLC_MASK_TYPE
)
457 flag
= flag
& ~wxLC_MASK_TYPE
;
458 if ( style
& wxLC_MASK_ALIGN
)
459 flag
= flag
& ~wxLC_MASK_ALIGN
;
460 if ( style
& wxLC_MASK_SORT
)
461 flag
= flag
& ~wxLC_MASK_SORT
;
477 m_windowStyle
= flag
;
482 // Set the whole window style
483 void wxListCtrl::SetWindowStyleFlag(long flag
)
485 m_windowStyle
= flag
;
490 // Can be just a single style, or a bitlist
491 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
494 if ( style
& wxLC_ICON
)
496 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
497 oldStyle
-= LVS_SMALLICON
;
498 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
499 oldStyle
-= LVS_REPORT
;
500 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
501 oldStyle
-= LVS_LIST
;
505 if ( style
& wxLC_SMALL_ICON
)
507 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
508 oldStyle
-= LVS_ICON
;
509 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
510 oldStyle
-= LVS_REPORT
;
511 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
512 oldStyle
-= LVS_LIST
;
513 wstyle
|= LVS_SMALLICON
;
516 if ( style
& wxLC_LIST
)
518 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
519 oldStyle
-= LVS_ICON
;
520 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
521 oldStyle
-= LVS_REPORT
;
522 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
523 oldStyle
-= LVS_SMALLICON
;
527 if ( style
& wxLC_REPORT
)
529 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
530 oldStyle
-= LVS_ICON
;
531 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
532 oldStyle
-= LVS_LIST
;
533 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
534 oldStyle
-= LVS_SMALLICON
;
536 wstyle
|= LVS_REPORT
;
539 if ( style
& wxLC_ALIGN_LEFT
)
541 if ( oldStyle
& LVS_ALIGNTOP
)
542 oldStyle
-= LVS_ALIGNTOP
;
543 wstyle
|= LVS_ALIGNLEFT
;
546 if ( style
& wxLC_ALIGN_TOP
)
548 if ( oldStyle
& LVS_ALIGNLEFT
)
549 oldStyle
-= LVS_ALIGNLEFT
;
550 wstyle
|= LVS_ALIGNTOP
;
553 if ( style
& wxLC_AUTOARRANGE
)
554 wstyle
|= LVS_AUTOARRANGE
;
556 if ( style
& wxLC_NO_SORT_HEADER
)
557 wstyle
|= LVS_NOSORTHEADER
;
559 if ( style
& wxLC_NO_HEADER
)
560 wstyle
|= LVS_NOCOLUMNHEADER
;
562 if ( style
& wxLC_EDIT_LABELS
)
563 wstyle
|= LVS_EDITLABELS
;
565 if ( style
& wxLC_SINGLE_SEL
)
566 wstyle
|= LVS_SINGLESEL
;
568 if ( style
& wxLC_SORT_ASCENDING
)
570 if ( oldStyle
& LVS_SORTDESCENDING
)
571 oldStyle
-= LVS_SORTDESCENDING
;
572 wstyle
|= LVS_SORTASCENDING
;
575 if ( style
& wxLC_SORT_DESCENDING
)
577 if ( oldStyle
& LVS_SORTASCENDING
)
578 oldStyle
-= LVS_SORTASCENDING
;
579 wstyle
|= LVS_SORTDESCENDING
;
582 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
583 if ( style
& wxLC_VIRTUAL
)
585 int ver
= wxTheApp
->GetComCtl32Version();
588 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."),
589 ver
/ 100, ver
% 100);
592 wstyle
|= LVS_OWNERDATA
;
599 // ----------------------------------------------------------------------------
601 // ----------------------------------------------------------------------------
603 // Sets the foreground, i.e. text, colour
604 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
606 if ( !wxWindow::SetForegroundColour(col
) )
609 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
614 // Sets the background colour
615 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
617 if ( !wxWindow::SetBackgroundColour(col
) )
620 // we set the same colour for both the "empty" background and the items
622 COLORREF color
= wxColourToRGB(col
);
623 ListView_SetBkColor(GetHwnd(), color
);
624 ListView_SetTextBkColor(GetHwnd(), color
);
629 // Gets information about this column
630 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
635 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
637 lvCol
.mask
|= LVCF_TEXT
;
638 lvCol
.pszText
= new wxChar
[513];
639 lvCol
.cchTextMax
= 512;
642 bool success
= ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0;
644 // item.m_subItem = lvCol.iSubItem;
645 item
.m_width
= lvCol
.cx
;
647 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
649 item
.m_text
= lvCol
.pszText
;
650 delete[] lvCol
.pszText
;
653 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
655 if (lvCol
.fmt
== LVCFMT_LEFT
)
656 item
.m_format
= wxLIST_FORMAT_LEFT
;
657 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
658 item
.m_format
= wxLIST_FORMAT_RIGHT
;
659 else if (lvCol
.fmt
== LVCFMT_CENTER
)
660 item
.m_format
= wxLIST_FORMAT_CENTRE
;
666 // Sets information about this column
667 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
670 wxConvertToMSWListCol(col
, item
, lvCol
);
672 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
675 // Gets the column width
676 int wxListCtrl::GetColumnWidth(int col
) const
678 return ListView_GetColumnWidth(GetHwnd(), col
);
681 // Sets the column width
682 bool wxListCtrl::SetColumnWidth(int col
, int width
)
685 if ( m_windowStyle
& wxLC_LIST
)
689 if ( width2
== wxLIST_AUTOSIZE
)
690 width2
= LVSCW_AUTOSIZE
;
691 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
692 width2
= LVSCW_AUTOSIZE_USEHEADER
;
694 return ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0;
697 // Gets the number of items that can fit vertically in the
698 // visible area of the list control (list or report view)
699 // or the total number of items in the list control (icon
700 // or small icon view)
701 int wxListCtrl::GetCountPerPage() const
703 return ListView_GetCountPerPage(GetHwnd());
706 // Gets the edit control for editing labels.
707 wxTextCtrl
* wxListCtrl::GetEditControl() const
712 // Gets information about the item
713 bool wxListCtrl::GetItem(wxListItem
& info
) const
716 wxZeroMemory(lvItem
);
718 lvItem
.iItem
= info
.m_itemId
;
719 lvItem
.iSubItem
= info
.m_col
;
721 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
723 lvItem
.mask
|= LVIF_TEXT
;
724 lvItem
.pszText
= new wxChar
[513];
725 lvItem
.cchTextMax
= 512;
729 lvItem
.pszText
= NULL
;
732 if (info
.m_mask
& wxLIST_MASK_DATA
)
733 lvItem
.mask
|= LVIF_PARAM
;
735 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
736 lvItem
.mask
|= LVIF_IMAGE
;
738 if ( info
.m_mask
& wxLIST_MASK_STATE
)
740 lvItem
.mask
|= LVIF_STATE
;
741 // the other bits are hardly interesting anyhow
742 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
745 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
748 wxLogError(_("Couldn't retrieve information about list control item %d."),
753 // give NULL as hwnd as we already have everything we need
754 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
758 delete[] lvItem
.pszText
;
763 // Sets information about the item
764 bool wxListCtrl::SetItem(wxListItem
& info
)
767 wxConvertToMSWListItem(this, info
, item
);
769 // we could be changing only the attribute in which case we don't need to
770 // call ListView_SetItem() at all
774 if ( !ListView_SetItem(GetHwnd(), &item
) )
776 wxLogDebug(_T("ListView_SetItem() failed"));
782 // we need to update the item immediately to show the new image
783 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
785 // check whether it has any custom attributes
786 if ( info
.HasAttributes() )
788 wxListItemAttr
*attr
= (wxListItemAttr
*)m_attrs
.Get(item
.iItem
);
791 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
793 *attr
= *info
.GetAttributes();
797 // if the colour has changed, we must redraw the item
803 // we need this to make the change visible right now
804 RefreshItem(item
.iItem
);
810 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
814 info
.m_mask
= wxLIST_MASK_TEXT
;
815 info
.m_itemId
= index
;
819 info
.m_image
= imageId
;
820 info
.m_mask
|= wxLIST_MASK_IMAGE
;
822 return SetItem(info
);
826 // Gets the item state
827 int wxListCtrl::GetItemState(long item
, long stateMask
) const
831 info
.m_mask
= wxLIST_MASK_STATE
;
832 info
.m_stateMask
= stateMask
;
833 info
.m_itemId
= item
;
841 // Sets the item state
842 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
844 // NB: don't use SetItem() here as it doesn't work with the virtual list
847 wxZeroMemory(lvItem
);
849 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
851 // for the virtual list controls we need to refresh the previously focused
852 // item manually when changing focus without changing selection
853 // programmatically because otherwise it keeps its focus rectangle until
854 // next repaint (yet another comctl32 bug)
857 (stateMask
& wxLIST_STATE_FOCUSED
) &&
858 (state
& wxLIST_STATE_FOCUSED
) )
860 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
867 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
868 (WPARAM
)item
, (LPARAM
)&lvItem
) )
870 wxLogLastError(_T("ListView_SetItemState"));
875 if ( focusOld
!= -1 )
877 // no need to refresh the item if it was previously selected, it would
878 // only result in annoying flicker
879 if ( !(GetItemState(focusOld
,
880 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
882 RefreshItem(focusOld
);
889 // Sets the item image
890 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
894 info
.m_mask
= wxLIST_MASK_IMAGE
;
895 info
.m_image
= image
;
896 info
.m_itemId
= item
;
898 return SetItem(info
);
901 // Gets the item text
902 wxString
wxListCtrl::GetItemText(long item
) const
906 info
.m_mask
= wxLIST_MASK_TEXT
;
907 info
.m_itemId
= item
;
914 // Sets the item text
915 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
919 info
.m_mask
= wxLIST_MASK_TEXT
;
920 info
.m_itemId
= item
;
926 // Gets the item data
927 long wxListCtrl::GetItemData(long item
) const
931 info
.m_mask
= wxLIST_MASK_DATA
;
932 info
.m_itemId
= item
;
939 // Sets the item data
940 bool wxListCtrl::SetItemData(long item
, long data
)
944 info
.m_mask
= wxLIST_MASK_DATA
;
945 info
.m_itemId
= item
;
948 return SetItem(info
);
951 // Gets the item rectangle
952 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
957 if ( code
== wxLIST_RECT_BOUNDS
)
958 codeWin
= LVIR_BOUNDS
;
959 else if ( code
== wxLIST_RECT_ICON
)
961 else if ( code
== wxLIST_RECT_LABEL
)
962 codeWin
= LVIR_LABEL
;
965 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
967 codeWin
= LVIR_BOUNDS
;
971 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
) != 0;
973 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
976 rect
.x
= rectWin
.left
;
977 rect
.y
= rectWin
.top
;
978 rect
.width
= rectWin
.right
- rectWin
.left
;
979 rect
.height
= rectWin
.bottom
- rectWin
.top
;
984 // Gets the item position
985 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
989 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
991 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
995 // Sets the item position.
996 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
998 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
1001 // Gets the number of items in the list control
1002 int wxListCtrl::GetItemCount() const
1004 return ListView_GetItemCount(GetHwnd());
1007 // Retrieves the spacing between icons in pixels.
1008 // If small is TRUE, gets the spacing for the small icon
1009 // view, otherwise the large icon view.
1010 int wxListCtrl::GetItemSpacing(bool isSmall
) const
1012 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
1015 // Gets the number of selected items in the list control
1016 int wxListCtrl::GetSelectedItemCount() const
1018 return ListView_GetSelectedCount(GetHwnd());
1021 // Gets the text colour of the listview
1022 wxColour
wxListCtrl::GetTextColour() const
1024 COLORREF ref
= ListView_GetTextColor(GetHwnd());
1025 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
1029 // Sets the text colour of the listview
1030 void wxListCtrl::SetTextColour(const wxColour
& col
)
1032 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
1035 // Gets the index of the topmost visible item when in
1036 // list or report view
1037 long wxListCtrl::GetTopItem() const
1039 return (long) ListView_GetTopIndex(GetHwnd());
1042 // Searches for an item, starting from 'item'.
1043 // 'geometry' is one of
1044 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1045 // 'state' is a state bit flag, one or more of
1046 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1047 // item can be -1 to find the first item that matches the
1049 // Returns the item or -1 if unsuccessful.
1050 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1054 if ( geom
== wxLIST_NEXT_ABOVE
)
1055 flags
|= LVNI_ABOVE
;
1056 if ( geom
== wxLIST_NEXT_ALL
)
1058 if ( geom
== wxLIST_NEXT_BELOW
)
1059 flags
|= LVNI_BELOW
;
1060 if ( geom
== wxLIST_NEXT_LEFT
)
1061 flags
|= LVNI_TOLEFT
;
1062 if ( geom
== wxLIST_NEXT_RIGHT
)
1063 flags
|= LVNI_TORIGHT
;
1065 if ( state
& wxLIST_STATE_CUT
)
1067 if ( state
& wxLIST_STATE_DROPHILITED
)
1068 flags
|= LVNI_DROPHILITED
;
1069 if ( state
& wxLIST_STATE_FOCUSED
)
1070 flags
|= LVNI_FOCUSED
;
1071 if ( state
& wxLIST_STATE_SELECTED
)
1072 flags
|= LVNI_SELECTED
;
1074 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1078 wxImageList
*wxListCtrl::GetImageList(int which
) const
1080 if ( which
== wxIMAGE_LIST_NORMAL
)
1082 return m_imageListNormal
;
1084 else if ( which
== wxIMAGE_LIST_SMALL
)
1086 return m_imageListSmall
;
1088 else if ( which
== wxIMAGE_LIST_STATE
)
1090 return m_imageListState
;
1095 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1098 if ( which
== wxIMAGE_LIST_NORMAL
)
1100 flags
= LVSIL_NORMAL
;
1101 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1102 m_imageListNormal
= imageList
;
1103 m_ownsImageListNormal
= FALSE
;
1105 else if ( which
== wxIMAGE_LIST_SMALL
)
1107 flags
= LVSIL_SMALL
;
1108 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1109 m_imageListSmall
= imageList
;
1110 m_ownsImageListSmall
= FALSE
;
1112 else if ( which
== wxIMAGE_LIST_STATE
)
1114 flags
= LVSIL_STATE
;
1115 if (m_ownsImageListState
) delete m_imageListState
;
1116 m_imageListState
= imageList
;
1117 m_ownsImageListState
= FALSE
;
1119 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1122 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1124 SetImageList(imageList
, which
);
1125 if ( which
== wxIMAGE_LIST_NORMAL
)
1126 m_ownsImageListNormal
= TRUE
;
1127 else if ( which
== wxIMAGE_LIST_SMALL
)
1128 m_ownsImageListSmall
= TRUE
;
1129 else if ( which
== wxIMAGE_LIST_STATE
)
1130 m_ownsImageListState
= TRUE
;
1133 // ----------------------------------------------------------------------------
1135 // ----------------------------------------------------------------------------
1137 // Arranges the items
1138 bool wxListCtrl::Arrange(int flag
)
1141 if ( flag
== wxLIST_ALIGN_LEFT
)
1142 code
= LVA_ALIGNLEFT
;
1143 else if ( flag
== wxLIST_ALIGN_TOP
)
1144 code
= LVA_ALIGNTOP
;
1145 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1147 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1148 code
= LVA_SNAPTOGRID
;
1150 return (ListView_Arrange(GetHwnd(), code
) != 0);
1154 bool wxListCtrl::DeleteItem(long item
)
1156 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1158 wxLogLastError(_T("ListView_DeleteItem"));
1162 // the virtual list control doesn't refresh itself correctly, help it
1165 // we need to refresh all the lines below the one which was deleted
1167 if ( item
> 0 && GetItemCount() )
1169 GetItemRect(item
- 1, rectItem
);
1174 rectItem
.height
= 0;
1177 wxRect rectWin
= GetRect();
1178 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1179 rectWin
.y
= rectItem
.GetBottom();
1181 RefreshRect(rectWin
);
1187 // Deletes all items
1188 bool wxListCtrl::DeleteAllItems()
1190 return ListView_DeleteAllItems(GetHwnd()) != 0;
1193 // Deletes all items
1194 bool wxListCtrl::DeleteAllColumns()
1196 while ( m_colCount
> 0 )
1198 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1200 wxLogLastError(wxT("ListView_DeleteColumn"));
1208 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1214 bool wxListCtrl::DeleteColumn(int col
)
1216 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1218 if ( success
&& (m_colCount
> 0) )
1223 // Clears items, and columns if there are any.
1224 void wxListCtrl::ClearAll()
1227 if ( m_colCount
> 0 )
1231 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1233 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1235 // VS: ListView_EditLabel requires that the list has focus.
1237 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
1241 m_textCtrl
->SetHWND(0);
1242 m_textCtrl
->UnsubclassWin();
1247 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1248 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1249 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1254 // End label editing, optionally cancelling the edit
1255 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1257 wxFAIL_MSG( _T("not implemented") );
1262 // Ensures this item is visible
1263 bool wxListCtrl::EnsureVisible(long item
)
1265 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0;
1268 // Find an item whose label matches this string, starting from the item after 'start'
1269 // or the beginning if 'start' is -1.
1270 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1272 LV_FINDINFO findInfo
;
1274 findInfo
.flags
= LVFI_STRING
;
1276 findInfo
.flags
|= LVFI_PARTIAL
;
1279 // ListView_FindItem() excludes the first item from search and to look
1280 // through all the items you need to start from -1 which is unnatural and
1281 // inconsistent with the generic version - so we adjust the index
1284 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1287 // Find an item whose data matches this data, starting from the item after 'start'
1288 // or the beginning if 'start' is -1.
1289 long wxListCtrl::FindItem(long start
, long data
)
1291 LV_FINDINFO findInfo
;
1293 findInfo
.flags
= LVFI_PARAM
;
1294 findInfo
.lParam
= data
;
1296 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1299 // Find an item nearest this position in the specified direction, starting from
1300 // the item after 'start' or the beginning if 'start' is -1.
1301 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1303 LV_FINDINFO findInfo
;
1305 findInfo
.flags
= LVFI_NEARESTXY
;
1306 findInfo
.pt
.x
= pt
.x
;
1307 findInfo
.pt
.y
= pt
.y
;
1308 findInfo
.vkDirection
= VK_RIGHT
;
1310 if ( direction
== wxLIST_FIND_UP
)
1311 findInfo
.vkDirection
= VK_UP
;
1312 else if ( direction
== wxLIST_FIND_DOWN
)
1313 findInfo
.vkDirection
= VK_DOWN
;
1314 else if ( direction
== wxLIST_FIND_LEFT
)
1315 findInfo
.vkDirection
= VK_LEFT
;
1316 else if ( direction
== wxLIST_FIND_RIGHT
)
1317 findInfo
.vkDirection
= VK_RIGHT
;
1319 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1322 // Determines which item (if any) is at the specified point,
1323 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1324 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1326 LV_HITTESTINFO hitTestInfo
;
1327 hitTestInfo
.pt
.x
= (int) point
.x
;
1328 hitTestInfo
.pt
.y
= (int) point
.y
;
1330 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1333 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1334 flags
|= wxLIST_HITTEST_ABOVE
;
1335 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1336 flags
|= wxLIST_HITTEST_BELOW
;
1337 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1338 flags
|= wxLIST_HITTEST_NOWHERE
;
1339 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1340 flags
|= wxLIST_HITTEST_ONITEMICON
;
1341 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1342 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1343 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1344 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1345 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1346 flags
|= wxLIST_HITTEST_TOLEFT
;
1347 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1348 flags
|= wxLIST_HITTEST_TORIGHT
;
1350 return (long) hitTestInfo
.iItem
;
1353 // Inserts an item, returning the index of the new item if successful,
1355 long wxListCtrl::InsertItem(wxListItem
& info
)
1357 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1360 wxConvertToMSWListItem(this, info
, item
);
1362 // check whether it has any custom attributes
1363 if ( info
.HasAttributes() )
1366 wxListItemAttr
*attr
;
1367 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
1371 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1373 else *attr
= *info
.GetAttributes();
1375 m_hasAnyAttr
= TRUE
;
1378 return (long) ListView_InsertItem(GetHwnd(), & item
);
1381 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1384 info
.m_text
= label
;
1385 info
.m_mask
= wxLIST_MASK_TEXT
;
1386 info
.m_itemId
= index
;
1387 return InsertItem(info
);
1390 // Inserts an image item
1391 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1394 info
.m_image
= imageIndex
;
1395 info
.m_mask
= wxLIST_MASK_IMAGE
;
1396 info
.m_itemId
= index
;
1397 return InsertItem(info
);
1400 // Inserts an image/string item
1401 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1404 info
.m_image
= imageIndex
;
1405 info
.m_text
= label
;
1406 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1407 info
.m_itemId
= index
;
1408 return InsertItem(info
);
1411 // For list view mode (only), inserts a column.
1412 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1415 wxConvertToMSWListCol(col
, item
, lvCol
);
1417 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1419 // always give some width to the new column: this one is compatible
1420 // with the generic version
1421 lvCol
.mask
|= LVCF_WIDTH
;
1425 // when we insert a column which can contain an image, we must specify this
1426 // flag right now as doing it later in SetColumn() has no effect
1428 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1429 // way to dynamically set/clear the bitmap as the column without a bitmap
1430 // on the left looks ugly (there is a hole)
1432 // unfortunately with my version of comctl32.dll (5.80), the left column
1433 // image is always on the left and it seems that it's a "feature" - I
1434 // didn't find any way to work around it in any case
1435 if ( lvCol
.mask
& LVCF_IMAGE
)
1437 lvCol
.mask
|= LVCF_FMT
;
1438 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
;
1441 bool success
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
) != -1;
1448 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1455 long wxListCtrl::InsertColumn(long col
,
1456 const wxString
& heading
,
1461 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1462 item
.m_text
= heading
;
1465 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1466 item
.m_width
= width
;
1468 item
.m_format
= format
;
1470 return InsertColumn(col
, item
);
1473 // Scrolls the list control. If in icon, small icon or report view mode,
1474 // x specifies the number of pixels to scroll. If in list view mode, x
1475 // specifies the number of columns to scroll.
1476 // If in icon, small icon or list view mode, y specifies the number of pixels
1477 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1478 bool wxListCtrl::ScrollList(int dx
, int dy
)
1480 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1485 // fn is a function which takes 3 long arguments: item1, item2, data.
1486 // item1 is the long data associated with a first item (NOT the index).
1487 // item2 is the long data associated with a second item (NOT the index).
1488 // data is the same value as passed to SortItems.
1489 // The return value is a negative number if the first item should precede the second
1490 // item, a positive number of the second item should precede the first,
1491 // or zero if the two items are equivalent.
1493 // data is arbitrary data to be passed to the sort function.
1495 // FIXME: this is horrible and MT-unsafe and everything else but I don't have
1496 // time for anything better right now (VZ)
1497 static long gs_sortData
= 0;
1498 static wxListCtrl
*gs_sortCtrl
= NULL
;
1499 static wxListCtrlCompare gs_sortFunction
= NULL
;
1501 int wxCMPFUNC_CONV
wxListCtrlCompareFn(const void *arg1
, const void *arg2
)
1503 int n1
= *(const int *)arg1
,
1504 n2
= *(const int *)arg2
;
1506 return gs_sortFunction(gs_sortCtrl
->GetItemData(n1
),
1507 gs_sortCtrl
->GetItemData(n2
),
1511 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1513 // sort the attributes too
1517 count
= GetItemCount();
1518 int *aItems
= new int[count
];
1519 for ( n
= 0; n
< count
; n
++ )
1526 gs_sortFunction
= fn
;
1528 qsort(aItems
, count
, sizeof(int), wxListCtrlCompareFn
);
1532 gs_sortFunction
= NULL
;
1534 wxHashTable
attrsNew(wxKEY_INTEGER
, 1000);
1535 for ( n
= 0; n
< count
; n
++ )
1537 wxObject
*attr
= m_attrs
.Delete(aItems
[n
]);
1540 attrsNew
.Put(n
, attr
);
1550 if ( !ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
)fn
, data
) )
1552 wxLogDebug(_T("ListView_SortItems() failed"));
1562 // ----------------------------------------------------------------------------
1563 // message processing
1564 // ----------------------------------------------------------------------------
1566 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1568 if (cmd
== EN_UPDATE
)
1570 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1571 event
.SetEventObject( this );
1572 ProcessCommand(event
);
1575 else if (cmd
== EN_KILLFOCUS
)
1577 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1578 event
.SetEventObject( this );
1579 ProcessCommand(event
);
1586 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1588 // prepare the event
1589 // -----------------
1591 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1592 event
.SetEventObject(this);
1594 wxEventType eventType
= wxEVT_NULL
;
1596 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1598 // if your compiler is as broken as this, you should really change it: this
1599 // code is needed for normal operation! #ifdef below is only useful for
1600 // automatic rebuilds which are done with a very old compiler version
1601 #ifdef HDN_BEGINTRACKA
1603 // check for messages from the header (in report view)
1604 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1606 // is it a message from the header?
1607 if ( nmhdr
->hwndFrom
== hwndHdr
)
1609 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1611 event
.m_itemIndex
= -1;
1613 switch ( nmhdr
->code
)
1615 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1616 // TRACK messages even to ANSI programs: on my system I get
1617 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1619 // work around is to simply catch both versions and hope that it
1620 // works (why should this message exist in ANSI and Unicode is
1621 // beyond me as it doesn't deal with strings at all...)
1622 case HDN_BEGINTRACKA
:
1623 case HDN_BEGINTRACKW
:
1624 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1629 if ( eventType
== wxEVT_NULL
)
1630 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1635 if ( eventType
== wxEVT_NULL
)
1636 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1637 event
.m_col
= nmHDR
->iItem
;
1642 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1645 // find the column clicked: we have to search for it
1646 // ourselves as the notification message doesn't provide
1649 // where did the click occur?
1651 if ( !::GetCursorPos(&ptClick
) )
1653 wxLogLastError(_T("GetCursorPos"));
1656 if ( !::ScreenToClient(hwndHdr
, &ptClick
) )
1658 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1661 event
.m_pointDrag
.x
= ptClick
.x
;
1662 event
.m_pointDrag
.y
= ptClick
.y
;
1664 int colCount
= Header_GetItemCount(hwndHdr
);
1667 for ( int col
= 0; col
< colCount
; col
++ )
1669 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1671 if ( ::PtInRect(&rect
, ptClick
) )
1682 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1686 #endif // defined(HDN_BEGINTRACKA)
1687 if ( nmhdr
->hwndFrom
== GetHwnd() )
1689 // almost all messages use NM_LISTVIEW
1690 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1692 // this is true for almost all events
1693 event
.m_item
.m_data
= nmLV
->lParam
;
1695 switch ( nmhdr
->code
)
1697 case LVN_BEGINRDRAG
:
1698 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1702 if ( eventType
== wxEVT_NULL
)
1704 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1707 event
.m_itemIndex
= nmLV
->iItem
;
1708 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1709 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1712 // NB: we have to handle both *A and *W versions here because some
1713 // versions of comctl32.dll send ANSI message to an Unicode app
1714 case LVN_BEGINLABELEDITA
:
1716 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1717 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1718 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1719 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1722 case LVN_BEGINLABELEDITW
:
1724 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1725 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1726 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1727 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1731 case LVN_ENDLABELEDITA
:
1733 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1734 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1735 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1736 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1737 ((LV_ITEM
)item
).iItem
== -1 )
1740 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1743 case LVN_ENDLABELEDITW
:
1745 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1746 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1747 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1748 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1749 ((LV_ITEM
)item
).iItem
== -1 )
1752 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1756 case LVN_COLUMNCLICK
:
1757 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1758 event
.m_itemIndex
= -1;
1759 event
.m_col
= nmLV
->iSubItem
;
1762 case LVN_DELETEALLITEMS
:
1763 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1764 event
.m_itemIndex
= -1;
1770 case LVN_DELETEITEM
:
1771 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1772 event
.m_itemIndex
= nmLV
->iItem
;
1776 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1780 case LVN_SETDISPINFO
:
1782 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1783 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1784 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
1788 case LVN_INSERTITEM
:
1789 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1790 event
.m_itemIndex
= nmLV
->iItem
;
1793 case LVN_ITEMCHANGED
:
1794 // we translate this catch all message into more interesting
1795 // (and more easy to process) wxWindows events
1797 // first of all, we deal with the state change events only
1798 if ( nmLV
->uChanged
& LVIF_STATE
)
1800 // temp vars for readability
1801 const UINT stOld
= nmLV
->uOldState
;
1802 const UINT stNew
= nmLV
->uNewState
;
1804 // has the focus changed?
1805 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
1807 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
1808 event
.m_itemIndex
= nmLV
->iItem
;
1811 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
1813 if ( eventType
!= wxEVT_NULL
)
1815 // focus and selection have both changed: send the
1816 // focus event from here and the selection one
1818 event
.SetEventType(eventType
);
1819 (void)GetEventHandler()->ProcessEvent(event
);
1821 else // no focus event to send
1823 // then need to set m_itemIndex as it wasn't done
1825 event
.m_itemIndex
= nmLV
->iItem
;
1828 eventType
= stNew
& LVIS_SELECTED
1829 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1830 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1834 if ( eventType
== wxEVT_NULL
)
1836 // not an interesting event for us
1844 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1845 WORD wVKey
= info
->wVKey
;
1847 // get the current selection
1848 long lItem
= GetNextItem(-1,
1850 wxLIST_STATE_SELECTED
);
1852 // <Enter> or <Space> activate the selected item if any (but
1853 // not with Shift and/or Ctrl as then they have a predefined
1854 // meaning for the list view)
1856 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
1857 !(wxIsShiftDown() || wxIsCtrlDown()) )
1859 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1863 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1865 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1866 // value which should be used as is
1867 int code
= wxCharCodeMSWToWX(wVKey
);
1868 event
.m_code
= code
? code
: wVKey
;
1872 event
.m_item
.m_itemId
= lItem
;
1876 // fill the other fields too
1877 event
.m_item
.m_text
= GetItemText(lItem
);
1878 event
.m_item
.m_data
= GetItemData(lItem
);
1884 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1886 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1891 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1892 // if it happened on an item (and not on empty place)
1893 if ( nmLV
->iItem
== -1 )
1899 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1900 event
.m_itemIndex
= nmLV
->iItem
;
1901 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1902 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1906 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1907 // don't do anything else
1908 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1913 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1914 LV_HITTESTINFO lvhti
;
1915 wxZeroMemory(lvhti
);
1917 ::GetCursorPos(&(lvhti
.pt
));
1918 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1919 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1921 if ( lvhti
.flags
& LVHT_ONITEM
)
1923 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1924 event
.m_itemIndex
= lvhti
.iItem
;
1925 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
1926 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
1931 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1932 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
1934 *result
= OnCustomDraw(lParam
);
1937 #endif // _WIN32_IE >= 0x300
1939 case LVN_ODCACHEHINT
:
1941 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
1943 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
1945 // we get some really stupid cache hints like ones for items in
1946 // range 0..0 for an empty control or, after deleting an item,
1947 // for items in invalid range - filter this garbage out
1948 if ( cacheHint
->iFrom
< cacheHint
->iTo
)
1950 event
.m_oldItemIndex
= cacheHint
->iFrom
;
1952 long iMax
= GetItemCount();
1953 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
1963 case LVN_GETDISPINFO
:
1966 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1968 LV_ITEM
& lvi
= info
->item
;
1969 long item
= lvi
.iItem
;
1971 if ( lvi
.mask
& LVIF_TEXT
)
1973 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
1974 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
1977 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1978 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
1979 if ( lvi
.mask
& LVIF_IMAGE
)
1981 lvi
.iImage
= OnGetItemImage(item
);
1985 // a little dose of healthy paranoia: as we never use
1986 // LVM_SETCALLBACKMASK we're not supposed to get these ones
1987 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
1988 _T("we don't support state callbacks yet!") );
1995 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
2000 // where did this one come from?
2004 // process the event
2005 // -----------------
2007 event
.SetEventType(eventType
);
2009 if ( !GetEventHandler()->ProcessEvent(event
) )
2015 switch ( nmhdr
->code
)
2017 case LVN_DELETEALLITEMS
:
2018 // always return TRUE to suppress all additional LVN_DELETEITEM
2019 // notifications - this makes deleting all items from a list ctrl
2025 case LVN_ENDLABELEDITA
:
2026 case LVN_ENDLABELEDITW
:
2027 // logic here is inversed compared to all the other messages
2028 *result
= event
.IsAllowed();
2033 *result
= !event
.IsAllowed();
2038 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
2040 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
2042 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
2043 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
2044 switch ( nmcd
.dwDrawStage
)
2047 // if we've got any items with non standard attributes,
2048 // notify us before painting each item
2050 // for virtual controls, always suppose that we have attributes as
2051 // there is no way to check for this
2052 return IsVirtual() || m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
2055 case CDDS_ITEMPREPAINT
:
2057 size_t item
= (size_t)nmcd
.dwItemSpec
;
2058 if ( item
>= (size_t)GetItemCount() )
2060 // we get this message with item == 0 for an empty control,
2061 // we must ignore it as calling OnGetItemAttr() would be
2063 return CDRF_DODEFAULT
;
2066 wxListItemAttr
*attr
=
2067 IsVirtual() ? OnGetItemAttr(item
)
2068 : (wxListItemAttr
*)m_attrs
.Get(item
);
2072 // nothing to do for this item
2073 return CDRF_DODEFAULT
;
2077 wxColour colText
, colBack
;
2078 if ( attr
->HasFont() )
2080 wxFont font
= attr
->GetFont();
2081 hFont
= (HFONT
)font
.GetResourceHandle();
2088 if ( attr
->HasTextColour() )
2090 colText
= attr
->GetTextColour();
2094 colText
= GetTextColour();
2097 if ( attr
->HasBackgroundColour() )
2099 colBack
= attr
->GetBackgroundColour();
2103 colBack
= GetBackgroundColour();
2106 lplvcd
->clrText
= wxColourToRGB(colText
);
2107 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
2109 // note that if we wanted to set colours for
2110 // individual columns (subitems), we would have
2111 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2114 ::SelectObject(nmcd
.hdc
, hFont
);
2116 return CDRF_NEWFONT
;
2119 // fall through to return CDRF_DODEFAULT
2122 return CDRF_DODEFAULT
;
2126 #endif // NM_CUSTOMDRAW supported
2128 // Necessary for drawing hrules and vrules, if specified
2129 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2133 wxControl::OnPaint(event
);
2135 // Reset the device origin since it may have been set
2136 dc
.SetDeviceOrigin(0, 0);
2138 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
2139 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
2141 if (!drawHRules
&& !drawVRules
)
2143 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
2146 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2148 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2150 wxSize clientSize
= GetClientSize();
2154 int itemCount
= GetItemCount();
2158 long top
= GetTopItem();
2159 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2161 if (GetItemRect(i
, itemRect
))
2163 cy
= itemRect
.GetTop();
2164 if (i
!= 0) // Don't draw the first one
2166 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2169 if (i
== itemCount
- 1)
2171 cy
= itemRect
.GetBottom();
2172 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2178 if (drawVRules
&& (i
> -1))
2180 wxRect firstItemRect
;
2181 GetItemRect(0, firstItemRect
);
2183 if (GetItemRect(i
, itemRect
))
2186 int x
= itemRect
.GetX();
2187 for (col
= 0; col
< GetColumnCount(); col
++)
2189 int colWidth
= GetColumnWidth(col
);
2191 dc
.DrawLine(x
, firstItemRect
.GetY() - 2, x
, itemRect
.GetBottom());
2197 // ----------------------------------------------------------------------------
2198 // virtual list controls
2199 // ----------------------------------------------------------------------------
2201 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2203 // this is a pure virtual function, in fact - which is not really pure
2204 // because the controls which are not virtual don't need to implement it
2205 wxFAIL_MSG( _T("not supposed to be called") );
2207 return wxEmptyString
;
2210 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2213 wxFAIL_MSG( _T("not supposed to be called") );
2218 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2220 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2221 _T("invalid item index in OnGetItemAttr()") );
2223 // no attributes by default
2227 void wxListCtrl::SetItemCount(long count
)
2229 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2231 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
, 0) )
2233 wxLogLastError(_T("ListView_SetItemCount"));
2237 void wxListCtrl::RefreshItem(long item
)
2239 // strangely enough, ListView_Update() results in much more flicker here
2240 // than a dumb Refresh() -- why?
2242 if ( !ListView_Update(GetHwnd(), item
) )
2244 wxLogLastError(_T("ListView_Update"));
2248 GetItemRect(item
, rect
);
2253 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2255 wxRect rect1
, rect2
;
2256 GetItemRect(itemFrom
, rect1
);
2257 GetItemRect(itemTo
, rect2
);
2259 wxRect rect
= rect1
;
2260 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2265 // ----------------------------------------------------------------------------
2267 // ----------------------------------------------------------------------------
2269 // List item structure
2270 wxListItem::wxListItem()
2280 m_format
= wxLIST_FORMAT_CENTRE
;
2286 void wxListItem::Clear()
2295 m_format
= wxLIST_FORMAT_CENTRE
;
2297 m_text
= wxEmptyString
;
2299 if (m_attr
) delete m_attr
;
2303 void wxListItem::ClearAttributes()
2305 if (m_attr
) delete m_attr
;
2309 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2313 info
.m_data
= lvItem
.lParam
;
2316 info
.m_stateMask
= 0;
2317 info
.m_itemId
= lvItem
.iItem
;
2319 long oldMask
= lvItem
.mask
;
2321 bool needText
= FALSE
;
2322 if (hwndListCtrl
!= 0)
2324 if ( lvItem
.mask
& LVIF_TEXT
)
2331 lvItem
.pszText
= new wxChar
[513];
2332 lvItem
.cchTextMax
= 512;
2334 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2335 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2338 if ( lvItem
.mask
& LVIF_STATE
)
2340 info
.m_mask
|= wxLIST_MASK_STATE
;
2342 if ( lvItem
.stateMask
& LVIS_CUT
)
2344 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2345 if ( lvItem
.state
& LVIS_CUT
)
2346 info
.m_state
|= wxLIST_STATE_CUT
;
2348 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2350 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2351 if ( lvItem
.state
& LVIS_DROPHILITED
)
2352 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2354 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2356 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2357 if ( lvItem
.state
& LVIS_FOCUSED
)
2358 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2360 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2362 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2363 if ( lvItem
.state
& LVIS_SELECTED
)
2364 info
.m_state
|= wxLIST_STATE_SELECTED
;
2368 if ( lvItem
.mask
& LVIF_TEXT
)
2370 info
.m_mask
|= wxLIST_MASK_TEXT
;
2371 info
.m_text
= lvItem
.pszText
;
2373 if ( lvItem
.mask
& LVIF_IMAGE
)
2375 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2376 info
.m_image
= lvItem
.iImage
;
2378 if ( lvItem
.mask
& LVIF_PARAM
)
2379 info
.m_mask
|= wxLIST_MASK_DATA
;
2380 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2381 info
.m_mask
|= wxLIST_SET_ITEM
;
2382 info
.m_col
= lvItem
.iSubItem
;
2387 delete[] lvItem
.pszText
;
2389 lvItem
.mask
= oldMask
;
2392 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2394 if (stateMask
& wxLIST_STATE_CUT
)
2396 lvItem
.stateMask
|= LVIS_CUT
;
2397 if (state
& wxLIST_STATE_CUT
)
2398 lvItem
.state
|= LVIS_CUT
;
2400 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2402 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2403 if (state
& wxLIST_STATE_DROPHILITED
)
2404 lvItem
.state
|= LVIS_DROPHILITED
;
2406 if (stateMask
& wxLIST_STATE_FOCUSED
)
2408 lvItem
.stateMask
|= LVIS_FOCUSED
;
2409 if (state
& wxLIST_STATE_FOCUSED
)
2410 lvItem
.state
|= LVIS_FOCUSED
;
2412 if (stateMask
& wxLIST_STATE_SELECTED
)
2414 lvItem
.stateMask
|= LVIS_SELECTED
;
2415 if (state
& wxLIST_STATE_SELECTED
)
2416 lvItem
.state
|= LVIS_SELECTED
;
2420 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2421 const wxListItem
& info
,
2424 lvItem
.iItem
= (int) info
.m_itemId
;
2426 lvItem
.iImage
= info
.m_image
;
2427 lvItem
.lParam
= info
.m_data
;
2428 lvItem
.stateMask
= 0;
2431 lvItem
.iSubItem
= info
.m_col
;
2433 if (info
.m_mask
& wxLIST_MASK_STATE
)
2435 lvItem
.mask
|= LVIF_STATE
;
2437 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2440 if (info
.m_mask
& wxLIST_MASK_TEXT
)
2442 lvItem
.mask
|= LVIF_TEXT
;
2443 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
2445 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
2449 // pszText is not const, hence the cast
2450 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
2451 if ( lvItem
.pszText
)
2452 lvItem
.cchTextMax
= info
.m_text
.Length();
2454 lvItem
.cchTextMax
= 0;
2457 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
2458 lvItem
.mask
|= LVIF_IMAGE
;
2459 if (info
.m_mask
& wxLIST_MASK_DATA
)
2460 lvItem
.mask
|= LVIF_PARAM
;
2463 static void wxConvertToMSWListCol(int WXUNUSED(col
), const wxListItem
& item
,
2466 wxZeroMemory(lvCol
);
2468 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
2470 lvCol
.mask
|= LVCF_TEXT
;
2471 lvCol
.pszText
= (wxChar
*)item
.m_text
.c_str(); // cast is safe
2474 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
2476 lvCol
.mask
|= LVCF_FMT
;
2478 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
2479 lvCol
.fmt
= LVCFMT_LEFT
;
2480 else if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
2481 lvCol
.fmt
= LVCFMT_RIGHT
;
2482 else if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
2483 lvCol
.fmt
= LVCFMT_CENTER
;
2486 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
2488 lvCol
.mask
|= LVCF_WIDTH
;
2489 if ( item
.m_width
== wxLIST_AUTOSIZE
)
2490 lvCol
.cx
= LVSCW_AUTOSIZE
;
2491 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2492 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
2494 lvCol
.cx
= item
.m_width
;
2497 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2498 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2499 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
2501 if ( wxTheApp
->GetComCtl32Version() >= 470 )
2503 lvCol
.mask
|= LVCF_IMAGE
;
2504 lvCol
.iImage
= item
.m_image
;
2506 //else: it doesn't support item images anyhow
2511 #endif // wxUSE_LISTCTRL