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();
107 #else // !wxUSE_UNICODE
108 wxLV_ITEM(LV_ITEMW
&item
)
110 m_item
= new LV_ITEM((LV_ITEM
&)item
);
112 // the code below doesn't compile without wxUSE_WCHAR_T and as I don't
113 // know if it's useful to have it at all (do we ever get Unicode
114 // notifications in ANSI mode? I don't think so...) I'm not going to
115 // write alternative implementation right now
117 // but if it is indeed used, we should simply directly use
118 // ::WideCharToMultiByte() here
120 if ( (item
.mask
& LVIF_TEXT
) && item
.pszText
)
124 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX((const __wchar_t
* ) item
.pszText
));
126 m_buf
= new wxWC2WXbuf(wxConvLocal
.cWC2WX(item
.pszText
));
128 m_item
->pszText
= (wxChar
*)m_buf
->data();
131 #endif // wxUSE_WCHAR_T
134 wxLV_ITEM(LV_ITEMA
&item
) : m_buf(NULL
), m_item(&item
) {}
137 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
141 DECLARE_NO_COPY_CLASS(wxLV_ITEM
)
144 ///////////////////////////////////////////////////////
146 // The MSW version had problems with SetTextColour() et
147 // al as the wxListItemAttr's were stored keyed on the
148 // item index. If a item was inserted anywhere but the end
149 // of the list the the text attributes (colour etc) for
150 // the following items were out of sync.
153 // Under MSW the only way to associate data with a List
154 // item independant of its position in the list is to
155 // store a pointer to it in its lParam attribute. However
156 // user programs are already using this (via the
157 // SetItemData() GetItemData() calls).
159 // However what we can do is store a pointer to a
160 // structure which contains the attributes we want *and*
161 // a lParam for the users data, e.g.
163 // class wxListItemInternalData
166 // wxListItemAttr *attr;
167 // long lParam; // user data
170 // To conserve memory, a wxListItemInternalData is
171 // only allocated for a LV_ITEM if text attributes or
172 // user data(lparam) are being set.
175 // class wxListItemInternalData
176 class wxListItemInternalData
179 wxListItemAttr
*attr
;
180 LPARAM lParam
; // user data
182 wxListItemInternalData() : attr(NULL
), lParam(0) {}
183 ~wxListItemInternalData()
189 DECLARE_NO_COPY_CLASS(wxListItemInternalData
)
192 // Get the internal data structure
193 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
);
194 static wxListItemInternalData
*wxGetInternalData(wxListCtrl
*ctl
, long itemId
);
195 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
);
196 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
);
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
204 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
205 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
206 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
207 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
208 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
209 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
210 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
211 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
212 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
213 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
214 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
215 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
216 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
217 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
218 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
219 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
220 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
221 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
222 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
223 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
224 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
226 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
227 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
228 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
230 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
232 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
233 EVT_PAINT(wxListCtrl::OnPaint
)
236 // ============================================================================
238 // ============================================================================
240 // ----------------------------------------------------------------------------
241 // wxListCtrl construction
242 // ----------------------------------------------------------------------------
244 void wxListCtrl::Init()
246 m_imageListNormal
= NULL
;
247 m_imageListSmall
= NULL
;
248 m_imageListState
= NULL
;
249 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
253 m_AnyInternalData
= FALSE
;
254 m_hasAnyAttr
= FALSE
;
257 bool wxListCtrl::Create(wxWindow
*parent
,
262 const wxValidator
& validator
,
263 const wxString
& name
)
266 SetValidator(validator
);
267 #endif // wxUSE_VALIDATORS
276 m_windowStyle
= style
;
289 m_windowId
= (id
== -1) ? NewControlId() : id
;
291 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
292 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
294 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
295 wstyle
|= WS_CLIPSIBLINGS
;
297 if ( wxStyleHasBorder(m_windowStyle
) )
299 m_baseStyle
= wstyle
;
301 if ( !DoCreateControl(x
, y
, width
, height
) )
305 parent
->AddChild(this);
310 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
312 DWORD wstyle
= m_baseStyle
;
315 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
317 // Even with extended styles, need to combine with WS_BORDER
318 // for them to look right.
322 long oldStyle
= 0; // Dummy
323 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
325 // Create the ListView control.
326 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
331 GetWinHwnd(GetParent()),
338 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
343 // for comctl32.dll v 4.70+ we want to have this attribute because it's
344 // prettier (and also because wxGTK does it like this)
345 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
347 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
348 0, LVS_EX_FULLROWSELECT
);
351 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
352 SetForegroundColour(GetParent()->GetForegroundColour());
359 void wxListCtrl::UpdateStyle()
363 // The new window view style
365 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
366 dwStyleNew
|= m_baseStyle
;
368 // Get the current window style.
369 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
371 // Only set the window style if the view bits have changed.
372 if ( dwStyleOld
!= dwStyleNew
)
374 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
379 void wxListCtrl::FreeAllInternalData()
381 if (m_AnyInternalData
)
383 int n
= GetItemCount();
386 for (i
= 0; i
< n
; i
++)
387 wxDeleteInternalData(this, i
);
389 m_AnyInternalData
= FALSE
;
393 wxListCtrl::~wxListCtrl()
395 FreeAllInternalData();
399 m_textCtrl
->SetHWND(0);
400 m_textCtrl
->UnsubclassWin();
405 if (m_ownsImageListNormal
) delete m_imageListNormal
;
406 if (m_ownsImageListSmall
) delete m_imageListSmall
;
407 if (m_ownsImageListState
) delete m_imageListState
;
410 // ----------------------------------------------------------------------------
411 // set/get/change style
412 // ----------------------------------------------------------------------------
414 // Add or remove a single window style
415 void wxListCtrl::SetSingleStyle(long style
, bool add
)
417 long flag
= GetWindowStyleFlag();
419 // Get rid of conflicting styles
422 if ( style
& wxLC_MASK_TYPE
)
423 flag
= flag
& ~wxLC_MASK_TYPE
;
424 if ( style
& wxLC_MASK_ALIGN
)
425 flag
= flag
& ~wxLC_MASK_ALIGN
;
426 if ( style
& wxLC_MASK_SORT
)
427 flag
= flag
& ~wxLC_MASK_SORT
;
443 m_windowStyle
= flag
;
448 // Set the whole window style
449 void wxListCtrl::SetWindowStyleFlag(long flag
)
451 m_windowStyle
= flag
;
456 // Can be just a single style, or a bitlist
457 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
460 if ( style
& wxLC_ICON
)
462 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
463 oldStyle
-= LVS_SMALLICON
;
464 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
465 oldStyle
-= LVS_REPORT
;
466 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
467 oldStyle
-= LVS_LIST
;
471 if ( style
& wxLC_SMALL_ICON
)
473 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
474 oldStyle
-= LVS_ICON
;
475 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
476 oldStyle
-= LVS_REPORT
;
477 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
478 oldStyle
-= LVS_LIST
;
479 wstyle
|= LVS_SMALLICON
;
482 if ( style
& wxLC_LIST
)
484 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
485 oldStyle
-= LVS_ICON
;
486 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
487 oldStyle
-= LVS_REPORT
;
488 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
489 oldStyle
-= LVS_SMALLICON
;
493 if ( style
& wxLC_REPORT
)
495 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
496 oldStyle
-= LVS_ICON
;
497 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
498 oldStyle
-= LVS_LIST
;
499 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
500 oldStyle
-= LVS_SMALLICON
;
502 wstyle
|= LVS_REPORT
;
505 if ( style
& wxLC_ALIGN_LEFT
)
507 if ( oldStyle
& LVS_ALIGNTOP
)
508 oldStyle
-= LVS_ALIGNTOP
;
509 wstyle
|= LVS_ALIGNLEFT
;
512 if ( style
& wxLC_ALIGN_TOP
)
514 if ( oldStyle
& LVS_ALIGNLEFT
)
515 oldStyle
-= LVS_ALIGNLEFT
;
516 wstyle
|= LVS_ALIGNTOP
;
519 if ( style
& wxLC_AUTOARRANGE
)
520 wstyle
|= LVS_AUTOARRANGE
;
522 if ( style
& wxLC_NO_SORT_HEADER
)
523 wstyle
|= LVS_NOSORTHEADER
;
525 if ( style
& wxLC_NO_HEADER
)
526 wstyle
|= LVS_NOCOLUMNHEADER
;
528 if ( style
& wxLC_EDIT_LABELS
)
529 wstyle
|= LVS_EDITLABELS
;
531 if ( style
& wxLC_SINGLE_SEL
)
532 wstyle
|= LVS_SINGLESEL
;
534 if ( style
& wxLC_SORT_ASCENDING
)
536 if ( oldStyle
& LVS_SORTDESCENDING
)
537 oldStyle
-= LVS_SORTDESCENDING
;
538 wstyle
|= LVS_SORTASCENDING
;
541 if ( style
& wxLC_SORT_DESCENDING
)
543 if ( oldStyle
& LVS_SORTASCENDING
)
544 oldStyle
-= LVS_SORTASCENDING
;
545 wstyle
|= LVS_SORTDESCENDING
;
548 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
549 if ( style
& wxLC_VIRTUAL
)
551 int ver
= wxTheApp
->GetComCtl32Version();
554 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."),
555 ver
/ 100, ver
% 100);
558 wstyle
|= LVS_OWNERDATA
;
565 // ----------------------------------------------------------------------------
567 // ----------------------------------------------------------------------------
569 // Sets the foreground, i.e. text, colour
570 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
572 if ( !wxWindow::SetForegroundColour(col
) )
575 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
580 // Sets the background colour
581 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
583 if ( !wxWindow::SetBackgroundColour(col
) )
586 // we set the same colour for both the "empty" background and the items
588 COLORREF color
= wxColourToRGB(col
);
589 ListView_SetBkColor(GetHwnd(), color
);
590 ListView_SetTextBkColor(GetHwnd(), color
);
595 // Gets information about this column
596 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
601 lvCol
.mask
= LVCF_WIDTH
;
603 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
605 lvCol
.mask
|= LVCF_TEXT
;
606 lvCol
.pszText
= new wxChar
[513];
607 lvCol
.cchTextMax
= 512;
610 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
612 lvCol
.mask
|= LVCF_FMT
;
615 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
617 lvCol
.mask
|= LVCF_IMAGE
;
620 bool success
= ListView_GetColumn(GetHwnd(), col
, &lvCol
) != 0;
622 // item.m_subItem = lvCol.iSubItem;
623 item
.m_width
= lvCol
.cx
;
625 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
627 item
.m_text
= lvCol
.pszText
;
628 delete[] lvCol
.pszText
;
631 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
633 switch (lvCol
.fmt
& LVCFMT_JUSTIFYMASK
) {
635 item
.m_format
= wxLIST_FORMAT_LEFT
;
638 item
.m_format
= wxLIST_FORMAT_RIGHT
;
641 item
.m_format
= wxLIST_FORMAT_CENTRE
;
644 item
.m_format
= -1; // Unknown?
649 #if _WIN32_IE >= 0x0300
650 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
652 item
.m_image
= lvCol
.iImage
;
659 // Sets information about this column
660 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
663 wxConvertToMSWListCol(col
, item
, lvCol
);
665 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
668 // Gets the column width
669 int wxListCtrl::GetColumnWidth(int col
) const
671 return ListView_GetColumnWidth(GetHwnd(), col
);
674 // Sets the column width
675 bool wxListCtrl::SetColumnWidth(int col
, int width
)
678 if ( m_windowStyle
& wxLC_LIST
)
682 if ( width2
== wxLIST_AUTOSIZE
)
683 width2
= LVSCW_AUTOSIZE
;
684 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
685 width2
= LVSCW_AUTOSIZE_USEHEADER
;
687 return ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0;
690 // Gets the number of items that can fit vertically in the
691 // visible area of the list control (list or report view)
692 // or the total number of items in the list control (icon
693 // or small icon view)
694 int wxListCtrl::GetCountPerPage() const
696 return ListView_GetCountPerPage(GetHwnd());
699 // Gets the edit control for editing labels.
700 wxTextCtrl
* wxListCtrl::GetEditControl() const
705 // Gets information about the item
706 bool wxListCtrl::GetItem(wxListItem
& info
) const
709 wxZeroMemory(lvItem
);
711 lvItem
.iItem
= info
.m_itemId
;
712 lvItem
.iSubItem
= info
.m_col
;
714 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
716 lvItem
.mask
|= LVIF_TEXT
;
717 lvItem
.pszText
= new wxChar
[513];
718 lvItem
.cchTextMax
= 512;
722 lvItem
.pszText
= NULL
;
725 if (info
.m_mask
& wxLIST_MASK_DATA
)
726 lvItem
.mask
|= LVIF_PARAM
;
728 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
729 lvItem
.mask
|= LVIF_IMAGE
;
731 if ( info
.m_mask
& wxLIST_MASK_STATE
)
733 lvItem
.mask
|= LVIF_STATE
;
734 // the other bits are hardly interesting anyhow
735 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
738 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
741 wxLogError(_("Couldn't retrieve information about list control item %d."),
746 // give NULL as hwnd as we already have everything we need
747 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
751 delete[] lvItem
.pszText
;
756 // Sets information about the item
757 bool wxListCtrl::SetItem(wxListItem
& info
)
760 wxConvertToMSWListItem(this, info
, item
);
762 // we never update the lParam if it contains our pointer
763 // to the wxListItemInternalData structure
764 item
.mask
&= ~LVIF_PARAM
;
766 // check if setting attributes or lParam
767 if (info
.HasAttributes() || (info
.m_mask
& wxLIST_MASK_DATA
))
769 // get internal item data
770 // perhaps a cache here ?
771 wxListItemInternalData
*data
= wxGetInternalData(this, info
.m_itemId
);
776 m_AnyInternalData
= TRUE
;
777 data
= new wxListItemInternalData();
778 item
.lParam
= (LPARAM
) data
;
779 item
.mask
|= LVIF_PARAM
;
784 if (info
.m_mask
& wxLIST_MASK_DATA
)
785 data
->lParam
= info
.m_data
;
788 if (info
.HasAttributes())
791 *data
->attr
= *info
.GetAttributes();
793 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
798 // we could be changing only the attribute in which case we don't need to
799 // call ListView_SetItem() at all
803 if ( !ListView_SetItem(GetHwnd(), &item
) )
805 wxLogDebug(_T("ListView_SetItem() failed"));
811 // we need to update the item immediately to show the new image
812 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
814 // check whether it has any custom attributes
815 if ( info
.HasAttributes() )
819 // if the colour has changed, we must redraw the item
825 // we need this to make the change visible right now
826 RefreshItem(item
.iItem
);
832 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
836 info
.m_mask
= wxLIST_MASK_TEXT
;
837 info
.m_itemId
= index
;
841 info
.m_image
= imageId
;
842 info
.m_mask
|= wxLIST_MASK_IMAGE
;
844 return SetItem(info
);
848 // Gets the item state
849 int wxListCtrl::GetItemState(long item
, long stateMask
) const
853 info
.m_mask
= wxLIST_MASK_STATE
;
854 info
.m_stateMask
= stateMask
;
855 info
.m_itemId
= item
;
863 // Sets the item state
864 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
866 // NB: don't use SetItem() here as it doesn't work with the virtual list
869 wxZeroMemory(lvItem
);
871 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
873 // for the virtual list controls we need to refresh the previously focused
874 // item manually when changing focus without changing selection
875 // programmatically because otherwise it keeps its focus rectangle until
876 // next repaint (yet another comctl32 bug)
879 (stateMask
& wxLIST_STATE_FOCUSED
) &&
880 (state
& wxLIST_STATE_FOCUSED
) )
882 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
889 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
890 (WPARAM
)item
, (LPARAM
)&lvItem
) )
892 wxLogLastError(_T("ListView_SetItemState"));
897 if ( focusOld
!= -1 )
899 // no need to refresh the item if it was previously selected, it would
900 // only result in annoying flicker
901 if ( !(GetItemState(focusOld
,
902 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
904 RefreshItem(focusOld
);
911 // Sets the item image
912 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
916 info
.m_mask
= wxLIST_MASK_IMAGE
;
917 info
.m_image
= image
;
918 info
.m_itemId
= item
;
920 return SetItem(info
);
923 // Gets the item text
924 wxString
wxListCtrl::GetItemText(long item
) const
928 info
.m_mask
= wxLIST_MASK_TEXT
;
929 info
.m_itemId
= item
;
932 return wxEmptyString
;
936 // Sets the item text
937 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
941 info
.m_mask
= wxLIST_MASK_TEXT
;
942 info
.m_itemId
= item
;
948 // Gets the item data
949 long wxListCtrl::GetItemData(long item
) const
953 info
.m_mask
= wxLIST_MASK_DATA
;
954 info
.m_itemId
= item
;
961 // Sets the item data
962 bool wxListCtrl::SetItemData(long item
, long data
)
966 info
.m_mask
= wxLIST_MASK_DATA
;
967 info
.m_itemId
= item
;
970 return SetItem(info
);
973 // Gets the item rectangle
974 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
979 if ( code
== wxLIST_RECT_BOUNDS
)
980 codeWin
= LVIR_BOUNDS
;
981 else if ( code
== wxLIST_RECT_ICON
)
983 else if ( code
== wxLIST_RECT_LABEL
)
984 codeWin
= LVIR_LABEL
;
987 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
989 codeWin
= LVIR_BOUNDS
;
992 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
994 rect
.x
= rectWin
.left
;
995 rect
.y
= rectWin
.top
;
996 rect
.width
= rectWin
.right
- rectWin
.left
;
997 rect
.height
= rectWin
.bottom
- rectWin
.top
;
1002 // Gets the item position
1003 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1007 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
1009 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
1013 // Sets the item position.
1014 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1016 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
1019 // Gets the number of items in the list control
1020 int wxListCtrl::GetItemCount() const
1022 return ListView_GetItemCount(GetHwnd());
1025 // Retrieves the spacing between icons in pixels.
1026 // If small is TRUE, gets the spacing for the small icon
1027 // view, otherwise the large icon view.
1028 int wxListCtrl::GetItemSpacing(bool isSmall
) const
1030 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
1033 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1036 info
.m_itemId
= item
;
1037 info
.SetTextColour( col
);
1041 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1044 info
.m_itemId
= item
;
1046 return info
.GetTextColour();
1049 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1052 info
.m_itemId
= item
;
1053 info
.SetBackgroundColour( col
);
1057 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1060 info
.m_itemId
= item
;
1062 return info
.GetBackgroundColour();
1065 // Gets the number of selected items in the list control
1066 int wxListCtrl::GetSelectedItemCount() const
1068 return ListView_GetSelectedCount(GetHwnd());
1071 // Gets the text colour of the listview
1072 wxColour
wxListCtrl::GetTextColour() const
1074 COLORREF ref
= ListView_GetTextColor(GetHwnd());
1075 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
1079 // Sets the text colour of the listview
1080 void wxListCtrl::SetTextColour(const wxColour
& col
)
1082 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
1085 // Gets the index of the topmost visible item when in
1086 // list or report view
1087 long wxListCtrl::GetTopItem() const
1089 return (long) ListView_GetTopIndex(GetHwnd());
1092 // Searches for an item, starting from 'item'.
1093 // 'geometry' is one of
1094 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1095 // 'state' is a state bit flag, one or more of
1096 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1097 // item can be -1 to find the first item that matches the
1099 // Returns the item or -1 if unsuccessful.
1100 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1104 if ( geom
== wxLIST_NEXT_ABOVE
)
1105 flags
|= LVNI_ABOVE
;
1106 if ( geom
== wxLIST_NEXT_ALL
)
1108 if ( geom
== wxLIST_NEXT_BELOW
)
1109 flags
|= LVNI_BELOW
;
1110 if ( geom
== wxLIST_NEXT_LEFT
)
1111 flags
|= LVNI_TOLEFT
;
1112 if ( geom
== wxLIST_NEXT_RIGHT
)
1113 flags
|= LVNI_TORIGHT
;
1115 if ( state
& wxLIST_STATE_CUT
)
1117 if ( state
& wxLIST_STATE_DROPHILITED
)
1118 flags
|= LVNI_DROPHILITED
;
1119 if ( state
& wxLIST_STATE_FOCUSED
)
1120 flags
|= LVNI_FOCUSED
;
1121 if ( state
& wxLIST_STATE_SELECTED
)
1122 flags
|= LVNI_SELECTED
;
1124 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1128 wxImageList
*wxListCtrl::GetImageList(int which
) const
1130 if ( which
== wxIMAGE_LIST_NORMAL
)
1132 return m_imageListNormal
;
1134 else if ( which
== wxIMAGE_LIST_SMALL
)
1136 return m_imageListSmall
;
1138 else if ( which
== wxIMAGE_LIST_STATE
)
1140 return m_imageListState
;
1145 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1148 if ( which
== wxIMAGE_LIST_NORMAL
)
1150 flags
= LVSIL_NORMAL
;
1151 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1152 m_imageListNormal
= imageList
;
1153 m_ownsImageListNormal
= FALSE
;
1155 else if ( which
== wxIMAGE_LIST_SMALL
)
1157 flags
= LVSIL_SMALL
;
1158 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1159 m_imageListSmall
= imageList
;
1160 m_ownsImageListSmall
= FALSE
;
1162 else if ( which
== wxIMAGE_LIST_STATE
)
1164 flags
= LVSIL_STATE
;
1165 if (m_ownsImageListState
) delete m_imageListState
;
1166 m_imageListState
= imageList
;
1167 m_ownsImageListState
= FALSE
;
1169 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1172 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1174 SetImageList(imageList
, which
);
1175 if ( which
== wxIMAGE_LIST_NORMAL
)
1176 m_ownsImageListNormal
= TRUE
;
1177 else if ( which
== wxIMAGE_LIST_SMALL
)
1178 m_ownsImageListSmall
= TRUE
;
1179 else if ( which
== wxIMAGE_LIST_STATE
)
1180 m_ownsImageListState
= TRUE
;
1183 // ----------------------------------------------------------------------------
1185 // ----------------------------------------------------------------------------
1187 // Arranges the items
1188 bool wxListCtrl::Arrange(int flag
)
1191 if ( flag
== wxLIST_ALIGN_LEFT
)
1192 code
= LVA_ALIGNLEFT
;
1193 else if ( flag
== wxLIST_ALIGN_TOP
)
1194 code
= LVA_ALIGNTOP
;
1195 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1197 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1198 code
= LVA_SNAPTOGRID
;
1200 return (ListView_Arrange(GetHwnd(), code
) != 0);
1204 bool wxListCtrl::DeleteItem(long item
)
1206 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1208 wxLogLastError(_T("ListView_DeleteItem"));
1212 // the virtual list control doesn't refresh itself correctly, help it
1215 // we need to refresh all the lines below the one which was deleted
1217 if ( item
> 0 && GetItemCount() )
1219 GetItemRect(item
- 1, rectItem
);
1224 rectItem
.height
= 0;
1227 wxRect rectWin
= GetRect();
1228 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1229 rectWin
.y
= rectItem
.GetBottom();
1231 RefreshRect(rectWin
);
1237 // Deletes all items
1238 bool wxListCtrl::DeleteAllItems()
1240 return ListView_DeleteAllItems(GetHwnd()) != 0;
1243 // Deletes all items
1244 bool wxListCtrl::DeleteAllColumns()
1246 while ( m_colCount
> 0 )
1248 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1250 wxLogLastError(wxT("ListView_DeleteColumn"));
1258 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1264 bool wxListCtrl::DeleteColumn(int col
)
1266 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1268 if ( success
&& (m_colCount
> 0) )
1273 // Clears items, and columns if there are any.
1274 void wxListCtrl::ClearAll()
1277 if ( m_colCount
> 0 )
1281 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1283 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1285 // ListView_EditLabel requires that the list has focus.
1288 WXHWND hWnd
= (WXHWND
) ListView_EditLabel(GetHwnd(), item
);
1291 // failed to start editing
1295 // [re]create the text control wrapping the HWND we got
1298 m_textCtrl
->SetHWND(0);
1299 m_textCtrl
->UnsubclassWin();
1303 m_textCtrl
= (wxTextCtrl
*)textControlClass
->CreateObject();
1304 m_textCtrl
->SetHWND(hWnd
);
1305 m_textCtrl
->SubclassWin(hWnd
);
1306 m_textCtrl
->SetParent(this);
1308 // we must disallow TABbing away from the control while the edit contol is
1309 // shown because this leaves it in some strange state (just try removing
1310 // this line and then pressing TAB while editing an item in listctrl
1312 m_textCtrl
->SetWindowStyle(m_textCtrl
->GetWindowStyle() | wxTE_PROCESS_TAB
);
1317 // End label editing, optionally cancelling the edit
1318 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1320 wxFAIL_MSG( _T("not implemented") );
1325 // Ensures this item is visible
1326 bool wxListCtrl::EnsureVisible(long item
)
1328 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0;
1331 // Find an item whose label matches this string, starting from the item after 'start'
1332 // or the beginning if 'start' is -1.
1333 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1335 LV_FINDINFO findInfo
;
1337 findInfo
.flags
= LVFI_STRING
;
1339 findInfo
.flags
|= LVFI_PARTIAL
;
1342 // ListView_FindItem() excludes the first item from search and to look
1343 // through all the items you need to start from -1 which is unnatural and
1344 // inconsistent with the generic version - so we adjust the index
1347 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1350 // Find an item whose data matches this data, starting from the item after 'start'
1351 // or the beginning if 'start' is -1.
1352 // NOTE : Lindsay Mathieson - 14-July-2002
1353 // No longer use ListView_FindItem as the data attribute is now stored
1354 // in a wxListItemInternalData structure refernced by the actual lParam
1355 long wxListCtrl::FindItem(long start
, long data
)
1357 long idx
= start
+ 1;
1358 long count
= GetItemCount();
1362 if (GetItemData(idx
) == data
)
1370 // Find an item nearest this position in the specified direction, starting from
1371 // the item after 'start' or the beginning if 'start' is -1.
1372 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1374 LV_FINDINFO findInfo
;
1376 findInfo
.flags
= LVFI_NEARESTXY
;
1377 findInfo
.pt
.x
= pt
.x
;
1378 findInfo
.pt
.y
= pt
.y
;
1379 findInfo
.vkDirection
= VK_RIGHT
;
1381 if ( direction
== wxLIST_FIND_UP
)
1382 findInfo
.vkDirection
= VK_UP
;
1383 else if ( direction
== wxLIST_FIND_DOWN
)
1384 findInfo
.vkDirection
= VK_DOWN
;
1385 else if ( direction
== wxLIST_FIND_LEFT
)
1386 findInfo
.vkDirection
= VK_LEFT
;
1387 else if ( direction
== wxLIST_FIND_RIGHT
)
1388 findInfo
.vkDirection
= VK_RIGHT
;
1390 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1393 // Determines which item (if any) is at the specified point,
1394 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1395 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1397 LV_HITTESTINFO hitTestInfo
;
1398 hitTestInfo
.pt
.x
= (int) point
.x
;
1399 hitTestInfo
.pt
.y
= (int) point
.y
;
1401 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1404 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1405 flags
|= wxLIST_HITTEST_ABOVE
;
1406 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1407 flags
|= wxLIST_HITTEST_BELOW
;
1408 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1409 flags
|= wxLIST_HITTEST_NOWHERE
;
1410 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1411 flags
|= wxLIST_HITTEST_ONITEMICON
;
1412 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1413 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1414 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1415 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1416 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1417 flags
|= wxLIST_HITTEST_TOLEFT
;
1418 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1419 flags
|= wxLIST_HITTEST_TORIGHT
;
1421 return (long) hitTestInfo
.iItem
;
1424 // Inserts an item, returning the index of the new item if successful,
1426 long wxListCtrl::InsertItem(wxListItem
& info
)
1428 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1431 wxConvertToMSWListItem(this, info
, item
);
1432 item
.mask
&= ~LVIF_PARAM
;
1434 // check wether we need to allocate our internal data
1435 bool needInternalData
= ((info
.m_mask
& wxLIST_MASK_DATA
) || info
.HasAttributes());
1436 if (needInternalData
)
1438 m_AnyInternalData
= TRUE
;
1439 item
.mask
|= LVIF_PARAM
;
1441 // internal stucture that manages data
1442 wxListItemInternalData
*data
= new wxListItemInternalData();
1443 item
.lParam
= (LPARAM
) data
;
1445 if (info
.m_mask
& wxLIST_MASK_DATA
)
1446 data
->lParam
= info
.m_data
;
1448 // check whether it has any custom attributes
1449 if ( info
.HasAttributes() )
1451 // take copy of attributes
1452 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
1457 return (long) ListView_InsertItem(GetHwnd(), & item
);
1460 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1463 info
.m_text
= label
;
1464 info
.m_mask
= wxLIST_MASK_TEXT
;
1465 info
.m_itemId
= index
;
1466 return InsertItem(info
);
1469 // Inserts an image item
1470 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1473 info
.m_image
= imageIndex
;
1474 info
.m_mask
= wxLIST_MASK_IMAGE
;
1475 info
.m_itemId
= index
;
1476 return InsertItem(info
);
1479 // Inserts an image/string item
1480 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1483 info
.m_image
= imageIndex
;
1484 info
.m_text
= label
;
1485 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1486 info
.m_itemId
= index
;
1487 return InsertItem(info
);
1490 // For list view mode (only), inserts a column.
1491 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1494 wxConvertToMSWListCol(col
, item
, lvCol
);
1496 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1498 // always give some width to the new column: this one is compatible
1499 // with the generic version
1500 lvCol
.mask
|= LVCF_WIDTH
;
1504 // when we insert a column which can contain an image, we must specify this
1505 // flag right now as doing it later in SetColumn() has no effect
1507 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1508 // way to dynamically set/clear the bitmap as the column without a bitmap
1509 // on the left looks ugly (there is a hole)
1511 // unfortunately with my version of comctl32.dll (5.80), the left column
1512 // image is always on the left and it seems that it's a "feature" - I
1513 // didn't find any way to work around it in any case
1514 if ( lvCol
.mask
& LVCF_IMAGE
)
1516 lvCol
.mask
|= LVCF_FMT
;
1517 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
;
1520 bool success
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
) != -1;
1527 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1534 long wxListCtrl::InsertColumn(long col
,
1535 const wxString
& heading
,
1540 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1541 item
.m_text
= heading
;
1544 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1545 item
.m_width
= width
;
1547 item
.m_format
= format
;
1549 return InsertColumn(col
, item
);
1552 // scroll the control by the given number of pixels (exception: in list view,
1553 // dx is interpreted as number of columns)
1554 bool wxListCtrl::ScrollList(int dx
, int dy
)
1556 if ( !ListView_Scroll(GetHwnd(), dx
, dy
) )
1558 wxLogDebug(_T("ListView_Scroll(%d, %d) failed"), dx
, dy
);
1568 // fn is a function which takes 3 long arguments: item1, item2, data.
1569 // item1 is the long data associated with a first item (NOT the index).
1570 // item2 is the long data associated with a second item (NOT the index).
1571 // data is the same value as passed to SortItems.
1572 // The return value is a negative number if the first item should precede the second
1573 // item, a positive number of the second item should precede the first,
1574 // or zero if the two items are equivalent.
1576 // data is arbitrary data to be passed to the sort function.
1578 // Internal structures for proxying the user compare function
1579 // so that we can pass it the *real* user data
1581 // translate lParam data and call user func
1582 struct wxInternalDataSort
1584 wxListCtrlCompare user_fn
;
1588 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
1590 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
1592 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
1593 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
1595 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
1596 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
1598 return internalData
->user_fn(d1
, d2
, internalData
->data
);
1602 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1604 struct wxInternalDataSort internalData
;
1605 internalData
.user_fn
= fn
;
1606 internalData
.data
= data
;
1608 // WPARAM cast is needed for mingw/cygwin
1609 if ( !ListView_SortItems(GetHwnd(),
1610 wxInternalDataCompareFunc
,
1611 (WPARAM
) &internalData
) )
1613 wxLogDebug(_T("ListView_SortItems() failed"));
1623 // ----------------------------------------------------------------------------
1624 // message processing
1625 // ----------------------------------------------------------------------------
1627 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1629 if (cmd
== EN_UPDATE
)
1631 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1632 event
.SetEventObject( this );
1633 ProcessCommand(event
);
1636 else if (cmd
== EN_KILLFOCUS
)
1638 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1639 event
.SetEventObject( this );
1640 ProcessCommand(event
);
1647 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1649 // prepare the event
1650 // -----------------
1652 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1653 event
.SetEventObject(this);
1655 wxEventType eventType
= wxEVT_NULL
;
1657 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1659 // if your compiler is as broken as this, you should really change it: this
1660 // code is needed for normal operation! #ifdef below is only useful for
1661 // automatic rebuilds which are done with a very old compiler version
1662 #ifdef HDN_BEGINTRACKA
1664 // check for messages from the header (in report view)
1665 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1667 // is it a message from the header?
1668 if ( nmhdr
->hwndFrom
== hwndHdr
)
1670 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1672 event
.m_itemIndex
= -1;
1674 switch ( nmhdr
->code
)
1676 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1677 // TRACK messages even to ANSI programs: on my system I get
1678 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1680 // work around is to simply catch both versions and hope that it
1681 // works (why should this message exist in ANSI and Unicode is
1682 // beyond me as it doesn't deal with strings at all...)
1684 // note that fr HDN_TRACK another possibility could be to use
1685 // HDN_ITEMCHANGING but it is sent even after HDN_ENDTRACK and when
1686 // something other than the item width changes so we'd have to
1687 // filter out the unwanted events then
1688 case HDN_BEGINTRACKA
:
1689 case HDN_BEGINTRACKW
:
1690 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1695 if ( eventType
== wxEVT_NULL
)
1696 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1701 if ( eventType
== wxEVT_NULL
)
1702 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1704 event
.m_item
.m_width
= nmHDR
->pitem
->cxy
;
1705 event
.m_col
= nmHDR
->iItem
;
1710 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1713 // find the column clicked: we have to search for it
1714 // ourselves as the notification message doesn't provide
1717 // where did the click occur?
1719 if ( !::GetCursorPos(&ptClick
) )
1721 wxLogLastError(_T("GetCursorPos"));
1724 if ( !::ScreenToClient(hwndHdr
, &ptClick
) )
1726 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1729 event
.m_pointDrag
.x
= ptClick
.x
;
1730 event
.m_pointDrag
.y
= ptClick
.y
;
1732 int colCount
= Header_GetItemCount(hwndHdr
);
1735 for ( int col
= 0; col
< colCount
; col
++ )
1737 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1739 if ( ::PtInRect(&rect
, ptClick
) )
1749 case HDN_GETDISPINFOW
:
1751 LPNMHDDISPINFOW info
= (LPNMHDDISPINFOW
) lParam
;
1752 // This is a fix for a strange bug under XP.
1753 // Normally, info->iItem is a valid index, but
1754 // sometimes this is a silly (large) number
1755 // and when we return FALSE via wxControl::MSWOnNotify
1756 // to indicate that it hasn't yet been processed,
1757 // there's a GPF in Windows.
1758 // By returning TRUE here, we avoid further processing
1759 // of this strange message.
1760 if (info
->iItem
> GetColumnCount())
1766 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1770 #endif // defined(HDN_BEGINTRACKA)
1771 if ( nmhdr
->hwndFrom
== GetHwnd() )
1773 // almost all messages use NM_LISTVIEW
1774 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1776 const int iItem
= nmLV
->iItem
;
1778 // set the data event field for all messages for which the system gives
1779 // us a valid NM_LISTVIEW::lParam
1780 switch ( nmLV
->hdr
.code
)
1783 case LVN_BEGINRDRAG
:
1784 case LVN_COLUMNCLICK
:
1785 case LVN_ITEMCHANGED
:
1786 case LVN_ITEMCHANGING
:
1789 wxListItemInternalData
*internaldata
=
1790 (wxListItemInternalData
*) nmLV
->lParam
;
1793 event
.m_item
.m_data
= internaldata
->lParam
;
1801 switch ( nmhdr
->code
)
1803 case LVN_BEGINRDRAG
:
1804 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1808 if ( eventType
== wxEVT_NULL
)
1810 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1813 event
.m_itemIndex
= iItem
;
1814 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1815 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1818 // NB: we have to handle both *A and *W versions here because some
1819 // versions of comctl32.dll send ANSI message to an Unicode app
1820 case LVN_BEGINLABELEDITA
:
1822 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1823 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1824 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1825 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1828 case LVN_BEGINLABELEDITW
:
1830 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1831 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1832 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1833 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1837 case LVN_ENDLABELEDITA
:
1839 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1840 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1841 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1842 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1843 ((LV_ITEM
)item
).iItem
== -1 )
1846 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1849 case LVN_ENDLABELEDITW
:
1851 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1852 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1853 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1854 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1855 ((LV_ITEM
)item
).iItem
== -1 )
1858 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1862 case LVN_COLUMNCLICK
:
1863 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1864 event
.m_itemIndex
= -1;
1865 event
.m_col
= nmLV
->iSubItem
;
1868 case LVN_DELETEALLITEMS
:
1869 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1870 event
.m_itemIndex
= -1;
1873 case LVN_DELETEITEM
:
1874 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1875 event
.m_itemIndex
= iItem
;
1876 // delete the assoicated internal data
1877 wxDeleteInternalData(this, iItem
);
1880 case LVN_SETDISPINFO
:
1882 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1883 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1884 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
1888 case LVN_INSERTITEM
:
1889 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1890 event
.m_itemIndex
= iItem
;
1893 case LVN_ITEMCHANGED
:
1894 // we translate this catch all message into more interesting
1895 // (and more easy to process) wxWindows events
1897 // first of all, we deal with the state change events only and
1898 // only for valid items (item == -1 for the virtual list
1900 if ( nmLV
->uChanged
& LVIF_STATE
&& iItem
!= -1 )
1902 // temp vars for readability
1903 const UINT stOld
= nmLV
->uOldState
;
1904 const UINT stNew
= nmLV
->uNewState
;
1906 event
.m_item
.SetId(iItem
);
1907 event
.m_item
.SetMask(wxLIST_MASK_TEXT
|
1910 GetItem(event
.m_item
);
1912 // has the focus changed?
1913 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
1915 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
1916 event
.m_itemIndex
= iItem
;
1919 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
1921 if ( eventType
!= wxEVT_NULL
)
1923 // focus and selection have both changed: send the
1924 // focus event from here and the selection one
1926 event
.SetEventType(eventType
);
1927 (void)GetEventHandler()->ProcessEvent(event
);
1929 else // no focus event to send
1931 // then need to set m_itemIndex as it wasn't done
1933 event
.m_itemIndex
= iItem
;
1936 eventType
= stNew
& LVIS_SELECTED
1937 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1938 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1942 if ( eventType
== wxEVT_NULL
)
1944 // not an interesting event for us
1952 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1953 WORD wVKey
= info
->wVKey
;
1955 // get the current selection
1956 long lItem
= GetNextItem(-1,
1958 wxLIST_STATE_SELECTED
);
1960 // <Enter> or <Space> activate the selected item if any (but
1961 // not with Shift and/or Ctrl as then they have a predefined
1962 // meaning for the list view)
1964 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
1965 !(wxIsShiftDown() || wxIsCtrlDown()) )
1967 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1971 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1973 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1974 // value which should be used as is
1975 int code
= wxCharCodeMSWToWX(wVKey
);
1976 event
.m_code
= code
? code
: wVKey
;
1980 event
.m_item
.m_itemId
= lItem
;
1984 // fill the other fields too
1985 event
.m_item
.m_text
= GetItemText(lItem
);
1986 event
.m_item
.m_data
= GetItemData(lItem
);
1992 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1994 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1999 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
2000 // if it happened on an item (and not on empty place)
2007 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
2008 event
.m_itemIndex
= iItem
;
2009 event
.m_item
.m_text
= GetItemText(iItem
);
2010 event
.m_item
.m_data
= GetItemData(iItem
);
2014 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
2015 // don't do anything else
2016 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
2021 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
2022 LV_HITTESTINFO lvhti
;
2023 wxZeroMemory(lvhti
);
2025 ::GetCursorPos(&(lvhti
.pt
));
2026 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
2027 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
2029 if ( lvhti
.flags
& LVHT_ONITEM
)
2031 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
2032 event
.m_itemIndex
= lvhti
.iItem
;
2033 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
2034 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
2039 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2040 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
2042 *result
= OnCustomDraw(lParam
);
2045 #endif // _WIN32_IE >= 0x300
2047 case LVN_ODCACHEHINT
:
2049 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
2051 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
2053 // we get some really stupid cache hints like ones for items in
2054 // range 0..0 for an empty control or, after deleting an item,
2055 // for items in invalid range - filter this garbage out
2056 if ( cacheHint
->iFrom
< cacheHint
->iTo
)
2058 event
.m_oldItemIndex
= cacheHint
->iFrom
;
2060 long iMax
= GetItemCount();
2061 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
2071 case LVN_GETDISPINFO
:
2074 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
2076 LV_ITEM
& lvi
= info
->item
;
2077 long item
= lvi
.iItem
;
2079 if ( lvi
.mask
& LVIF_TEXT
)
2081 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
2082 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
2085 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2086 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2087 if ( lvi
.mask
& LVIF_IMAGE
)
2089 lvi
.iImage
= OnGetItemImage(item
);
2093 // a little dose of healthy paranoia: as we never use
2094 // LVM_SETCALLBACKMASK we're not supposed to get these ones
2095 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
2096 _T("we don't support state callbacks yet!") );
2103 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
2108 // where did this one come from?
2112 // process the event
2113 // -----------------
2115 event
.SetEventType(eventType
);
2117 if ( !GetEventHandler()->ProcessEvent(event
) )
2123 switch ( nmhdr
->code
)
2125 case LVN_DELETEALLITEMS
:
2126 // always return TRUE to suppress all additional LVN_DELETEITEM
2127 // notifications - this makes deleting all items from a list ctrl
2133 case LVN_ENDLABELEDITA
:
2134 case LVN_ENDLABELEDITW
:
2135 // logic here is inversed compared to all the other messages
2136 *result
= event
.IsAllowed();
2138 // don't keep a stale wxTextCtrl around
2141 // EDIT control will be deleted by the list control itself so
2142 // prevent us from deleting it as well
2143 m_textCtrl
->SetHWND(0);
2144 m_textCtrl
->UnsubclassWin();
2152 *result
= !event
.IsAllowed();
2157 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
2159 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
2161 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
2162 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
2163 switch ( nmcd
.dwDrawStage
)
2166 // if we've got any items with non standard attributes,
2167 // notify us before painting each item
2169 // for virtual controls, always suppose that we have attributes as
2170 // there is no way to check for this
2171 return IsVirtual() || m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
2174 case CDDS_ITEMPREPAINT
:
2176 size_t item
= (size_t)nmcd
.dwItemSpec
;
2177 if ( item
>= (size_t)GetItemCount() )
2179 // we get this message with item == 0 for an empty control,
2180 // we must ignore it as calling OnGetItemAttr() would be
2182 return CDRF_DODEFAULT
;
2185 wxListItemAttr
*attr
=
2186 IsVirtual() ? OnGetItemAttr(item
)
2187 : wxGetInternalDataAttr(this, item
);
2191 // nothing to do for this item
2192 return CDRF_DODEFAULT
;
2196 wxColour colText
, colBack
;
2197 if ( attr
->HasFont() )
2199 wxFont font
= attr
->GetFont();
2200 hFont
= (HFONT
)font
.GetResourceHandle();
2207 if ( attr
->HasTextColour() )
2209 colText
= attr
->GetTextColour();
2213 colText
= GetTextColour();
2216 if ( attr
->HasBackgroundColour() )
2218 colBack
= attr
->GetBackgroundColour();
2222 colBack
= GetBackgroundColour();
2225 lplvcd
->clrText
= wxColourToRGB(colText
);
2226 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
2228 // note that if we wanted to set colours for
2229 // individual columns (subitems), we would have
2230 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2233 ::SelectObject(nmcd
.hdc
, hFont
);
2235 return CDRF_NEWFONT
;
2238 // fall through to return CDRF_DODEFAULT
2241 return CDRF_DODEFAULT
;
2245 #endif // NM_CUSTOMDRAW supported
2247 // Necessary for drawing hrules and vrules, if specified
2248 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2252 wxControl::OnPaint(event
);
2254 // Reset the device origin since it may have been set
2255 dc
.SetDeviceOrigin(0, 0);
2257 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
2258 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
2260 if (!drawHRules
&& !drawVRules
)
2262 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
2265 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2267 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2269 wxSize clientSize
= GetClientSize();
2273 int itemCount
= GetItemCount();
2277 long top
= GetTopItem();
2278 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2280 if (GetItemRect(i
, itemRect
))
2282 cy
= itemRect
.GetTop();
2283 if (i
!= 0) // Don't draw the first one
2285 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2288 if (i
== itemCount
- 1)
2290 cy
= itemRect
.GetBottom();
2291 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2297 if (drawVRules
&& (i
> -1))
2299 wxRect firstItemRect
;
2300 GetItemRect(0, firstItemRect
);
2302 if (GetItemRect(i
, itemRect
))
2305 int x
= itemRect
.GetX();
2306 for (col
= 0; col
< GetColumnCount(); col
++)
2308 int colWidth
= GetColumnWidth(col
);
2310 dc
.DrawLine(x
-1, firstItemRect
.GetY() - 2, x
-1, itemRect
.GetBottom());
2316 // ----------------------------------------------------------------------------
2317 // virtual list controls
2318 // ----------------------------------------------------------------------------
2320 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2322 // this is a pure virtual function, in fact - which is not really pure
2323 // because the controls which are not virtual don't need to implement it
2324 wxFAIL_MSG( _T("not supposed to be called") );
2326 return wxEmptyString
;
2329 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2332 wxFAIL_MSG( _T("not supposed to be called") );
2337 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2339 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2340 _T("invalid item index in OnGetItemAttr()") );
2342 // no attributes by default
2346 void wxListCtrl::SetItemCount(long count
)
2348 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2350 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
, 0) )
2352 wxLogLastError(_T("ListView_SetItemCount"));
2356 void wxListCtrl::RefreshItem(long item
)
2358 // strangely enough, ListView_Update() results in much more flicker here
2359 // than a dumb Refresh() -- why?
2361 if ( !ListView_Update(GetHwnd(), item
) )
2363 wxLogLastError(_T("ListView_Update"));
2367 GetItemRect(item
, rect
);
2372 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2374 wxRect rect1
, rect2
;
2375 GetItemRect(itemFrom
, rect1
);
2376 GetItemRect(itemTo
, rect2
);
2378 wxRect rect
= rect1
;
2379 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2384 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
2387 it
.mask
= LVIF_PARAM
;
2390 bool success
= ListView_GetItem(hwnd
, &it
) != 0;
2392 return (wxListItemInternalData
*) it
.lParam
;
2397 static wxListItemInternalData
*wxGetInternalData(wxListCtrl
*ctl
, long itemId
)
2399 return wxGetInternalData((HWND
) ctl
->GetHWND(), itemId
);
2402 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
2404 wxListItemInternalData
*data
= wxGetInternalData(ctl
, itemId
);
2411 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
2413 wxListItemInternalData
*data
= wxGetInternalData(ctl
, itemId
);
2418 memset(&item
, 0, sizeof(item
));
2419 item
.iItem
= itemId
;
2420 item
.mask
= LVIF_PARAM
;
2421 item
.lParam
= (LPARAM
) 0;
2422 ListView_SetItem((HWND
)ctl
->GetHWND(), &item
);
2426 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2430 wxListItemInternalData
*internaldata
=
2431 (wxListItemInternalData
*) lvItem
.lParam
;
2434 info
.m_data
= internaldata
->lParam
;
2438 info
.m_stateMask
= 0;
2439 info
.m_itemId
= lvItem
.iItem
;
2441 long oldMask
= lvItem
.mask
;
2443 bool needText
= FALSE
;
2444 if (hwndListCtrl
!= 0)
2446 if ( lvItem
.mask
& LVIF_TEXT
)
2453 lvItem
.pszText
= new wxChar
[513];
2454 lvItem
.cchTextMax
= 512;
2456 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2457 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2460 if ( lvItem
.mask
& LVIF_STATE
)
2462 info
.m_mask
|= wxLIST_MASK_STATE
;
2464 if ( lvItem
.stateMask
& LVIS_CUT
)
2466 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2467 if ( lvItem
.state
& LVIS_CUT
)
2468 info
.m_state
|= wxLIST_STATE_CUT
;
2470 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2472 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2473 if ( lvItem
.state
& LVIS_DROPHILITED
)
2474 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2476 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2478 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2479 if ( lvItem
.state
& LVIS_FOCUSED
)
2480 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2482 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2484 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2485 if ( lvItem
.state
& LVIS_SELECTED
)
2486 info
.m_state
|= wxLIST_STATE_SELECTED
;
2490 if ( lvItem
.mask
& LVIF_TEXT
)
2492 info
.m_mask
|= wxLIST_MASK_TEXT
;
2493 info
.m_text
= lvItem
.pszText
;
2495 if ( lvItem
.mask
& LVIF_IMAGE
)
2497 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2498 info
.m_image
= lvItem
.iImage
;
2500 if ( lvItem
.mask
& LVIF_PARAM
)
2501 info
.m_mask
|= wxLIST_MASK_DATA
;
2502 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2503 info
.m_mask
|= wxLIST_SET_ITEM
;
2504 info
.m_col
= lvItem
.iSubItem
;
2509 delete[] lvItem
.pszText
;
2511 lvItem
.mask
= oldMask
;
2514 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2516 if (stateMask
& wxLIST_STATE_CUT
)
2518 lvItem
.stateMask
|= LVIS_CUT
;
2519 if (state
& wxLIST_STATE_CUT
)
2520 lvItem
.state
|= LVIS_CUT
;
2522 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2524 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2525 if (state
& wxLIST_STATE_DROPHILITED
)
2526 lvItem
.state
|= LVIS_DROPHILITED
;
2528 if (stateMask
& wxLIST_STATE_FOCUSED
)
2530 lvItem
.stateMask
|= LVIS_FOCUSED
;
2531 if (state
& wxLIST_STATE_FOCUSED
)
2532 lvItem
.state
|= LVIS_FOCUSED
;
2534 if (stateMask
& wxLIST_STATE_SELECTED
)
2536 lvItem
.stateMask
|= LVIS_SELECTED
;
2537 if (state
& wxLIST_STATE_SELECTED
)
2538 lvItem
.state
|= LVIS_SELECTED
;
2542 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2543 const wxListItem
& info
,
2546 lvItem
.iItem
= (int) info
.m_itemId
;
2548 lvItem
.iImage
= info
.m_image
;
2549 lvItem
.stateMask
= 0;
2552 lvItem
.iSubItem
= info
.m_col
;
2554 if (info
.m_mask
& wxLIST_MASK_STATE
)
2556 lvItem
.mask
|= LVIF_STATE
;
2558 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2561 if (info
.m_mask
& wxLIST_MASK_TEXT
)
2563 lvItem
.mask
|= LVIF_TEXT
;
2564 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
2566 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
2570 // pszText is not const, hence the cast
2571 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
2572 if ( lvItem
.pszText
)
2573 lvItem
.cchTextMax
= info
.m_text
.Length();
2575 lvItem
.cchTextMax
= 0;
2578 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
2579 lvItem
.mask
|= LVIF_IMAGE
;
2582 static void wxConvertToMSWListCol(int WXUNUSED(col
), const wxListItem
& item
,
2585 wxZeroMemory(lvCol
);
2587 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
2589 lvCol
.mask
|= LVCF_TEXT
;
2590 lvCol
.pszText
= (wxChar
*)item
.m_text
.c_str(); // cast is safe
2593 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
2595 lvCol
.mask
|= LVCF_FMT
;
2597 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
2598 lvCol
.fmt
= LVCFMT_LEFT
;
2599 else if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
2600 lvCol
.fmt
= LVCFMT_RIGHT
;
2601 else if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
2602 lvCol
.fmt
= LVCFMT_CENTER
;
2605 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
2607 lvCol
.mask
|= LVCF_WIDTH
;
2608 if ( item
.m_width
== wxLIST_AUTOSIZE
)
2609 lvCol
.cx
= LVSCW_AUTOSIZE
;
2610 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2611 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
2613 lvCol
.cx
= item
.m_width
;
2616 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2617 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2618 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
2620 if ( wxTheApp
->GetComCtl32Version() >= 470 )
2622 lvCol
.mask
|= LVCF_IMAGE
;
2623 lvCol
.iImage
= item
.m_image
;
2625 //else: it doesn't support item images anyhow
2630 #endif // wxUSE_LISTCTRL