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
)
115 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX((const __wchar_t
* ) item
.pszText
));
117 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX(item
.pszText
));
119 m_item
->pszText
= (wxChar
*)m_buf
->data();
124 wxLV_ITEM(LV_ITEMA
&item
) : m_buf(NULL
), m_item(&item
) {}
132 ///////////////////////////////////////////////////////
134 // The MSW version had problems with SetTextColour() et
135 // al as the wxListItemAttr's were stored keyed on the
136 // item index. If a item was inserted anywhere but the end
137 // of the list the the text attributes (colour etc) for
138 // the following items were out of sync.
141 // Under MSW the only way to associate data with a List
142 // item independant of its position in the list is to
143 // store a pointer to it in its lParam attribute. However
144 // user programs are already using this (via the
145 // SetItemData() GetItemData() calls).
147 // However what we can do is store a pointer to a
148 // structure which contains the attributes we want *and*
149 // a lParam for the users data, e.g.
151 // class wxListItemInternalData
154 // wxListItemAttr *attr;
155 // long lParam; // user data
158 // To conserve memory, a wxListItemInternalData is
159 // only allocated for a LV_ITEM if text attributes or
160 // user data(lparam) are being set.
163 // class wxListItemInternalData
164 class wxListItemInternalData
167 wxListItemAttr
*attr
;
168 LPARAM lParam
; // user data
170 wxListItemInternalData() : attr(NULL
), lParam(0) {}
171 ~wxListItemInternalData()
178 // Get the internal data structure
179 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
);
180 static wxListItemInternalData
*wxGetInternalData(wxListCtrl
*ctl
, long itemId
);
181 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
);
182 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
);
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
190 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
191 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
192 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
193 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
194 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
195 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
196 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
197 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
198 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
199 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
200 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
201 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
202 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
203 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
204 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
205 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
206 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
207 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
208 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
209 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
210 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
212 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
213 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
214 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
216 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
218 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
219 EVT_PAINT(wxListCtrl::OnPaint
)
222 // ============================================================================
224 // ============================================================================
226 // ----------------------------------------------------------------------------
227 // wxListCtrl construction
228 // ----------------------------------------------------------------------------
230 void wxListCtrl::Init()
232 m_imageListNormal
= NULL
;
233 m_imageListSmall
= NULL
;
234 m_imageListState
= NULL
;
235 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
239 m_AnyInternalData
= FALSE
;
240 m_hasAnyAttr
= FALSE
;
243 bool wxListCtrl::Create(wxWindow
*parent
,
248 const wxValidator
& validator
,
249 const wxString
& name
)
252 SetValidator(validator
);
253 #endif // wxUSE_VALIDATORS
262 m_windowStyle
= style
;
275 m_windowId
= (id
== -1) ? NewControlId() : id
;
277 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
278 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
280 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
281 wstyle
|= WS_CLIPSIBLINGS
;
283 if ( wxStyleHasBorder(m_windowStyle
) )
285 m_baseStyle
= wstyle
;
287 if ( !DoCreateControl(x
, y
, width
, height
) )
291 parent
->AddChild(this);
296 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
298 DWORD wstyle
= m_baseStyle
;
301 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
303 // Even with extended styles, need to combine with WS_BORDER
304 // for them to look right.
308 long oldStyle
= 0; // Dummy
309 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
311 // Create the ListView control.
312 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
317 GetWinHwnd(GetParent()),
324 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
329 // for comctl32.dll v 4.70+ we want to have this attribute because it's
330 // prettier (and also because wxGTK does it like this)
331 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
333 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
334 0, LVS_EX_FULLROWSELECT
);
337 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
338 SetForegroundColour(GetParent()->GetForegroundColour());
345 void wxListCtrl::UpdateStyle()
349 // The new window view style
351 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
352 dwStyleNew
|= m_baseStyle
;
354 // Get the current window style.
355 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
357 // Only set the window style if the view bits have changed.
358 if ( dwStyleOld
!= dwStyleNew
)
360 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
365 void wxListCtrl::FreeAllInternalData()
367 if (m_AnyInternalData
)
369 int n
= GetItemCount();
372 for (i
= 0; i
< n
; i
++)
373 wxDeleteInternalData(this, i
);
375 m_AnyInternalData
= FALSE
;
379 wxListCtrl::~wxListCtrl()
381 FreeAllInternalData();
385 m_textCtrl
->SetHWND(0);
386 m_textCtrl
->UnsubclassWin();
391 if (m_ownsImageListNormal
) delete m_imageListNormal
;
392 if (m_ownsImageListSmall
) delete m_imageListSmall
;
393 if (m_ownsImageListState
) delete m_imageListState
;
396 // ----------------------------------------------------------------------------
397 // set/get/change style
398 // ----------------------------------------------------------------------------
400 // Add or remove a single window style
401 void wxListCtrl::SetSingleStyle(long style
, bool add
)
403 long flag
= GetWindowStyleFlag();
405 // Get rid of conflicting styles
408 if ( style
& wxLC_MASK_TYPE
)
409 flag
= flag
& ~wxLC_MASK_TYPE
;
410 if ( style
& wxLC_MASK_ALIGN
)
411 flag
= flag
& ~wxLC_MASK_ALIGN
;
412 if ( style
& wxLC_MASK_SORT
)
413 flag
= flag
& ~wxLC_MASK_SORT
;
429 m_windowStyle
= flag
;
434 // Set the whole window style
435 void wxListCtrl::SetWindowStyleFlag(long flag
)
437 m_windowStyle
= flag
;
442 // Can be just a single style, or a bitlist
443 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
446 if ( style
& wxLC_ICON
)
448 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
449 oldStyle
-= LVS_SMALLICON
;
450 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
451 oldStyle
-= LVS_REPORT
;
452 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
453 oldStyle
-= LVS_LIST
;
457 if ( style
& wxLC_SMALL_ICON
)
459 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
460 oldStyle
-= LVS_ICON
;
461 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
462 oldStyle
-= LVS_REPORT
;
463 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
464 oldStyle
-= LVS_LIST
;
465 wstyle
|= LVS_SMALLICON
;
468 if ( style
& wxLC_LIST
)
470 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
471 oldStyle
-= LVS_ICON
;
472 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
473 oldStyle
-= LVS_REPORT
;
474 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
475 oldStyle
-= LVS_SMALLICON
;
479 if ( style
& wxLC_REPORT
)
481 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
482 oldStyle
-= LVS_ICON
;
483 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
484 oldStyle
-= LVS_LIST
;
485 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
486 oldStyle
-= LVS_SMALLICON
;
488 wstyle
|= LVS_REPORT
;
491 if ( style
& wxLC_ALIGN_LEFT
)
493 if ( oldStyle
& LVS_ALIGNTOP
)
494 oldStyle
-= LVS_ALIGNTOP
;
495 wstyle
|= LVS_ALIGNLEFT
;
498 if ( style
& wxLC_ALIGN_TOP
)
500 if ( oldStyle
& LVS_ALIGNLEFT
)
501 oldStyle
-= LVS_ALIGNLEFT
;
502 wstyle
|= LVS_ALIGNTOP
;
505 if ( style
& wxLC_AUTOARRANGE
)
506 wstyle
|= LVS_AUTOARRANGE
;
508 if ( style
& wxLC_NO_SORT_HEADER
)
509 wstyle
|= LVS_NOSORTHEADER
;
511 if ( style
& wxLC_NO_HEADER
)
512 wstyle
|= LVS_NOCOLUMNHEADER
;
514 if ( style
& wxLC_EDIT_LABELS
)
515 wstyle
|= LVS_EDITLABELS
;
517 if ( style
& wxLC_SINGLE_SEL
)
518 wstyle
|= LVS_SINGLESEL
;
520 if ( style
& wxLC_SORT_ASCENDING
)
522 if ( oldStyle
& LVS_SORTDESCENDING
)
523 oldStyle
-= LVS_SORTDESCENDING
;
524 wstyle
|= LVS_SORTASCENDING
;
527 if ( style
& wxLC_SORT_DESCENDING
)
529 if ( oldStyle
& LVS_SORTASCENDING
)
530 oldStyle
-= LVS_SORTASCENDING
;
531 wstyle
|= LVS_SORTDESCENDING
;
534 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
535 if ( style
& wxLC_VIRTUAL
)
537 int ver
= wxTheApp
->GetComCtl32Version();
540 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."),
541 ver
/ 100, ver
% 100);
544 wstyle
|= LVS_OWNERDATA
;
551 // ----------------------------------------------------------------------------
553 // ----------------------------------------------------------------------------
555 // Sets the foreground, i.e. text, colour
556 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
558 if ( !wxWindow::SetForegroundColour(col
) )
561 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
566 // Sets the background colour
567 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
569 if ( !wxWindow::SetBackgroundColour(col
) )
572 // we set the same colour for both the "empty" background and the items
574 COLORREF color
= wxColourToRGB(col
);
575 ListView_SetBkColor(GetHwnd(), color
);
576 ListView_SetTextBkColor(GetHwnd(), color
);
581 // Gets information about this column
582 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
587 lvCol
.mask
= LVCF_WIDTH
;
589 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
591 lvCol
.mask
|= LVCF_TEXT
;
592 lvCol
.pszText
= new wxChar
[513];
593 lvCol
.cchTextMax
= 512;
596 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
598 lvCol
.mask
|= LVCF_FMT
;
601 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
603 lvCol
.mask
|= LVCF_IMAGE
;
606 bool success
= ListView_GetColumn(GetHwnd(), col
, &lvCol
) != 0;
608 // item.m_subItem = lvCol.iSubItem;
609 item
.m_width
= lvCol
.cx
;
611 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
613 item
.m_text
= lvCol
.pszText
;
614 delete[] lvCol
.pszText
;
617 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
619 switch (lvCol
.fmt
& LVCFMT_JUSTIFYMASK
) {
621 item
.m_format
= wxLIST_FORMAT_LEFT
;
624 item
.m_format
= wxLIST_FORMAT_RIGHT
;
627 item
.m_format
= wxLIST_FORMAT_CENTRE
;
630 item
.m_format
= -1; // Unknown?
635 #if _WIN32_IE >= 0x0300
636 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
638 item
.m_image
= lvCol
.iImage
;
645 // Sets information about this column
646 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
649 wxConvertToMSWListCol(col
, item
, lvCol
);
651 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
654 // Gets the column width
655 int wxListCtrl::GetColumnWidth(int col
) const
657 return ListView_GetColumnWidth(GetHwnd(), col
);
660 // Sets the column width
661 bool wxListCtrl::SetColumnWidth(int col
, int width
)
664 if ( m_windowStyle
& wxLC_LIST
)
668 if ( width2
== wxLIST_AUTOSIZE
)
669 width2
= LVSCW_AUTOSIZE
;
670 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
671 width2
= LVSCW_AUTOSIZE_USEHEADER
;
673 return ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0;
676 // Gets the number of items that can fit vertically in the
677 // visible area of the list control (list or report view)
678 // or the total number of items in the list control (icon
679 // or small icon view)
680 int wxListCtrl::GetCountPerPage() const
682 return ListView_GetCountPerPage(GetHwnd());
685 // Gets the edit control for editing labels.
686 wxTextCtrl
* wxListCtrl::GetEditControl() const
691 // Gets information about the item
692 bool wxListCtrl::GetItem(wxListItem
& info
) const
695 wxZeroMemory(lvItem
);
697 lvItem
.iItem
= info
.m_itemId
;
698 lvItem
.iSubItem
= info
.m_col
;
700 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
702 lvItem
.mask
|= LVIF_TEXT
;
703 lvItem
.pszText
= new wxChar
[513];
704 lvItem
.cchTextMax
= 512;
708 lvItem
.pszText
= NULL
;
711 if (info
.m_mask
& wxLIST_MASK_DATA
)
712 lvItem
.mask
|= LVIF_PARAM
;
714 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
715 lvItem
.mask
|= LVIF_IMAGE
;
717 if ( info
.m_mask
& wxLIST_MASK_STATE
)
719 lvItem
.mask
|= LVIF_STATE
;
720 // the other bits are hardly interesting anyhow
721 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
724 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
727 wxLogError(_("Couldn't retrieve information about list control item %d."),
732 // give NULL as hwnd as we already have everything we need
733 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
737 delete[] lvItem
.pszText
;
742 // Sets information about the item
743 bool wxListCtrl::SetItem(wxListItem
& info
)
746 wxConvertToMSWListItem(this, info
, item
);
748 // we never update the lParam if it contains our pointer
749 // to the wxListItemInternalData structure
750 item
.mask
&= ~LVIF_PARAM
;
752 // check if setting attributes or lParam
753 if (info
.HasAttributes() || (info
.m_mask
& wxLIST_MASK_DATA
))
755 // get internal item data
756 // perhaps a cache here ?
757 wxListItemInternalData
*data
= wxGetInternalData(this, info
.m_itemId
);
762 m_AnyInternalData
= TRUE
;
763 data
= new wxListItemInternalData();
764 item
.lParam
= (LPARAM
) data
;
765 item
.mask
|= LVIF_PARAM
;
770 if (info
.m_mask
& wxLIST_MASK_DATA
)
771 data
->lParam
= info
.m_data
;
774 if (info
.HasAttributes())
777 *data
->attr
= *info
.GetAttributes();
779 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
784 // we could be changing only the attribute in which case we don't need to
785 // call ListView_SetItem() at all
789 if ( !ListView_SetItem(GetHwnd(), &item
) )
791 wxLogDebug(_T("ListView_SetItem() failed"));
797 // we need to update the item immediately to show the new image
798 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
800 // check whether it has any custom attributes
801 if ( info
.HasAttributes() )
805 // if the colour has changed, we must redraw the item
811 // we need this to make the change visible right now
812 RefreshItem(item
.iItem
);
818 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
822 info
.m_mask
= wxLIST_MASK_TEXT
;
823 info
.m_itemId
= index
;
827 info
.m_image
= imageId
;
828 info
.m_mask
|= wxLIST_MASK_IMAGE
;
830 return SetItem(info
);
834 // Gets the item state
835 int wxListCtrl::GetItemState(long item
, long stateMask
) const
839 info
.m_mask
= wxLIST_MASK_STATE
;
840 info
.m_stateMask
= stateMask
;
841 info
.m_itemId
= item
;
849 // Sets the item state
850 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
852 // NB: don't use SetItem() here as it doesn't work with the virtual list
855 wxZeroMemory(lvItem
);
857 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
859 // for the virtual list controls we need to refresh the previously focused
860 // item manually when changing focus without changing selection
861 // programmatically because otherwise it keeps its focus rectangle until
862 // next repaint (yet another comctl32 bug)
865 (stateMask
& wxLIST_STATE_FOCUSED
) &&
866 (state
& wxLIST_STATE_FOCUSED
) )
868 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
875 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
876 (WPARAM
)item
, (LPARAM
)&lvItem
) )
878 wxLogLastError(_T("ListView_SetItemState"));
883 if ( focusOld
!= -1 )
885 // no need to refresh the item if it was previously selected, it would
886 // only result in annoying flicker
887 if ( !(GetItemState(focusOld
,
888 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
890 RefreshItem(focusOld
);
897 // Sets the item image
898 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
902 info
.m_mask
= wxLIST_MASK_IMAGE
;
903 info
.m_image
= image
;
904 info
.m_itemId
= item
;
906 return SetItem(info
);
909 // Gets the item text
910 wxString
wxListCtrl::GetItemText(long item
) const
914 info
.m_mask
= wxLIST_MASK_TEXT
;
915 info
.m_itemId
= item
;
922 // Sets the item text
923 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
927 info
.m_mask
= wxLIST_MASK_TEXT
;
928 info
.m_itemId
= item
;
934 // Gets the item data
935 long wxListCtrl::GetItemData(long item
) const
939 info
.m_mask
= wxLIST_MASK_DATA
;
940 info
.m_itemId
= item
;
947 // Sets the item data
948 bool wxListCtrl::SetItemData(long item
, long data
)
952 info
.m_mask
= wxLIST_MASK_DATA
;
953 info
.m_itemId
= item
;
956 return SetItem(info
);
959 // Gets the item rectangle
960 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
965 if ( code
== wxLIST_RECT_BOUNDS
)
966 codeWin
= LVIR_BOUNDS
;
967 else if ( code
== wxLIST_RECT_ICON
)
969 else if ( code
== wxLIST_RECT_LABEL
)
970 codeWin
= LVIR_LABEL
;
973 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
975 codeWin
= LVIR_BOUNDS
;
978 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
980 rect
.x
= rectWin
.left
;
981 rect
.y
= rectWin
.top
;
982 rect
.width
= rectWin
.right
- rectWin
.left
;
983 rect
.height
= rectWin
.bottom
- rectWin
.top
;
988 // Gets the item position
989 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
993 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
995 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
999 // Sets the item position.
1000 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1002 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
1005 // Gets the number of items in the list control
1006 int wxListCtrl::GetItemCount() const
1008 return ListView_GetItemCount(GetHwnd());
1011 // Retrieves the spacing between icons in pixels.
1012 // If small is TRUE, gets the spacing for the small icon
1013 // view, otherwise the large icon view.
1014 int wxListCtrl::GetItemSpacing(bool isSmall
) const
1016 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
1019 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1022 info
.m_itemId
= item
;
1023 info
.SetTextColour( col
);
1027 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1030 info
.m_itemId
= item
;
1032 return info
.GetTextColour();
1035 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1038 info
.m_itemId
= item
;
1039 info
.SetBackgroundColour( col
);
1043 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1046 info
.m_itemId
= item
;
1048 return info
.GetBackgroundColour();
1051 // Gets the number of selected items in the list control
1052 int wxListCtrl::GetSelectedItemCount() const
1054 return ListView_GetSelectedCount(GetHwnd());
1057 // Gets the text colour of the listview
1058 wxColour
wxListCtrl::GetTextColour() const
1060 COLORREF ref
= ListView_GetTextColor(GetHwnd());
1061 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
1065 // Sets the text colour of the listview
1066 void wxListCtrl::SetTextColour(const wxColour
& col
)
1068 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
1071 // Gets the index of the topmost visible item when in
1072 // list or report view
1073 long wxListCtrl::GetTopItem() const
1075 return (long) ListView_GetTopIndex(GetHwnd());
1078 // Searches for an item, starting from 'item'.
1079 // 'geometry' is one of
1080 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1081 // 'state' is a state bit flag, one or more of
1082 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1083 // item can be -1 to find the first item that matches the
1085 // Returns the item or -1 if unsuccessful.
1086 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1090 if ( geom
== wxLIST_NEXT_ABOVE
)
1091 flags
|= LVNI_ABOVE
;
1092 if ( geom
== wxLIST_NEXT_ALL
)
1094 if ( geom
== wxLIST_NEXT_BELOW
)
1095 flags
|= LVNI_BELOW
;
1096 if ( geom
== wxLIST_NEXT_LEFT
)
1097 flags
|= LVNI_TOLEFT
;
1098 if ( geom
== wxLIST_NEXT_RIGHT
)
1099 flags
|= LVNI_TORIGHT
;
1101 if ( state
& wxLIST_STATE_CUT
)
1103 if ( state
& wxLIST_STATE_DROPHILITED
)
1104 flags
|= LVNI_DROPHILITED
;
1105 if ( state
& wxLIST_STATE_FOCUSED
)
1106 flags
|= LVNI_FOCUSED
;
1107 if ( state
& wxLIST_STATE_SELECTED
)
1108 flags
|= LVNI_SELECTED
;
1110 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1114 wxImageList
*wxListCtrl::GetImageList(int which
) const
1116 if ( which
== wxIMAGE_LIST_NORMAL
)
1118 return m_imageListNormal
;
1120 else if ( which
== wxIMAGE_LIST_SMALL
)
1122 return m_imageListSmall
;
1124 else if ( which
== wxIMAGE_LIST_STATE
)
1126 return m_imageListState
;
1131 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1134 if ( which
== wxIMAGE_LIST_NORMAL
)
1136 flags
= LVSIL_NORMAL
;
1137 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1138 m_imageListNormal
= imageList
;
1139 m_ownsImageListNormal
= FALSE
;
1141 else if ( which
== wxIMAGE_LIST_SMALL
)
1143 flags
= LVSIL_SMALL
;
1144 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1145 m_imageListSmall
= imageList
;
1146 m_ownsImageListSmall
= FALSE
;
1148 else if ( which
== wxIMAGE_LIST_STATE
)
1150 flags
= LVSIL_STATE
;
1151 if (m_ownsImageListState
) delete m_imageListState
;
1152 m_imageListState
= imageList
;
1153 m_ownsImageListState
= FALSE
;
1155 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1158 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1160 SetImageList(imageList
, which
);
1161 if ( which
== wxIMAGE_LIST_NORMAL
)
1162 m_ownsImageListNormal
= TRUE
;
1163 else if ( which
== wxIMAGE_LIST_SMALL
)
1164 m_ownsImageListSmall
= TRUE
;
1165 else if ( which
== wxIMAGE_LIST_STATE
)
1166 m_ownsImageListState
= TRUE
;
1169 // ----------------------------------------------------------------------------
1171 // ----------------------------------------------------------------------------
1173 // Arranges the items
1174 bool wxListCtrl::Arrange(int flag
)
1177 if ( flag
== wxLIST_ALIGN_LEFT
)
1178 code
= LVA_ALIGNLEFT
;
1179 else if ( flag
== wxLIST_ALIGN_TOP
)
1180 code
= LVA_ALIGNTOP
;
1181 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1183 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1184 code
= LVA_SNAPTOGRID
;
1186 return (ListView_Arrange(GetHwnd(), code
) != 0);
1190 bool wxListCtrl::DeleteItem(long item
)
1192 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1194 wxLogLastError(_T("ListView_DeleteItem"));
1198 // the virtual list control doesn't refresh itself correctly, help it
1201 // we need to refresh all the lines below the one which was deleted
1203 if ( item
> 0 && GetItemCount() )
1205 GetItemRect(item
- 1, rectItem
);
1210 rectItem
.height
= 0;
1213 wxRect rectWin
= GetRect();
1214 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1215 rectWin
.y
= rectItem
.GetBottom();
1217 RefreshRect(rectWin
);
1223 // Deletes all items
1224 bool wxListCtrl::DeleteAllItems()
1226 return ListView_DeleteAllItems(GetHwnd()) != 0;
1229 // Deletes all items
1230 bool wxListCtrl::DeleteAllColumns()
1232 while ( m_colCount
> 0 )
1234 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1236 wxLogLastError(wxT("ListView_DeleteColumn"));
1244 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1250 bool wxListCtrl::DeleteColumn(int col
)
1252 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1254 if ( success
&& (m_colCount
> 0) )
1259 // Clears items, and columns if there are any.
1260 void wxListCtrl::ClearAll()
1263 if ( m_colCount
> 0 )
1267 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1269 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1271 // ListView_EditLabel requires that the list has focus.
1273 WXHWND hWnd
= (WXHWND
) ListView_EditLabel(GetHwnd(), item
);
1277 m_textCtrl
->SetHWND(0);
1278 m_textCtrl
->UnsubclassWin();
1282 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1283 m_textCtrl
->SetHWND(hWnd
);
1284 m_textCtrl
->SubclassWin(hWnd
);
1285 m_textCtrl
->SetParent(this);
1290 // End label editing, optionally cancelling the edit
1291 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1293 wxFAIL_MSG( _T("not implemented") );
1298 // Ensures this item is visible
1299 bool wxListCtrl::EnsureVisible(long item
)
1301 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0;
1304 // Find an item whose label matches this string, starting from the item after 'start'
1305 // or the beginning if 'start' is -1.
1306 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1308 LV_FINDINFO findInfo
;
1310 findInfo
.flags
= LVFI_STRING
;
1312 findInfo
.flags
|= LVFI_PARTIAL
;
1315 // ListView_FindItem() excludes the first item from search and to look
1316 // through all the items you need to start from -1 which is unnatural and
1317 // inconsistent with the generic version - so we adjust the index
1320 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1323 // Find an item whose data matches this data, starting from the item after 'start'
1324 // or the beginning if 'start' is -1.
1325 // NOTE : Lindsay Mathieson - 14-July-2002
1326 // No longer use ListView_FindItem as the data attribute is now stored
1327 // in a wxListItemInternalData structure refernced by the actual lParam
1328 long wxListCtrl::FindItem(long start
, long data
)
1330 long idx
= start
+ 1;
1331 long count
= GetItemCount();
1335 if (GetItemData(idx
) == data
)
1343 // Find an item nearest this position in the specified direction, starting from
1344 // the item after 'start' or the beginning if 'start' is -1.
1345 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1347 LV_FINDINFO findInfo
;
1349 findInfo
.flags
= LVFI_NEARESTXY
;
1350 findInfo
.pt
.x
= pt
.x
;
1351 findInfo
.pt
.y
= pt
.y
;
1352 findInfo
.vkDirection
= VK_RIGHT
;
1354 if ( direction
== wxLIST_FIND_UP
)
1355 findInfo
.vkDirection
= VK_UP
;
1356 else if ( direction
== wxLIST_FIND_DOWN
)
1357 findInfo
.vkDirection
= VK_DOWN
;
1358 else if ( direction
== wxLIST_FIND_LEFT
)
1359 findInfo
.vkDirection
= VK_LEFT
;
1360 else if ( direction
== wxLIST_FIND_RIGHT
)
1361 findInfo
.vkDirection
= VK_RIGHT
;
1363 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1366 // Determines which item (if any) is at the specified point,
1367 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1368 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1370 LV_HITTESTINFO hitTestInfo
;
1371 hitTestInfo
.pt
.x
= (int) point
.x
;
1372 hitTestInfo
.pt
.y
= (int) point
.y
;
1374 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1377 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1378 flags
|= wxLIST_HITTEST_ABOVE
;
1379 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1380 flags
|= wxLIST_HITTEST_BELOW
;
1381 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1382 flags
|= wxLIST_HITTEST_NOWHERE
;
1383 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1384 flags
|= wxLIST_HITTEST_ONITEMICON
;
1385 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1386 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1387 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1388 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1389 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1390 flags
|= wxLIST_HITTEST_TOLEFT
;
1391 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1392 flags
|= wxLIST_HITTEST_TORIGHT
;
1394 return (long) hitTestInfo
.iItem
;
1397 // Inserts an item, returning the index of the new item if successful,
1399 long wxListCtrl::InsertItem(wxListItem
& info
)
1401 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1404 wxConvertToMSWListItem(this, info
, item
);
1405 item
.mask
&= ~LVIF_PARAM
;
1407 // check wether we need to allocate our internal data
1408 bool needInternalData
= ((info
.m_mask
& wxLIST_MASK_DATA
) || info
.HasAttributes());
1409 if (needInternalData
)
1411 m_AnyInternalData
= TRUE
;
1412 item
.mask
|= LVIF_PARAM
;
1414 // internal stucture that manages data
1415 wxListItemInternalData
*data
= new wxListItemInternalData();
1416 item
.lParam
= (LPARAM
) data
;
1418 if (info
.m_mask
& wxLIST_MASK_DATA
)
1419 data
->lParam
= info
.m_data
;
1421 // check whether it has any custom attributes
1422 if ( info
.HasAttributes() )
1424 // take copy of attributes
1425 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
1430 return (long) ListView_InsertItem(GetHwnd(), & item
);
1433 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1436 info
.m_text
= label
;
1437 info
.m_mask
= wxLIST_MASK_TEXT
;
1438 info
.m_itemId
= index
;
1439 return InsertItem(info
);
1442 // Inserts an image item
1443 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1446 info
.m_image
= imageIndex
;
1447 info
.m_mask
= wxLIST_MASK_IMAGE
;
1448 info
.m_itemId
= index
;
1449 return InsertItem(info
);
1452 // Inserts an image/string item
1453 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1456 info
.m_image
= imageIndex
;
1457 info
.m_text
= label
;
1458 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1459 info
.m_itemId
= index
;
1460 return InsertItem(info
);
1463 // For list view mode (only), inserts a column.
1464 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1467 wxConvertToMSWListCol(col
, item
, lvCol
);
1469 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1471 // always give some width to the new column: this one is compatible
1472 // with the generic version
1473 lvCol
.mask
|= LVCF_WIDTH
;
1477 // when we insert a column which can contain an image, we must specify this
1478 // flag right now as doing it later in SetColumn() has no effect
1480 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1481 // way to dynamically set/clear the bitmap as the column without a bitmap
1482 // on the left looks ugly (there is a hole)
1484 // unfortunately with my version of comctl32.dll (5.80), the left column
1485 // image is always on the left and it seems that it's a "feature" - I
1486 // didn't find any way to work around it in any case
1487 if ( lvCol
.mask
& LVCF_IMAGE
)
1489 lvCol
.mask
|= LVCF_FMT
;
1490 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
;
1493 bool success
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
) != -1;
1500 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1507 long wxListCtrl::InsertColumn(long col
,
1508 const wxString
& heading
,
1513 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1514 item
.m_text
= heading
;
1517 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1518 item
.m_width
= width
;
1520 item
.m_format
= format
;
1522 return InsertColumn(col
, item
);
1525 // Scrolls the list control. If in icon, small icon or report view mode,
1526 // x specifies the number of pixels to scroll. If in list view mode, x
1527 // specifies the number of columns to scroll.
1528 // If in icon, small icon or list view mode, y specifies the number of pixels
1529 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1530 bool wxListCtrl::ScrollList(int dx
, int dy
)
1532 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1537 // fn is a function which takes 3 long arguments: item1, item2, data.
1538 // item1 is the long data associated with a first item (NOT the index).
1539 // item2 is the long data associated with a second item (NOT the index).
1540 // data is the same value as passed to SortItems.
1541 // The return value is a negative number if the first item should precede the second
1542 // item, a positive number of the second item should precede the first,
1543 // or zero if the two items are equivalent.
1545 // data is arbitrary data to be passed to the sort function.
1547 // Internal structures for proxying the user compare function
1548 // so that we can pass it the *real* user data
1550 // translate lParam data and call user func
1551 struct wxInternalDataSort
1553 wxListCtrlCompare user_fn
;
1557 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
1559 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
1561 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
1562 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
1564 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
1565 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
1567 return internalData
->user_fn(d1
, d2
, internalData
->data
);
1571 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1573 struct wxInternalDataSort internalData
;
1574 internalData
.user_fn
= fn
;
1575 internalData
.data
= data
;
1577 // WPARAM cast is needed for mingw/cygwin
1578 if ( !ListView_SortItems(GetHwnd(),
1579 wxInternalDataCompareFunc
,
1580 (WPARAM
) &internalData
) )
1582 wxLogDebug(_T("ListView_SortItems() failed"));
1592 // ----------------------------------------------------------------------------
1593 // message processing
1594 // ----------------------------------------------------------------------------
1596 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1598 if (cmd
== EN_UPDATE
)
1600 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1601 event
.SetEventObject( this );
1602 ProcessCommand(event
);
1605 else if (cmd
== EN_KILLFOCUS
)
1607 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1608 event
.SetEventObject( this );
1609 ProcessCommand(event
);
1616 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1618 // prepare the event
1619 // -----------------
1621 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1622 event
.SetEventObject(this);
1624 wxEventType eventType
= wxEVT_NULL
;
1626 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1628 // if your compiler is as broken as this, you should really change it: this
1629 // code is needed for normal operation! #ifdef below is only useful for
1630 // automatic rebuilds which are done with a very old compiler version
1631 #ifdef HDN_BEGINTRACKA
1633 // check for messages from the header (in report view)
1634 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1636 // is it a message from the header?
1637 if ( nmhdr
->hwndFrom
== hwndHdr
)
1639 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1641 event
.m_itemIndex
= -1;
1643 switch ( nmhdr
->code
)
1645 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1646 // TRACK messages even to ANSI programs: on my system I get
1647 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1649 // work around is to simply catch both versions and hope that it
1650 // works (why should this message exist in ANSI and Unicode is
1651 // beyond me as it doesn't deal with strings at all...)
1652 case HDN_BEGINTRACKA
:
1653 case HDN_BEGINTRACKW
:
1654 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1659 if ( eventType
== wxEVT_NULL
)
1660 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1665 if ( eventType
== wxEVT_NULL
)
1666 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1667 event
.m_col
= nmHDR
->iItem
;
1672 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1675 // find the column clicked: we have to search for it
1676 // ourselves as the notification message doesn't provide
1679 // where did the click occur?
1681 if ( !::GetCursorPos(&ptClick
) )
1683 wxLogLastError(_T("GetCursorPos"));
1686 if ( !::ScreenToClient(hwndHdr
, &ptClick
) )
1688 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1691 event
.m_pointDrag
.x
= ptClick
.x
;
1692 event
.m_pointDrag
.y
= ptClick
.y
;
1694 int colCount
= Header_GetItemCount(hwndHdr
);
1697 for ( int col
= 0; col
< colCount
; col
++ )
1699 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1701 if ( ::PtInRect(&rect
, ptClick
) )
1712 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1716 #endif // defined(HDN_BEGINTRACKA)
1717 if ( nmhdr
->hwndFrom
== GetHwnd() )
1719 // almost all messages use NM_LISTVIEW
1720 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1722 // this is true for almost all events
1723 event
.m_item
.m_data
= nmLV
->lParam
;
1725 switch ( nmhdr
->code
)
1727 case LVN_BEGINRDRAG
:
1728 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1732 if ( eventType
== wxEVT_NULL
)
1734 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1737 event
.m_itemIndex
= nmLV
->iItem
;
1738 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1739 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1742 // NB: we have to handle both *A and *W versions here because some
1743 // versions of comctl32.dll send ANSI message to an Unicode app
1744 case LVN_BEGINLABELEDITA
:
1746 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1747 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1748 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1749 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1752 case LVN_BEGINLABELEDITW
:
1754 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1755 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1756 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1757 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1761 case LVN_ENDLABELEDITA
:
1763 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1764 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1765 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1766 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1767 ((LV_ITEM
)item
).iItem
== -1 )
1770 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1773 case LVN_ENDLABELEDITW
:
1775 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1776 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1777 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1778 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1779 ((LV_ITEM
)item
).iItem
== -1 )
1782 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1786 case LVN_COLUMNCLICK
:
1787 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1788 event
.m_itemIndex
= -1;
1789 event
.m_col
= nmLV
->iSubItem
;
1792 case LVN_DELETEALLITEMS
:
1793 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1794 event
.m_itemIndex
= -1;
1797 case LVN_DELETEITEM
:
1798 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1799 event
.m_itemIndex
= nmLV
->iItem
;
1800 // delete the assoicated internal data
1801 wxDeleteInternalData(this, nmLV
->iItem
);
1804 case LVN_SETDISPINFO
:
1806 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1807 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1808 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
1812 case LVN_INSERTITEM
:
1813 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1814 event
.m_itemIndex
= nmLV
->iItem
;
1817 case LVN_ITEMCHANGED
:
1818 // we translate this catch all message into more interesting
1819 // (and more easy to process) wxWindows events
1821 // first of all, we deal with the state change events only
1822 if ( nmLV
->uChanged
& LVIF_STATE
)
1824 // temp vars for readability
1825 const UINT stOld
= nmLV
->uOldState
;
1826 const UINT stNew
= nmLV
->uNewState
;
1828 // has the focus changed?
1829 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
1831 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
1832 event
.m_itemIndex
= nmLV
->iItem
;
1835 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
1837 if ( eventType
!= wxEVT_NULL
)
1839 // focus and selection have both changed: send the
1840 // focus event from here and the selection one
1842 event
.SetEventType(eventType
);
1843 (void)GetEventHandler()->ProcessEvent(event
);
1845 else // no focus event to send
1847 // then need to set m_itemIndex as it wasn't done
1849 event
.m_itemIndex
= nmLV
->iItem
;
1852 eventType
= stNew
& LVIS_SELECTED
1853 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1854 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1858 if ( eventType
== wxEVT_NULL
)
1860 // not an interesting event for us
1868 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1869 WORD wVKey
= info
->wVKey
;
1871 // get the current selection
1872 long lItem
= GetNextItem(-1,
1874 wxLIST_STATE_SELECTED
);
1876 // <Enter> or <Space> activate the selected item if any (but
1877 // not with Shift and/or Ctrl as then they have a predefined
1878 // meaning for the list view)
1880 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
1881 !(wxIsShiftDown() || wxIsCtrlDown()) )
1883 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1887 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1889 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1890 // value which should be used as is
1891 int code
= wxCharCodeMSWToWX(wVKey
);
1892 event
.m_code
= code
? code
: wVKey
;
1896 event
.m_item
.m_itemId
= lItem
;
1900 // fill the other fields too
1901 event
.m_item
.m_text
= GetItemText(lItem
);
1902 event
.m_item
.m_data
= GetItemData(lItem
);
1908 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1910 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1915 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1916 // if it happened on an item (and not on empty place)
1917 if ( nmLV
->iItem
== -1 )
1923 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1924 event
.m_itemIndex
= nmLV
->iItem
;
1925 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1926 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1930 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1931 // don't do anything else
1932 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1937 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1938 LV_HITTESTINFO lvhti
;
1939 wxZeroMemory(lvhti
);
1941 ::GetCursorPos(&(lvhti
.pt
));
1942 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1943 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1945 if ( lvhti
.flags
& LVHT_ONITEM
)
1947 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1948 event
.m_itemIndex
= lvhti
.iItem
;
1949 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
1950 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
1955 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
1956 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
1958 *result
= OnCustomDraw(lParam
);
1961 #endif // _WIN32_IE >= 0x300
1963 case LVN_ODCACHEHINT
:
1965 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
1967 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
1969 // we get some really stupid cache hints like ones for items in
1970 // range 0..0 for an empty control or, after deleting an item,
1971 // for items in invalid range - filter this garbage out
1972 if ( cacheHint
->iFrom
< cacheHint
->iTo
)
1974 event
.m_oldItemIndex
= cacheHint
->iFrom
;
1976 long iMax
= GetItemCount();
1977 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
1987 case LVN_GETDISPINFO
:
1990 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1992 LV_ITEM
& lvi
= info
->item
;
1993 long item
= lvi
.iItem
;
1995 if ( lvi
.mask
& LVIF_TEXT
)
1997 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
1998 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
2001 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2002 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2003 if ( lvi
.mask
& LVIF_IMAGE
)
2005 lvi
.iImage
= OnGetItemImage(item
);
2009 // a little dose of healthy paranoia: as we never use
2010 // LVM_SETCALLBACKMASK we're not supposed to get these ones
2011 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
2012 _T("we don't support state callbacks yet!") );
2019 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
2024 // where did this one come from?
2028 // process the event
2029 // -----------------
2031 event
.SetEventType(eventType
);
2033 if ( !GetEventHandler()->ProcessEvent(event
) )
2039 switch ( nmhdr
->code
)
2041 case LVN_DELETEALLITEMS
:
2042 // always return TRUE to suppress all additional LVN_DELETEITEM
2043 // notifications - this makes deleting all items from a list ctrl
2049 case LVN_ENDLABELEDITA
:
2050 case LVN_ENDLABELEDITW
:
2051 // logic here is inversed compared to all the other messages
2052 *result
= event
.IsAllowed();
2057 *result
= !event
.IsAllowed();
2062 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
2064 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
2066 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
2067 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
2068 switch ( nmcd
.dwDrawStage
)
2071 // if we've got any items with non standard attributes,
2072 // notify us before painting each item
2074 // for virtual controls, always suppose that we have attributes as
2075 // there is no way to check for this
2076 return IsVirtual() || m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
2079 case CDDS_ITEMPREPAINT
:
2081 size_t item
= (size_t)nmcd
.dwItemSpec
;
2082 if ( item
>= (size_t)GetItemCount() )
2084 // we get this message with item == 0 for an empty control,
2085 // we must ignore it as calling OnGetItemAttr() would be
2087 return CDRF_DODEFAULT
;
2090 wxListItemAttr
*attr
=
2091 IsVirtual() ? OnGetItemAttr(item
)
2092 : wxGetInternalDataAttr(this, item
);
2096 // nothing to do for this item
2097 return CDRF_DODEFAULT
;
2101 wxColour colText
, colBack
;
2102 if ( attr
->HasFont() )
2104 wxFont font
= attr
->GetFont();
2105 hFont
= (HFONT
)font
.GetResourceHandle();
2112 if ( attr
->HasTextColour() )
2114 colText
= attr
->GetTextColour();
2118 colText
= GetTextColour();
2121 if ( attr
->HasBackgroundColour() )
2123 colBack
= attr
->GetBackgroundColour();
2127 colBack
= GetBackgroundColour();
2130 lplvcd
->clrText
= wxColourToRGB(colText
);
2131 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
2133 // note that if we wanted to set colours for
2134 // individual columns (subitems), we would have
2135 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2138 ::SelectObject(nmcd
.hdc
, hFont
);
2140 return CDRF_NEWFONT
;
2143 // fall through to return CDRF_DODEFAULT
2146 return CDRF_DODEFAULT
;
2150 #endif // NM_CUSTOMDRAW supported
2152 // Necessary for drawing hrules and vrules, if specified
2153 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2157 wxControl::OnPaint(event
);
2159 // Reset the device origin since it may have been set
2160 dc
.SetDeviceOrigin(0, 0);
2162 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
2163 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
2165 if (!drawHRules
&& !drawVRules
)
2167 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
2170 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2172 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2174 wxSize clientSize
= GetClientSize();
2178 int itemCount
= GetItemCount();
2182 long top
= GetTopItem();
2183 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2185 if (GetItemRect(i
, itemRect
))
2187 cy
= itemRect
.GetTop();
2188 if (i
!= 0) // Don't draw the first one
2190 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2193 if (i
== itemCount
- 1)
2195 cy
= itemRect
.GetBottom();
2196 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2202 if (drawVRules
&& (i
> -1))
2204 wxRect firstItemRect
;
2205 GetItemRect(0, firstItemRect
);
2207 if (GetItemRect(i
, itemRect
))
2210 int x
= itemRect
.GetX();
2211 for (col
= 0; col
< GetColumnCount(); col
++)
2213 int colWidth
= GetColumnWidth(col
);
2215 dc
.DrawLine(x
-1, firstItemRect
.GetY() - 2, x
-1, itemRect
.GetBottom());
2221 // ----------------------------------------------------------------------------
2222 // virtual list controls
2223 // ----------------------------------------------------------------------------
2225 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2227 // this is a pure virtual function, in fact - which is not really pure
2228 // because the controls which are not virtual don't need to implement it
2229 wxFAIL_MSG( _T("not supposed to be called") );
2231 return wxEmptyString
;
2234 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2237 wxFAIL_MSG( _T("not supposed to be called") );
2242 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2244 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2245 _T("invalid item index in OnGetItemAttr()") );
2247 // no attributes by default
2251 void wxListCtrl::SetItemCount(long count
)
2253 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2255 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
, 0) )
2257 wxLogLastError(_T("ListView_SetItemCount"));
2261 void wxListCtrl::RefreshItem(long item
)
2263 // strangely enough, ListView_Update() results in much more flicker here
2264 // than a dumb Refresh() -- why?
2266 if ( !ListView_Update(GetHwnd(), item
) )
2268 wxLogLastError(_T("ListView_Update"));
2272 GetItemRect(item
, rect
);
2277 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2279 wxRect rect1
, rect2
;
2280 GetItemRect(itemFrom
, rect1
);
2281 GetItemRect(itemTo
, rect2
);
2283 wxRect rect
= rect1
;
2284 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2289 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
2292 it
.mask
= LVIF_PARAM
;
2295 bool success
= ListView_GetItem(hwnd
, &it
) != 0;
2297 return (wxListItemInternalData
*) it
.lParam
;
2302 static wxListItemInternalData
*wxGetInternalData(wxListCtrl
*ctl
, long itemId
)
2304 return wxGetInternalData((HWND
) ctl
->GetHWND(), itemId
);
2307 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
2309 wxListItemInternalData
*data
= wxGetInternalData(ctl
, itemId
);
2316 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
2318 wxListItemInternalData
*data
= wxGetInternalData(ctl
, itemId
);
2323 memset(&item
, 0, sizeof(item
));
2324 item
.iItem
= itemId
;
2325 item
.mask
= LVIF_PARAM
;
2326 item
.lParam
= (LPARAM
) 0;
2327 ListView_SetItem((HWND
)ctl
->GetHWND(), &item
);
2331 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2335 wxListItemInternalData
*internaldata
=
2336 (wxListItemInternalData
*) lvItem
.lParam
;
2339 info
.m_data
= internaldata
->lParam
;
2343 info
.m_stateMask
= 0;
2344 info
.m_itemId
= lvItem
.iItem
;
2346 long oldMask
= lvItem
.mask
;
2348 bool needText
= FALSE
;
2349 if (hwndListCtrl
!= 0)
2351 if ( lvItem
.mask
& LVIF_TEXT
)
2358 lvItem
.pszText
= new wxChar
[513];
2359 lvItem
.cchTextMax
= 512;
2361 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2362 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2365 if ( lvItem
.mask
& LVIF_STATE
)
2367 info
.m_mask
|= wxLIST_MASK_STATE
;
2369 if ( lvItem
.stateMask
& LVIS_CUT
)
2371 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2372 if ( lvItem
.state
& LVIS_CUT
)
2373 info
.m_state
|= wxLIST_STATE_CUT
;
2375 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2377 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2378 if ( lvItem
.state
& LVIS_DROPHILITED
)
2379 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2381 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2383 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2384 if ( lvItem
.state
& LVIS_FOCUSED
)
2385 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2387 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2389 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2390 if ( lvItem
.state
& LVIS_SELECTED
)
2391 info
.m_state
|= wxLIST_STATE_SELECTED
;
2395 if ( lvItem
.mask
& LVIF_TEXT
)
2397 info
.m_mask
|= wxLIST_MASK_TEXT
;
2398 info
.m_text
= lvItem
.pszText
;
2400 if ( lvItem
.mask
& LVIF_IMAGE
)
2402 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2403 info
.m_image
= lvItem
.iImage
;
2405 if ( lvItem
.mask
& LVIF_PARAM
)
2406 info
.m_mask
|= wxLIST_MASK_DATA
;
2407 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2408 info
.m_mask
|= wxLIST_SET_ITEM
;
2409 info
.m_col
= lvItem
.iSubItem
;
2414 delete[] lvItem
.pszText
;
2416 lvItem
.mask
= oldMask
;
2419 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2421 if (stateMask
& wxLIST_STATE_CUT
)
2423 lvItem
.stateMask
|= LVIS_CUT
;
2424 if (state
& wxLIST_STATE_CUT
)
2425 lvItem
.state
|= LVIS_CUT
;
2427 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2429 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2430 if (state
& wxLIST_STATE_DROPHILITED
)
2431 lvItem
.state
|= LVIS_DROPHILITED
;
2433 if (stateMask
& wxLIST_STATE_FOCUSED
)
2435 lvItem
.stateMask
|= LVIS_FOCUSED
;
2436 if (state
& wxLIST_STATE_FOCUSED
)
2437 lvItem
.state
|= LVIS_FOCUSED
;
2439 if (stateMask
& wxLIST_STATE_SELECTED
)
2441 lvItem
.stateMask
|= LVIS_SELECTED
;
2442 if (state
& wxLIST_STATE_SELECTED
)
2443 lvItem
.state
|= LVIS_SELECTED
;
2447 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2448 const wxListItem
& info
,
2451 lvItem
.iItem
= (int) info
.m_itemId
;
2453 lvItem
.iImage
= info
.m_image
;
2454 lvItem
.stateMask
= 0;
2457 lvItem
.iSubItem
= info
.m_col
;
2459 if (info
.m_mask
& wxLIST_MASK_STATE
)
2461 lvItem
.mask
|= LVIF_STATE
;
2463 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2466 if (info
.m_mask
& wxLIST_MASK_TEXT
)
2468 lvItem
.mask
|= LVIF_TEXT
;
2469 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
2471 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
2475 // pszText is not const, hence the cast
2476 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
2477 if ( lvItem
.pszText
)
2478 lvItem
.cchTextMax
= info
.m_text
.Length();
2480 lvItem
.cchTextMax
= 0;
2483 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
2484 lvItem
.mask
|= LVIF_IMAGE
;
2487 static void wxConvertToMSWListCol(int WXUNUSED(col
), const wxListItem
& item
,
2490 wxZeroMemory(lvCol
);
2492 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
2494 lvCol
.mask
|= LVCF_TEXT
;
2495 lvCol
.pszText
= (wxChar
*)item
.m_text
.c_str(); // cast is safe
2498 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
2500 lvCol
.mask
|= LVCF_FMT
;
2502 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
2503 lvCol
.fmt
= LVCFMT_LEFT
;
2504 else if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
2505 lvCol
.fmt
= LVCFMT_RIGHT
;
2506 else if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
2507 lvCol
.fmt
= LVCFMT_CENTER
;
2510 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
2512 lvCol
.mask
|= LVCF_WIDTH
;
2513 if ( item
.m_width
== wxLIST_AUTOSIZE
)
2514 lvCol
.cx
= LVSCW_AUTOSIZE
;
2515 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2516 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
2518 lvCol
.cx
= item
.m_width
;
2521 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2522 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2523 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
2525 if ( wxTheApp
->GetComCtl32Version() >= 470 )
2527 lvCol
.mask
|= LVCF_IMAGE
;
2528 lvCol
.iImage
= item
.m_image
;
2530 //else: it doesn't support item images anyhow
2535 #endif // wxUSE_LISTCTRL