1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/listctrl.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "listctrl.h"
22 #pragma implementation "listctrlbase.h"
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
32 #if wxUSE_LISTCTRL && defined(__WIN95__)
38 #include "wx/settings.h"
41 #include "wx/textctrl.h"
42 #include "wx/imaglist.h"
43 #include "wx/listctrl.h"
44 #include "wx/dcclient.h"
46 #include "wx/msw/private.h"
48 #if ((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__))
49 #include "wx/msw/gnuwin32/extra.h"
54 #include "wx/msw/missing.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // convert our state and mask flags to LV_ITEM constants
61 static void wxConvertToMSWFlags(long state
, long mask
, LV_ITEM
& lvItem
);
63 // convert wxListItem to LV_ITEM
64 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
65 const wxListItem
& info
, LV_ITEM
& lvItem
);
67 // convert LV_ITEM to wxListItem
68 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
70 /* const */ LV_ITEM
& lvItem
);
72 // convert our wxListItem to LV_COLUMN
73 static void wxConvertToMSWListCol(int col
, const wxListItem
& item
,
76 // ----------------------------------------------------------------------------
77 // private helper classes
78 // ----------------------------------------------------------------------------
80 // We have to handle both fooW and fooA notifications in several cases
81 // because of broken commctl.dll and/or unicows.dll. This class is used to
82 // convert LV_ITEMA and LV_ITEMW to LV_ITEM (which is either LV_ITEMA or
83 // LV_ITEMW depending on wxUSE_UNICODE setting), so that it can be processed
84 // by wxConvertToMSWListItem().
88 ~wxLV_ITEM() { delete m_buf
; }
89 operator LV_ITEM
&() const { return *m_item
; }
92 wxLV_ITEM(LV_ITEMW
&item
) : m_buf(NULL
), m_item(&item
) {}
93 wxLV_ITEM(LV_ITEMA
&item
)
95 m_item
= new LV_ITEM((LV_ITEM
&)item
);
96 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
98 m_buf
= new wxMB2WXbuf(wxConvLocal
.cMB2WX(item
.pszText
));
99 m_item
->pszText
= (wxChar
*)m_buf
->data();
108 wxLV_ITEM(LV_ITEMW
&item
)
110 m_item
= new LV_ITEM((LV_ITEM
&)item
);
111 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
113 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX(item
.pszText
));
114 m_item
->pszText
= (wxChar
*)m_buf
->data();
119 wxLV_ITEM(LV_ITEMA
&item
) : m_buf(NULL
), m_item(&item
) {}
127 ///////////////////////////////////////////////////////
129 // The MSW version had problems with SetTextColour() et
130 // al as the wxListItemAttr's were stored keyed on the
131 // item index. If a item was inserted anywhere but the end
132 // of the list the the text attributes (colour etc) for
133 // the following items were out of sync.
136 // Under MSW the only way to associate data with a List
137 // item independant of its position in the list is to
138 // store a pointer to it in its lParam attribute. However
139 // user programs are already using this (via the
140 // SetItemData() GetItemData() calls).
142 // However what we can do is store a pointer to a
143 // structure which contains the attributes we want *and*
144 // a lParam for the users data, e.g.
146 // class wxListItemInternalData
149 // wxListItemAttr *attr;
150 // long lParam; // user data
153 // To conserve memory, a wxListItemInternalData is
154 // only allocated for a LV_ITEM if text attributes or
155 // user data(lparam) are being set.
158 // class wxListItemInternalData
159 class wxListItemInternalData
162 wxListItemAttr
*attr
;
163 LPARAM lParam
; // user data
165 wxListItemInternalData() : attr(NULL
), lParam(0) {}
166 ~wxListItemInternalData()
173 // Get the internal data structure
174 static wxListItemInternalData
*GetInternalData(HWND hwnd
, long itemId
);
175 static wxListItemInternalData
*GetInternalData(wxListCtrl
*ctl
, long itemId
);
176 static wxListItemAttr
*GetInternalDataAttr(wxListCtrl
*ctl
, long itemId
);
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
183 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
184 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
185 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
186 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
187 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
188 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
189 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
190 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
191 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
192 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
193 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
194 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
195 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
196 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
197 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
198 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
199 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
200 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
201 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
202 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
203 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
204 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
206 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
207 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
208 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
210 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
212 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
213 EVT_PAINT(wxListCtrl::OnPaint
)
216 // ============================================================================
218 // ============================================================================
220 // ----------------------------------------------------------------------------
221 // wxListCtrl construction
222 // ----------------------------------------------------------------------------
224 void wxListCtrl::Init()
226 m_imageListNormal
= NULL
;
227 m_imageListSmall
= NULL
;
228 m_imageListState
= NULL
;
229 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
233 m_AnyInternalData
= FALSE
;
234 m_hasAnyAttr
= FALSE
;
237 bool wxListCtrl::Create(wxWindow
*parent
,
242 const wxValidator
& validator
,
243 const wxString
& name
)
246 SetValidator(validator
);
247 #endif // wxUSE_VALIDATORS
256 m_windowStyle
= style
;
269 m_windowId
= (id
== -1) ? NewControlId() : id
;
271 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
272 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
274 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
275 wstyle
|= WS_CLIPSIBLINGS
;
277 if ( wxStyleHasBorder(m_windowStyle
) )
279 m_baseStyle
= wstyle
;
281 if ( !DoCreateControl(x
, y
, width
, height
) )
285 parent
->AddChild(this);
290 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
292 DWORD wstyle
= m_baseStyle
;
295 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
297 // Even with extended styles, need to combine with WS_BORDER
298 // for them to look right.
302 long oldStyle
= 0; // Dummy
303 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
305 // Create the ListView control.
306 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
311 GetWinHwnd(GetParent()),
318 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
323 // for comctl32.dll v 4.70+ we want to have this attribute because it's
324 // prettier (and also because wxGTK does it like this)
325 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
327 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
328 0, LVS_EX_FULLROWSELECT
);
331 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
332 SetForegroundColour(GetParent()->GetForegroundColour());
339 void wxListCtrl::UpdateStyle()
343 // The new window view style
345 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
346 dwStyleNew
|= m_baseStyle
;
348 // Get the current window style.
349 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
351 // Only set the window style if the view bits have changed.
352 if ( dwStyleOld
!= dwStyleNew
)
354 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
359 void wxListCtrl::FreeAllInternalData()
361 if (m_AnyInternalData
)
363 int n
= GetItemCount();
366 for (i
= 0; i
< n
; i
++)
368 wxListItemInternalData
*data
= GetInternalData(this, i
);
375 wxListCtrl::~wxListCtrl()
377 FreeAllInternalData();
381 m_textCtrl
->SetHWND(0);
382 m_textCtrl
->UnsubclassWin();
387 if (m_ownsImageListNormal
) delete m_imageListNormal
;
388 if (m_ownsImageListSmall
) delete m_imageListSmall
;
389 if (m_ownsImageListState
) delete m_imageListState
;
392 // ----------------------------------------------------------------------------
393 // set/get/change style
394 // ----------------------------------------------------------------------------
396 // Add or remove a single window style
397 void wxListCtrl::SetSingleStyle(long style
, bool add
)
399 long flag
= GetWindowStyleFlag();
401 // Get rid of conflicting styles
404 if ( style
& wxLC_MASK_TYPE
)
405 flag
= flag
& ~wxLC_MASK_TYPE
;
406 if ( style
& wxLC_MASK_ALIGN
)
407 flag
= flag
& ~wxLC_MASK_ALIGN
;
408 if ( style
& wxLC_MASK_SORT
)
409 flag
= flag
& ~wxLC_MASK_SORT
;
425 m_windowStyle
= flag
;
430 // Set the whole window style
431 void wxListCtrl::SetWindowStyleFlag(long flag
)
433 m_windowStyle
= flag
;
438 // Can be just a single style, or a bitlist
439 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
442 if ( style
& wxLC_ICON
)
444 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
445 oldStyle
-= LVS_SMALLICON
;
446 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
447 oldStyle
-= LVS_REPORT
;
448 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
449 oldStyle
-= LVS_LIST
;
453 if ( style
& wxLC_SMALL_ICON
)
455 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
456 oldStyle
-= LVS_ICON
;
457 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
458 oldStyle
-= LVS_REPORT
;
459 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
460 oldStyle
-= LVS_LIST
;
461 wstyle
|= LVS_SMALLICON
;
464 if ( style
& wxLC_LIST
)
466 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
467 oldStyle
-= LVS_ICON
;
468 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
469 oldStyle
-= LVS_REPORT
;
470 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
471 oldStyle
-= LVS_SMALLICON
;
475 if ( style
& wxLC_REPORT
)
477 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
478 oldStyle
-= LVS_ICON
;
479 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
480 oldStyle
-= LVS_LIST
;
481 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
482 oldStyle
-= LVS_SMALLICON
;
484 wstyle
|= LVS_REPORT
;
487 if ( style
& wxLC_ALIGN_LEFT
)
489 if ( oldStyle
& LVS_ALIGNTOP
)
490 oldStyle
-= LVS_ALIGNTOP
;
491 wstyle
|= LVS_ALIGNLEFT
;
494 if ( style
& wxLC_ALIGN_TOP
)
496 if ( oldStyle
& LVS_ALIGNLEFT
)
497 oldStyle
-= LVS_ALIGNLEFT
;
498 wstyle
|= LVS_ALIGNTOP
;
501 if ( style
& wxLC_AUTOARRANGE
)
502 wstyle
|= LVS_AUTOARRANGE
;
504 if ( style
& wxLC_NO_SORT_HEADER
)
505 wstyle
|= LVS_NOSORTHEADER
;
507 if ( style
& wxLC_NO_HEADER
)
508 wstyle
|= LVS_NOCOLUMNHEADER
;
510 if ( style
& wxLC_EDIT_LABELS
)
511 wstyle
|= LVS_EDITLABELS
;
513 if ( style
& wxLC_SINGLE_SEL
)
514 wstyle
|= LVS_SINGLESEL
;
516 if ( style
& wxLC_SORT_ASCENDING
)
518 if ( oldStyle
& LVS_SORTDESCENDING
)
519 oldStyle
-= LVS_SORTDESCENDING
;
520 wstyle
|= LVS_SORTASCENDING
;
523 if ( style
& wxLC_SORT_DESCENDING
)
525 if ( oldStyle
& LVS_SORTASCENDING
)
526 oldStyle
-= LVS_SORTASCENDING
;
527 wstyle
|= LVS_SORTDESCENDING
;
530 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
531 if ( style
& wxLC_VIRTUAL
)
533 int ver
= wxTheApp
->GetComCtl32Version();
536 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."),
537 ver
/ 100, ver
% 100);
540 wstyle
|= LVS_OWNERDATA
;
547 // ----------------------------------------------------------------------------
549 // ----------------------------------------------------------------------------
551 // Sets the foreground, i.e. text, colour
552 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
554 if ( !wxWindow::SetForegroundColour(col
) )
557 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
562 // Sets the background colour
563 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
565 if ( !wxWindow::SetBackgroundColour(col
) )
568 // we set the same colour for both the "empty" background and the items
570 COLORREF color
= wxColourToRGB(col
);
571 ListView_SetBkColor(GetHwnd(), color
);
572 ListView_SetTextBkColor(GetHwnd(), color
);
577 // Gets information about this column
578 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
583 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
585 lvCol
.mask
|= LVCF_TEXT
;
586 lvCol
.pszText
= new wxChar
[513];
587 lvCol
.cchTextMax
= 512;
590 bool success
= ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0;
592 // item.m_subItem = lvCol.iSubItem;
593 item
.m_width
= lvCol
.cx
;
595 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
597 item
.m_text
= lvCol
.pszText
;
598 delete[] lvCol
.pszText
;
601 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
603 if (lvCol
.fmt
== LVCFMT_LEFT
)
604 item
.m_format
= wxLIST_FORMAT_LEFT
;
605 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
606 item
.m_format
= wxLIST_FORMAT_RIGHT
;
607 else if (lvCol
.fmt
== LVCFMT_CENTER
)
608 item
.m_format
= wxLIST_FORMAT_CENTRE
;
614 // Sets information about this column
615 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
618 wxConvertToMSWListCol(col
, item
, lvCol
);
620 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
623 // Gets the column width
624 int wxListCtrl::GetColumnWidth(int col
) const
626 return ListView_GetColumnWidth(GetHwnd(), col
);
629 // Sets the column width
630 bool wxListCtrl::SetColumnWidth(int col
, int width
)
633 if ( m_windowStyle
& wxLC_LIST
)
637 if ( width2
== wxLIST_AUTOSIZE
)
638 width2
= LVSCW_AUTOSIZE
;
639 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
640 width2
= LVSCW_AUTOSIZE_USEHEADER
;
642 return ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0;
645 // Gets the number of items that can fit vertically in the
646 // visible area of the list control (list or report view)
647 // or the total number of items in the list control (icon
648 // or small icon view)
649 int wxListCtrl::GetCountPerPage() const
651 return ListView_GetCountPerPage(GetHwnd());
654 // Gets the edit control for editing labels.
655 wxTextCtrl
* wxListCtrl::GetEditControl() const
660 // Gets information about the item
661 bool wxListCtrl::GetItem(wxListItem
& info
) const
664 wxZeroMemory(lvItem
);
666 lvItem
.iItem
= info
.m_itemId
;
667 lvItem
.iSubItem
= info
.m_col
;
669 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
671 lvItem
.mask
|= LVIF_TEXT
;
672 lvItem
.pszText
= new wxChar
[513];
673 lvItem
.cchTextMax
= 512;
677 lvItem
.pszText
= NULL
;
680 if (info
.m_mask
& wxLIST_MASK_DATA
)
681 lvItem
.mask
|= LVIF_PARAM
;
683 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
684 lvItem
.mask
|= LVIF_IMAGE
;
686 if ( info
.m_mask
& wxLIST_MASK_STATE
)
688 lvItem
.mask
|= LVIF_STATE
;
689 // the other bits are hardly interesting anyhow
690 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
693 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
696 wxLogError(_("Couldn't retrieve information about list control item %d."),
701 // give NULL as hwnd as we already have everything we need
702 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
706 delete[] lvItem
.pszText
;
711 // Sets information about the item
712 bool wxListCtrl::SetItem(wxListItem
& info
)
715 wxConvertToMSWListItem(this, info
, item
);
717 // we never update the lParam if it contains our pointer
718 // to the wxListItemInternalData structure
719 item
.mask
&= ~LVIF_PARAM
;
721 // check if setting attributes or lParam
722 if (info
.HasAttributes() || (info
.m_mask
& wxLIST_MASK_DATA
))
724 // get internal item data
725 // perhaps a cache here ?
726 wxListItemInternalData
*data
= GetInternalData(this, info
.m_itemId
);
731 m_AnyInternalData
= TRUE
;
732 data
= new wxListItemInternalData();
733 item
.lParam
= (LPARAM
) data
;
734 item
.mask
|= LVIF_PARAM
;
739 if (info
.m_mask
& wxLIST_MASK_DATA
)
740 data
->lParam
= info
.m_data
;
743 if (info
.HasAttributes())
746 *data
->attr
= *info
.GetAttributes();
748 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
753 // we could be changing only the attribute in which case we don't need to
754 // call ListView_SetItem() at all
758 if ( !ListView_SetItem(GetHwnd(), &item
) )
760 wxLogDebug(_T("ListView_SetItem() failed"));
766 // we need to update the item immediately to show the new image
767 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
769 // check whether it has any custom attributes
770 if ( info
.HasAttributes() )
774 // if the colour has changed, we must redraw the item
780 // we need this to make the change visible right now
781 RefreshItem(item
.iItem
);
787 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
791 info
.m_mask
= wxLIST_MASK_TEXT
;
792 info
.m_itemId
= index
;
796 info
.m_image
= imageId
;
797 info
.m_mask
|= wxLIST_MASK_IMAGE
;
799 return SetItem(info
);
803 // Gets the item state
804 int wxListCtrl::GetItemState(long item
, long stateMask
) const
808 info
.m_mask
= wxLIST_MASK_STATE
;
809 info
.m_stateMask
= stateMask
;
810 info
.m_itemId
= item
;
818 // Sets the item state
819 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
821 // NB: don't use SetItem() here as it doesn't work with the virtual list
824 wxZeroMemory(lvItem
);
826 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
828 // for the virtual list controls we need to refresh the previously focused
829 // item manually when changing focus without changing selection
830 // programmatically because otherwise it keeps its focus rectangle until
831 // next repaint (yet another comctl32 bug)
834 (stateMask
& wxLIST_STATE_FOCUSED
) &&
835 (state
& wxLIST_STATE_FOCUSED
) )
837 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
844 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
845 (WPARAM
)item
, (LPARAM
)&lvItem
) )
847 wxLogLastError(_T("ListView_SetItemState"));
852 if ( focusOld
!= -1 )
854 // no need to refresh the item if it was previously selected, it would
855 // only result in annoying flicker
856 if ( !(GetItemState(focusOld
,
857 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
859 RefreshItem(focusOld
);
866 // Sets the item image
867 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
871 info
.m_mask
= wxLIST_MASK_IMAGE
;
872 info
.m_image
= image
;
873 info
.m_itemId
= item
;
875 return SetItem(info
);
878 // Gets the item text
879 wxString
wxListCtrl::GetItemText(long item
) const
883 info
.m_mask
= wxLIST_MASK_TEXT
;
884 info
.m_itemId
= item
;
891 // Sets the item text
892 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
896 info
.m_mask
= wxLIST_MASK_TEXT
;
897 info
.m_itemId
= item
;
903 // Gets the item data
904 long wxListCtrl::GetItemData(long item
) const
908 info
.m_mask
= wxLIST_MASK_DATA
;
909 info
.m_itemId
= item
;
916 // Sets the item data
917 bool wxListCtrl::SetItemData(long item
, long data
)
921 info
.m_mask
= wxLIST_MASK_DATA
;
922 info
.m_itemId
= item
;
925 return SetItem(info
);
928 // Gets the item rectangle
929 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
934 if ( code
== wxLIST_RECT_BOUNDS
)
935 codeWin
= LVIR_BOUNDS
;
936 else if ( code
== wxLIST_RECT_ICON
)
938 else if ( code
== wxLIST_RECT_LABEL
)
939 codeWin
= LVIR_LABEL
;
942 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
944 codeWin
= LVIR_BOUNDS
;
948 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
) != 0;
950 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
953 rect
.x
= rectWin
.left
;
954 rect
.y
= rectWin
.top
;
955 rect
.width
= rectWin
.right
- rectWin
.left
;
956 rect
.height
= rectWin
.bottom
- rectWin
.top
;
961 // Gets the item position
962 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
966 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
968 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
972 // Sets the item position.
973 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
975 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
978 // Gets the number of items in the list control
979 int wxListCtrl::GetItemCount() const
981 return ListView_GetItemCount(GetHwnd());
984 // Retrieves the spacing between icons in pixels.
985 // If small is TRUE, gets the spacing for the small icon
986 // view, otherwise the large icon view.
987 int wxListCtrl::GetItemSpacing(bool isSmall
) const
989 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
992 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
995 info
.m_itemId
= item
;
996 info
.SetTextColour( col
);
1000 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1003 info
.m_itemId
= item
;
1005 return info
.GetTextColour();
1008 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1011 info
.m_itemId
= item
;
1012 info
.SetBackgroundColour( col
);
1016 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1019 info
.m_itemId
= item
;
1021 return info
.GetBackgroundColour();
1024 // Gets the number of selected items in the list control
1025 int wxListCtrl::GetSelectedItemCount() const
1027 return ListView_GetSelectedCount(GetHwnd());
1030 // Gets the text colour of the listview
1031 wxColour
wxListCtrl::GetTextColour() const
1033 COLORREF ref
= ListView_GetTextColor(GetHwnd());
1034 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
1038 // Sets the text colour of the listview
1039 void wxListCtrl::SetTextColour(const wxColour
& col
)
1041 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
1044 // Gets the index of the topmost visible item when in
1045 // list or report view
1046 long wxListCtrl::GetTopItem() const
1048 return (long) ListView_GetTopIndex(GetHwnd());
1051 // Searches for an item, starting from 'item'.
1052 // 'geometry' is one of
1053 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1054 // 'state' is a state bit flag, one or more of
1055 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1056 // item can be -1 to find the first item that matches the
1058 // Returns the item or -1 if unsuccessful.
1059 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1063 if ( geom
== wxLIST_NEXT_ABOVE
)
1064 flags
|= LVNI_ABOVE
;
1065 if ( geom
== wxLIST_NEXT_ALL
)
1067 if ( geom
== wxLIST_NEXT_BELOW
)
1068 flags
|= LVNI_BELOW
;
1069 if ( geom
== wxLIST_NEXT_LEFT
)
1070 flags
|= LVNI_TOLEFT
;
1071 if ( geom
== wxLIST_NEXT_RIGHT
)
1072 flags
|= LVNI_TORIGHT
;
1074 if ( state
& wxLIST_STATE_CUT
)
1076 if ( state
& wxLIST_STATE_DROPHILITED
)
1077 flags
|= LVNI_DROPHILITED
;
1078 if ( state
& wxLIST_STATE_FOCUSED
)
1079 flags
|= LVNI_FOCUSED
;
1080 if ( state
& wxLIST_STATE_SELECTED
)
1081 flags
|= LVNI_SELECTED
;
1083 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1087 wxImageList
*wxListCtrl::GetImageList(int which
) const
1089 if ( which
== wxIMAGE_LIST_NORMAL
)
1091 return m_imageListNormal
;
1093 else if ( which
== wxIMAGE_LIST_SMALL
)
1095 return m_imageListSmall
;
1097 else if ( which
== wxIMAGE_LIST_STATE
)
1099 return m_imageListState
;
1104 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1107 if ( which
== wxIMAGE_LIST_NORMAL
)
1109 flags
= LVSIL_NORMAL
;
1110 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1111 m_imageListNormal
= imageList
;
1112 m_ownsImageListNormal
= FALSE
;
1114 else if ( which
== wxIMAGE_LIST_SMALL
)
1116 flags
= LVSIL_SMALL
;
1117 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1118 m_imageListSmall
= imageList
;
1119 m_ownsImageListSmall
= FALSE
;
1121 else if ( which
== wxIMAGE_LIST_STATE
)
1123 flags
= LVSIL_STATE
;
1124 if (m_ownsImageListState
) delete m_imageListState
;
1125 m_imageListState
= imageList
;
1126 m_ownsImageListState
= FALSE
;
1128 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1131 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1133 SetImageList(imageList
, which
);
1134 if ( which
== wxIMAGE_LIST_NORMAL
)
1135 m_ownsImageListNormal
= TRUE
;
1136 else if ( which
== wxIMAGE_LIST_SMALL
)
1137 m_ownsImageListSmall
= TRUE
;
1138 else if ( which
== wxIMAGE_LIST_STATE
)
1139 m_ownsImageListState
= TRUE
;
1142 // ----------------------------------------------------------------------------
1144 // ----------------------------------------------------------------------------
1146 // Arranges the items
1147 bool wxListCtrl::Arrange(int flag
)
1150 if ( flag
== wxLIST_ALIGN_LEFT
)
1151 code
= LVA_ALIGNLEFT
;
1152 else if ( flag
== wxLIST_ALIGN_TOP
)
1153 code
= LVA_ALIGNTOP
;
1154 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1156 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1157 code
= LVA_SNAPTOGRID
;
1159 return (ListView_Arrange(GetHwnd(), code
) != 0);
1163 bool wxListCtrl::DeleteItem(long item
)
1165 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1167 wxLogLastError(_T("ListView_DeleteItem"));
1171 // the virtual list control doesn't refresh itself correctly, help it
1174 // we need to refresh all the lines below the one which was deleted
1176 if ( item
> 0 && GetItemCount() )
1178 GetItemRect(item
- 1, rectItem
);
1183 rectItem
.height
= 0;
1186 wxRect rectWin
= GetRect();
1187 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1188 rectWin
.y
= rectItem
.GetBottom();
1190 RefreshRect(rectWin
);
1196 // Deletes all items
1197 bool wxListCtrl::DeleteAllItems()
1199 return ListView_DeleteAllItems(GetHwnd()) != 0;
1202 // Deletes all items
1203 bool wxListCtrl::DeleteAllColumns()
1205 while ( m_colCount
> 0 )
1207 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1209 wxLogLastError(wxT("ListView_DeleteColumn"));
1217 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1223 bool wxListCtrl::DeleteColumn(int col
)
1225 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1227 if ( success
&& (m_colCount
> 0) )
1232 // Clears items, and columns if there are any.
1233 void wxListCtrl::ClearAll()
1236 if ( m_colCount
> 0 )
1240 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1242 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1244 // VS: ListView_EditLabel requires that the list has focus.
1246 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
1250 m_textCtrl
->SetHWND(0);
1251 m_textCtrl
->UnsubclassWin();
1256 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1257 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1258 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1263 // End label editing, optionally cancelling the edit
1264 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1266 wxFAIL_MSG( _T("not implemented") );
1271 // Ensures this item is visible
1272 bool wxListCtrl::EnsureVisible(long item
)
1274 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0;
1277 // Find an item whose label matches this string, starting from the item after 'start'
1278 // or the beginning if 'start' is -1.
1279 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1281 LV_FINDINFO findInfo
;
1283 findInfo
.flags
= LVFI_STRING
;
1285 findInfo
.flags
|= LVFI_PARTIAL
;
1288 // ListView_FindItem() excludes the first item from search and to look
1289 // through all the items you need to start from -1 which is unnatural and
1290 // inconsistent with the generic version - so we adjust the index
1293 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1296 // Find an item whose data matches this data, starting from the item after 'start'
1297 // or the beginning if 'start' is -1.
1298 long wxListCtrl::FindItem(long start
, long data
)
1300 LV_FINDINFO findInfo
;
1302 findInfo
.flags
= LVFI_PARAM
;
1303 findInfo
.lParam
= data
;
1305 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1308 // Find an item nearest this position in the specified direction, starting from
1309 // the item after 'start' or the beginning if 'start' is -1.
1310 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1312 LV_FINDINFO findInfo
;
1314 findInfo
.flags
= LVFI_NEARESTXY
;
1315 findInfo
.pt
.x
= pt
.x
;
1316 findInfo
.pt
.y
= pt
.y
;
1317 findInfo
.vkDirection
= VK_RIGHT
;
1319 if ( direction
== wxLIST_FIND_UP
)
1320 findInfo
.vkDirection
= VK_UP
;
1321 else if ( direction
== wxLIST_FIND_DOWN
)
1322 findInfo
.vkDirection
= VK_DOWN
;
1323 else if ( direction
== wxLIST_FIND_LEFT
)
1324 findInfo
.vkDirection
= VK_LEFT
;
1325 else if ( direction
== wxLIST_FIND_RIGHT
)
1326 findInfo
.vkDirection
= VK_RIGHT
;
1328 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1331 // Determines which item (if any) is at the specified point,
1332 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1333 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1335 LV_HITTESTINFO hitTestInfo
;
1336 hitTestInfo
.pt
.x
= (int) point
.x
;
1337 hitTestInfo
.pt
.y
= (int) point
.y
;
1339 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1342 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1343 flags
|= wxLIST_HITTEST_ABOVE
;
1344 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1345 flags
|= wxLIST_HITTEST_BELOW
;
1346 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1347 flags
|= wxLIST_HITTEST_NOWHERE
;
1348 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1349 flags
|= wxLIST_HITTEST_ONITEMICON
;
1350 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1351 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1352 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1353 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1354 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1355 flags
|= wxLIST_HITTEST_TOLEFT
;
1356 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1357 flags
|= wxLIST_HITTEST_TORIGHT
;
1359 return (long) hitTestInfo
.iItem
;
1362 // Inserts an item, returning the index of the new item if successful,
1364 long wxListCtrl::InsertItem(wxListItem
& info
)
1366 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1369 wxConvertToMSWListItem(this, info
, item
);
1370 item
.mask
&= ~LVIF_PARAM
;
1372 // check wether we need to allocate our internal data
1373 bool needInternalData
= ((info
.m_mask
& wxLIST_MASK_DATA
) || info
.HasAttributes());
1374 if (needInternalData
)
1376 m_AnyInternalData
= TRUE
;
1377 item
.mask
|= LVIF_PARAM
;
1379 // internal stucture that manages data
1380 wxListItemInternalData
*data
= new wxListItemInternalData();
1381 item
.lParam
= (LPARAM
) data
;
1383 if (info
.m_mask
& wxLIST_MASK_DATA
)
1384 data
->lParam
= info
.m_data
;
1386 // check whether it has any custom attributes
1387 if ( info
.HasAttributes() )
1389 // take copy of attributes
1390 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
1395 return (long) ListView_InsertItem(GetHwnd(), & item
);
1398 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1401 info
.m_text
= label
;
1402 info
.m_mask
= wxLIST_MASK_TEXT
;
1403 info
.m_itemId
= index
;
1404 return InsertItem(info
);
1407 // Inserts an image item
1408 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1411 info
.m_image
= imageIndex
;
1412 info
.m_mask
= wxLIST_MASK_IMAGE
;
1413 info
.m_itemId
= index
;
1414 return InsertItem(info
);
1417 // Inserts an image/string item
1418 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1421 info
.m_image
= imageIndex
;
1422 info
.m_text
= label
;
1423 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1424 info
.m_itemId
= index
;
1425 return InsertItem(info
);
1428 // For list view mode (only), inserts a column.
1429 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1432 wxConvertToMSWListCol(col
, item
, lvCol
);
1434 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1436 // always give some width to the new column: this one is compatible
1437 // with the generic version
1438 lvCol
.mask
|= LVCF_WIDTH
;
1442 // when we insert a column which can contain an image, we must specify this
1443 // flag right now as doing it later in SetColumn() has no effect
1445 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1446 // way to dynamically set/clear the bitmap as the column without a bitmap
1447 // on the left looks ugly (there is a hole)
1449 // unfortunately with my version of comctl32.dll (5.80), the left column
1450 // image is always on the left and it seems that it's a "feature" - I
1451 // didn't find any way to work around it in any case
1452 if ( lvCol
.mask
& LVCF_IMAGE
)
1454 lvCol
.mask
|= LVCF_FMT
;
1455 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
;
1458 bool success
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
) != -1;
1465 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1472 long wxListCtrl::InsertColumn(long col
,
1473 const wxString
& heading
,
1478 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1479 item
.m_text
= heading
;
1482 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1483 item
.m_width
= width
;
1485 item
.m_format
= format
;
1487 return InsertColumn(col
, item
);
1490 // Scrolls the list control. If in icon, small icon or report view mode,
1491 // x specifies the number of pixels to scroll. If in list view mode, x
1492 // specifies the number of columns to scroll.
1493 // If in icon, small icon or list view mode, y specifies the number of pixels
1494 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1495 bool wxListCtrl::ScrollList(int dx
, int dy
)
1497 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1502 // fn is a function which takes 3 long arguments: item1, item2, data.
1503 // item1 is the long data associated with a first item (NOT the index).
1504 // item2 is the long data associated with a second item (NOT the index).
1505 // data is the same value as passed to SortItems.
1506 // The return value is a negative number if the first item should precede the second
1507 // item, a positive number of the second item should precede the first,
1508 // or zero if the two items are equivalent.
1510 // data is arbitrary data to be passed to the sort function.
1512 // Internal structures for proxying the user compare function
1513 // so that we can pass it the *real* user data
1515 // translate lParam data and call user func
1516 struct wxInternalDataSort
1518 wxListCtrlCompare user_fn
;
1522 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
1524 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
1526 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
1527 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
1529 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
1530 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
1532 return internalData
->user_fn(d1
, d2
, internalData
->data
);
1536 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1538 struct wxInternalDataSort internalData
;
1539 internalData
.user_fn
= fn
;
1540 internalData
.data
= data
;
1542 // WPARAM cast is needed for mingw/cygwin
1543 if ( !ListView_SortItems(GetHwnd(),
1544 wxInternalDataCompareFunc
,
1545 (WPARAM
) &internalData
) )
1547 wxLogDebug(_T("ListView_SortItems() failed"));
1557 // ----------------------------------------------------------------------------
1558 // message processing
1559 // ----------------------------------------------------------------------------
1561 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1563 if (cmd
== EN_UPDATE
)
1565 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1566 event
.SetEventObject( this );
1567 ProcessCommand(event
);
1570 else if (cmd
== EN_KILLFOCUS
)
1572 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1573 event
.SetEventObject( this );
1574 ProcessCommand(event
);
1581 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1583 // prepare the event
1584 // -----------------
1586 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1587 event
.SetEventObject(this);
1589 wxEventType eventType
= wxEVT_NULL
;
1591 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1593 // if your compiler is as broken as this, you should really change it: this
1594 // code is needed for normal operation! #ifdef below is only useful for
1595 // automatic rebuilds which are done with a very old compiler version
1596 #ifdef HDN_BEGINTRACKA
1598 // check for messages from the header (in report view)
1599 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1601 // is it a message from the header?
1602 if ( nmhdr
->hwndFrom
== hwndHdr
)
1604 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1606 event
.m_itemIndex
= -1;
1608 switch ( nmhdr
->code
)
1610 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1611 // TRACK messages even to ANSI programs: on my system I get
1612 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1614 // work around is to simply catch both versions and hope that it
1615 // works (why should this message exist in ANSI and Unicode is
1616 // beyond me as it doesn't deal with strings at all...)
1617 case HDN_BEGINTRACKA
:
1618 case HDN_BEGINTRACKW
:
1619 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1624 if ( eventType
== wxEVT_NULL
)
1625 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1630 if ( eventType
== wxEVT_NULL
)
1631 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1632 event
.m_col
= nmHDR
->iItem
;
1637 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1640 // find the column clicked: we have to search for it
1641 // ourselves as the notification message doesn't provide
1644 // where did the click occur?
1646 if ( !::GetCursorPos(&ptClick
) )
1648 wxLogLastError(_T("GetCursorPos"));
1651 if ( !::ScreenToClient(hwndHdr
, &ptClick
) )
1653 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1656 event
.m_pointDrag
.x
= ptClick
.x
;
1657 event
.m_pointDrag
.y
= ptClick
.y
;
1659 int colCount
= Header_GetItemCount(hwndHdr
);
1662 for ( int col
= 0; col
< colCount
; col
++ )
1664 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1666 if ( ::PtInRect(&rect
, ptClick
) )
1677 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1681 #endif // defined(HDN_BEGINTRACKA)
1682 if ( nmhdr
->hwndFrom
== GetHwnd() )
1684 // almost all messages use NM_LISTVIEW
1685 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1687 // this is true for almost all events
1688 event
.m_item
.m_data
= nmLV
->lParam
;
1690 switch ( nmhdr
->code
)
1692 case LVN_BEGINRDRAG
:
1693 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1697 if ( eventType
== wxEVT_NULL
)
1699 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1702 event
.m_itemIndex
= nmLV
->iItem
;
1703 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1704 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1707 // NB: we have to handle both *A and *W versions here because some
1708 // versions of comctl32.dll send ANSI message to an Unicode app
1709 case LVN_BEGINLABELEDITA
:
1711 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1712 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1713 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1714 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1717 case LVN_BEGINLABELEDITW
:
1719 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1720 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1721 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1722 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1726 case LVN_ENDLABELEDITA
:
1728 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1729 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1730 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1731 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1732 ((LV_ITEM
)item
).iItem
== -1 )
1735 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1738 case LVN_ENDLABELEDITW
:
1740 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1741 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1742 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1743 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1744 ((LV_ITEM
)item
).iItem
== -1 )
1747 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1751 case LVN_COLUMNCLICK
:
1752 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1753 event
.m_itemIndex
= -1;
1754 event
.m_col
= nmLV
->iSubItem
;
1757 case LVN_DELETEALLITEMS
:
1758 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1759 event
.m_itemIndex
= -1;
1762 case LVN_DELETEITEM
:
1763 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1764 event
.m_itemIndex
= nmLV
->iItem
;
1766 // delete the assoicated internal data
1768 wxListItemInternalData
*data
=
1769 GetInternalData(this, nmLV
->iItem
);
1775 case LVN_SETDISPINFO
:
1777 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1778 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1779 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
1783 case LVN_INSERTITEM
:
1784 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1785 event
.m_itemIndex
= nmLV
->iItem
;
1788 case LVN_ITEMCHANGED
:
1789 // we translate this catch all message into more interesting
1790 // (and more easy to process) wxWindows events
1792 // first of all, we deal with the state change events only
1793 if ( nmLV
->uChanged
& LVIF_STATE
)
1795 // temp vars for readability
1796 const UINT stOld
= nmLV
->uOldState
;
1797 const UINT stNew
= nmLV
->uNewState
;
1799 // has the focus changed?
1800 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
1802 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
1803 event
.m_itemIndex
= nmLV
->iItem
;
1806 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
1808 if ( eventType
!= wxEVT_NULL
)
1810 // focus and selection have both changed: send the
1811 // focus event from here and the selection one
1813 event
.SetEventType(eventType
);
1814 (void)GetEventHandler()->ProcessEvent(event
);
1816 else // no focus event to send
1818 // then need to set m_itemIndex as it wasn't done
1820 event
.m_itemIndex
= nmLV
->iItem
;
1823 eventType
= stNew
& LVIS_SELECTED
1824 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1825 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1829 if ( eventType
== wxEVT_NULL
)
1831 // not an interesting event for us
1839 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1840 WORD wVKey
= info
->wVKey
;
1842 // get the current selection
1843 long lItem
= GetNextItem(-1,
1845 wxLIST_STATE_SELECTED
);
1847 // <Enter> or <Space> activate the selected item if any (but
1848 // not with Shift and/or Ctrl as then they have a predefined
1849 // meaning for the list view)
1851 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
1852 !(wxIsShiftDown() || wxIsCtrlDown()) )
1854 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1858 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1860 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1861 // value which should be used as is
1862 int code
= wxCharCodeMSWToWX(wVKey
);
1863 event
.m_code
= code
? code
: wVKey
;
1867 event
.m_item
.m_itemId
= lItem
;
1871 // fill the other fields too
1872 event
.m_item
.m_text
= GetItemText(lItem
);
1873 event
.m_item
.m_data
= GetItemData(lItem
);
1879 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1881 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1886 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1887 // if it happened on an item (and not on empty place)
1888 if ( nmLV
->iItem
== -1 )
1894 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1895 event
.m_itemIndex
= nmLV
->iItem
;
1896 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1897 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1901 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1902 // don't do anything else
1903 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1908 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1909 LV_HITTESTINFO lvhti
;
1910 wxZeroMemory(lvhti
);
1912 ::GetCursorPos(&(lvhti
.pt
));
1913 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1914 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1916 if ( lvhti
.flags
& LVHT_ONITEM
)
1918 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1919 event
.m_itemIndex
= lvhti
.iItem
;
1920 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
1921 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
1926 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1927 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
1929 *result
= OnCustomDraw(lParam
);
1932 #endif // _WIN32_IE >= 0x300
1934 case LVN_ODCACHEHINT
:
1936 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
1938 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
1940 // we get some really stupid cache hints like ones for items in
1941 // range 0..0 for an empty control or, after deleting an item,
1942 // for items in invalid range - filter this garbage out
1943 if ( cacheHint
->iFrom
< cacheHint
->iTo
)
1945 event
.m_oldItemIndex
= cacheHint
->iFrom
;
1947 long iMax
= GetItemCount();
1948 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
1958 case LVN_GETDISPINFO
:
1961 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1963 LV_ITEM
& lvi
= info
->item
;
1964 long item
= lvi
.iItem
;
1966 if ( lvi
.mask
& LVIF_TEXT
)
1968 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
1969 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
1972 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1973 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
1974 if ( lvi
.mask
& LVIF_IMAGE
)
1976 lvi
.iImage
= OnGetItemImage(item
);
1980 // a little dose of healthy paranoia: as we never use
1981 // LVM_SETCALLBACKMASK we're not supposed to get these ones
1982 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
1983 _T("we don't support state callbacks yet!") );
1990 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1995 // where did this one come from?
1999 // process the event
2000 // -----------------
2002 event
.SetEventType(eventType
);
2004 if ( !GetEventHandler()->ProcessEvent(event
) )
2010 switch ( nmhdr
->code
)
2012 case LVN_DELETEALLITEMS
:
2013 // always return TRUE to suppress all additional LVN_DELETEITEM
2014 // notifications - this makes deleting all items from a list ctrl
2020 case LVN_ENDLABELEDITA
:
2021 case LVN_ENDLABELEDITW
:
2022 // logic here is inversed compared to all the other messages
2023 *result
= event
.IsAllowed();
2028 *result
= !event
.IsAllowed();
2033 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
2035 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
2037 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
2038 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
2039 switch ( nmcd
.dwDrawStage
)
2042 // if we've got any items with non standard attributes,
2043 // notify us before painting each item
2045 // for virtual controls, always suppose that we have attributes as
2046 // there is no way to check for this
2047 return IsVirtual() || m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
2050 case CDDS_ITEMPREPAINT
:
2052 size_t item
= (size_t)nmcd
.dwItemSpec
;
2053 if ( item
>= (size_t)GetItemCount() )
2055 // we get this message with item == 0 for an empty control,
2056 // we must ignore it as calling OnGetItemAttr() would be
2058 return CDRF_DODEFAULT
;
2061 wxListItemAttr
*attr
=
2062 IsVirtual() ? OnGetItemAttr(item
)
2063 : GetInternalDataAttr(this, item
);
2067 // nothing to do for this item
2068 return CDRF_DODEFAULT
;
2072 wxColour colText
, colBack
;
2073 if ( attr
->HasFont() )
2075 wxFont font
= attr
->GetFont();
2076 hFont
= (HFONT
)font
.GetResourceHandle();
2083 if ( attr
->HasTextColour() )
2085 colText
= attr
->GetTextColour();
2089 colText
= GetTextColour();
2092 if ( attr
->HasBackgroundColour() )
2094 colBack
= attr
->GetBackgroundColour();
2098 colBack
= GetBackgroundColour();
2101 lplvcd
->clrText
= wxColourToRGB(colText
);
2102 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
2104 // note that if we wanted to set colours for
2105 // individual columns (subitems), we would have
2106 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2109 ::SelectObject(nmcd
.hdc
, hFont
);
2111 return CDRF_NEWFONT
;
2114 // fall through to return CDRF_DODEFAULT
2117 return CDRF_DODEFAULT
;
2121 #endif // NM_CUSTOMDRAW supported
2123 // Necessary for drawing hrules and vrules, if specified
2124 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2128 wxControl::OnPaint(event
);
2130 // Reset the device origin since it may have been set
2131 dc
.SetDeviceOrigin(0, 0);
2133 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
2134 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
2136 if (!drawHRules
&& !drawVRules
)
2138 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
2141 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2143 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2145 wxSize clientSize
= GetClientSize();
2149 int itemCount
= GetItemCount();
2153 long top
= GetTopItem();
2154 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2156 if (GetItemRect(i
, itemRect
))
2158 cy
= itemRect
.GetTop();
2159 if (i
!= 0) // Don't draw the first one
2161 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2164 if (i
== itemCount
- 1)
2166 cy
= itemRect
.GetBottom();
2167 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2173 if (drawVRules
&& (i
> -1))
2175 wxRect firstItemRect
;
2176 GetItemRect(0, firstItemRect
);
2178 if (GetItemRect(i
, itemRect
))
2181 int x
= itemRect
.GetX();
2182 for (col
= 0; col
< GetColumnCount(); col
++)
2184 int colWidth
= GetColumnWidth(col
);
2186 dc
.DrawLine(x
, firstItemRect
.GetY() - 2, x
, itemRect
.GetBottom());
2192 // ----------------------------------------------------------------------------
2193 // virtual list controls
2194 // ----------------------------------------------------------------------------
2196 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2198 // this is a pure virtual function, in fact - which is not really pure
2199 // because the controls which are not virtual don't need to implement it
2200 wxFAIL_MSG( _T("not supposed to be called") );
2202 return wxEmptyString
;
2205 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2208 wxFAIL_MSG( _T("not supposed to be called") );
2213 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2215 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2216 _T("invalid item index in OnGetItemAttr()") );
2218 // no attributes by default
2222 void wxListCtrl::SetItemCount(long count
)
2224 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2226 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
, 0) )
2228 wxLogLastError(_T("ListView_SetItemCount"));
2232 void wxListCtrl::RefreshItem(long item
)
2234 // strangely enough, ListView_Update() results in much more flicker here
2235 // than a dumb Refresh() -- why?
2237 if ( !ListView_Update(GetHwnd(), item
) )
2239 wxLogLastError(_T("ListView_Update"));
2243 GetItemRect(item
, rect
);
2248 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2250 wxRect rect1
, rect2
;
2251 GetItemRect(itemFrom
, rect1
);
2252 GetItemRect(itemTo
, rect2
);
2254 wxRect rect
= rect1
;
2255 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2260 static wxListItemInternalData
*GetInternalData(HWND hwnd
, long itemId
)
2263 it
.mask
= LVIF_PARAM
;
2266 bool success
= ListView_GetItem(hwnd
, &it
) != 0;
2268 return (wxListItemInternalData
*) it
.lParam
;
2273 static wxListItemInternalData
*GetInternalData(wxListCtrl
*ctl
, long itemId
)
2275 return GetInternalData((HWND
) ctl
->GetHWND(), itemId
);
2278 static wxListItemAttr
*GetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
2280 wxListItemInternalData
*data
= GetInternalData(ctl
, itemId
);
2288 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2292 wxListItemInternalData
*internaldata
=
2293 (wxListItemInternalData
*) lvItem
.lParam
;
2296 info
.m_data
= internaldata
->lParam
;
2300 info
.m_stateMask
= 0;
2301 info
.m_itemId
= lvItem
.iItem
;
2303 long oldMask
= lvItem
.mask
;
2305 bool needText
= FALSE
;
2306 if (hwndListCtrl
!= 0)
2308 if ( lvItem
.mask
& LVIF_TEXT
)
2315 lvItem
.pszText
= new wxChar
[513];
2316 lvItem
.cchTextMax
= 512;
2318 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2319 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2322 if ( lvItem
.mask
& LVIF_STATE
)
2324 info
.m_mask
|= wxLIST_MASK_STATE
;
2326 if ( lvItem
.stateMask
& LVIS_CUT
)
2328 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2329 if ( lvItem
.state
& LVIS_CUT
)
2330 info
.m_state
|= wxLIST_STATE_CUT
;
2332 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2334 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2335 if ( lvItem
.state
& LVIS_DROPHILITED
)
2336 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2338 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2340 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2341 if ( lvItem
.state
& LVIS_FOCUSED
)
2342 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2344 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2346 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2347 if ( lvItem
.state
& LVIS_SELECTED
)
2348 info
.m_state
|= wxLIST_STATE_SELECTED
;
2352 if ( lvItem
.mask
& LVIF_TEXT
)
2354 info
.m_mask
|= wxLIST_MASK_TEXT
;
2355 info
.m_text
= lvItem
.pszText
;
2357 if ( lvItem
.mask
& LVIF_IMAGE
)
2359 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2360 info
.m_image
= lvItem
.iImage
;
2362 if ( lvItem
.mask
& LVIF_PARAM
)
2363 info
.m_mask
|= wxLIST_MASK_DATA
;
2364 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2365 info
.m_mask
|= wxLIST_SET_ITEM
;
2366 info
.m_col
= lvItem
.iSubItem
;
2371 delete[] lvItem
.pszText
;
2373 lvItem
.mask
= oldMask
;
2376 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2378 if (stateMask
& wxLIST_STATE_CUT
)
2380 lvItem
.stateMask
|= LVIS_CUT
;
2381 if (state
& wxLIST_STATE_CUT
)
2382 lvItem
.state
|= LVIS_CUT
;
2384 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2386 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2387 if (state
& wxLIST_STATE_DROPHILITED
)
2388 lvItem
.state
|= LVIS_DROPHILITED
;
2390 if (stateMask
& wxLIST_STATE_FOCUSED
)
2392 lvItem
.stateMask
|= LVIS_FOCUSED
;
2393 if (state
& wxLIST_STATE_FOCUSED
)
2394 lvItem
.state
|= LVIS_FOCUSED
;
2396 if (stateMask
& wxLIST_STATE_SELECTED
)
2398 lvItem
.stateMask
|= LVIS_SELECTED
;
2399 if (state
& wxLIST_STATE_SELECTED
)
2400 lvItem
.state
|= LVIS_SELECTED
;
2404 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2405 const wxListItem
& info
,
2408 lvItem
.iItem
= (int) info
.m_itemId
;
2410 lvItem
.iImage
= info
.m_image
;
2411 lvItem
.stateMask
= 0;
2414 lvItem
.iSubItem
= info
.m_col
;
2416 if (info
.m_mask
& wxLIST_MASK_STATE
)
2418 lvItem
.mask
|= LVIF_STATE
;
2420 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2423 if (info
.m_mask
& wxLIST_MASK_TEXT
)
2425 lvItem
.mask
|= LVIF_TEXT
;
2426 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
2428 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
2432 // pszText is not const, hence the cast
2433 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
2434 if ( lvItem
.pszText
)
2435 lvItem
.cchTextMax
= info
.m_text
.Length();
2437 lvItem
.cchTextMax
= 0;
2440 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
2441 lvItem
.mask
|= LVIF_IMAGE
;
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