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
142 ///////////////////////////////////////////////////////
144 // The MSW version had problems with SetTextColour() et
145 // al as the wxListItemAttr's were stored keyed on the
146 // item index. If a item was inserted anywhere but the end
147 // of the list the the text attributes (colour etc) for
148 // the following items were out of sync.
151 // Under MSW the only way to associate data with a List
152 // item independant of its position in the list is to
153 // store a pointer to it in its lParam attribute. However
154 // user programs are already using this (via the
155 // SetItemData() GetItemData() calls).
157 // However what we can do is store a pointer to a
158 // structure which contains the attributes we want *and*
159 // a lParam for the users data, e.g.
161 // class wxListItemInternalData
164 // wxListItemAttr *attr;
165 // long lParam; // user data
168 // To conserve memory, a wxListItemInternalData is
169 // only allocated for a LV_ITEM if text attributes or
170 // user data(lparam) are being set.
173 // class wxListItemInternalData
174 class wxListItemInternalData
177 wxListItemAttr
*attr
;
178 LPARAM lParam
; // user data
180 wxListItemInternalData() : attr(NULL
), lParam(0) {}
181 ~wxListItemInternalData()
188 // Get the internal data structure
189 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
);
190 static wxListItemInternalData
*wxGetInternalData(wxListCtrl
*ctl
, long itemId
);
191 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
);
192 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
);
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
199 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_DRAG
)
200 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_RDRAG
)
201 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
)
202 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_END_LABEL_EDIT
)
203 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ITEM
)
204 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
)
205 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_GET_INFO
)
206 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_SET_INFO
)
207 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_SELECTED
)
208 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_DESELECTED
)
209 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_KEY_DOWN
)
210 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_INSERT_ITEM
)
211 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_CLICK
)
212 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
)
213 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
)
214 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_DRAGGING
)
215 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_COL_END_DRAG
)
216 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
)
217 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
)
218 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_ACTIVATED
)
219 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_ITEM_FOCUSED
)
220 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LIST_CACHE_HINT
)
222 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
223 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
224 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
226 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
228 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
229 EVT_PAINT(wxListCtrl::OnPaint
)
232 // ============================================================================
234 // ============================================================================
236 // ----------------------------------------------------------------------------
237 // wxListCtrl construction
238 // ----------------------------------------------------------------------------
240 void wxListCtrl::Init()
242 m_imageListNormal
= NULL
;
243 m_imageListSmall
= NULL
;
244 m_imageListState
= NULL
;
245 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
249 m_AnyInternalData
= FALSE
;
250 m_hasAnyAttr
= FALSE
;
253 bool wxListCtrl::Create(wxWindow
*parent
,
258 const wxValidator
& validator
,
259 const wxString
& name
)
262 SetValidator(validator
);
263 #endif // wxUSE_VALIDATORS
272 m_windowStyle
= style
;
285 m_windowId
= (id
== -1) ? NewControlId() : id
;
287 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
288 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
290 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
291 wstyle
|= WS_CLIPSIBLINGS
;
293 if ( wxStyleHasBorder(m_windowStyle
) )
295 m_baseStyle
= wstyle
;
297 if ( !DoCreateControl(x
, y
, width
, height
) )
301 parent
->AddChild(this);
306 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
308 DWORD wstyle
= m_baseStyle
;
311 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
313 // Even with extended styles, need to combine with WS_BORDER
314 // for them to look right.
318 long oldStyle
= 0; // Dummy
319 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
321 // Create the ListView control.
322 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
327 GetWinHwnd(GetParent()),
334 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
339 // for comctl32.dll v 4.70+ we want to have this attribute because it's
340 // prettier (and also because wxGTK does it like this)
341 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
343 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
344 0, LVS_EX_FULLROWSELECT
);
347 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
348 SetForegroundColour(GetParent()->GetForegroundColour());
355 void wxListCtrl::UpdateStyle()
359 // The new window view style
361 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
362 dwStyleNew
|= m_baseStyle
;
364 // Get the current window style.
365 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
367 // Only set the window style if the view bits have changed.
368 if ( dwStyleOld
!= dwStyleNew
)
370 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
375 void wxListCtrl::FreeAllInternalData()
377 if (m_AnyInternalData
)
379 int n
= GetItemCount();
382 for (i
= 0; i
< n
; i
++)
383 wxDeleteInternalData(this, i
);
385 m_AnyInternalData
= FALSE
;
389 wxListCtrl::~wxListCtrl()
391 FreeAllInternalData();
395 m_textCtrl
->SetHWND(0);
396 m_textCtrl
->UnsubclassWin();
401 if (m_ownsImageListNormal
) delete m_imageListNormal
;
402 if (m_ownsImageListSmall
) delete m_imageListSmall
;
403 if (m_ownsImageListState
) delete m_imageListState
;
406 // ----------------------------------------------------------------------------
407 // set/get/change style
408 // ----------------------------------------------------------------------------
410 // Add or remove a single window style
411 void wxListCtrl::SetSingleStyle(long style
, bool add
)
413 long flag
= GetWindowStyleFlag();
415 // Get rid of conflicting styles
418 if ( style
& wxLC_MASK_TYPE
)
419 flag
= flag
& ~wxLC_MASK_TYPE
;
420 if ( style
& wxLC_MASK_ALIGN
)
421 flag
= flag
& ~wxLC_MASK_ALIGN
;
422 if ( style
& wxLC_MASK_SORT
)
423 flag
= flag
& ~wxLC_MASK_SORT
;
439 m_windowStyle
= flag
;
444 // Set the whole window style
445 void wxListCtrl::SetWindowStyleFlag(long flag
)
447 m_windowStyle
= flag
;
452 // Can be just a single style, or a bitlist
453 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
456 if ( style
& wxLC_ICON
)
458 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
459 oldStyle
-= LVS_SMALLICON
;
460 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
461 oldStyle
-= LVS_REPORT
;
462 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
463 oldStyle
-= LVS_LIST
;
467 if ( style
& wxLC_SMALL_ICON
)
469 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
470 oldStyle
-= LVS_ICON
;
471 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
472 oldStyle
-= LVS_REPORT
;
473 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
474 oldStyle
-= LVS_LIST
;
475 wstyle
|= LVS_SMALLICON
;
478 if ( style
& wxLC_LIST
)
480 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
481 oldStyle
-= LVS_ICON
;
482 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
483 oldStyle
-= LVS_REPORT
;
484 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
485 oldStyle
-= LVS_SMALLICON
;
489 if ( style
& wxLC_REPORT
)
491 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
492 oldStyle
-= LVS_ICON
;
493 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
494 oldStyle
-= LVS_LIST
;
495 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
496 oldStyle
-= LVS_SMALLICON
;
498 wstyle
|= LVS_REPORT
;
501 if ( style
& wxLC_ALIGN_LEFT
)
503 if ( oldStyle
& LVS_ALIGNTOP
)
504 oldStyle
-= LVS_ALIGNTOP
;
505 wstyle
|= LVS_ALIGNLEFT
;
508 if ( style
& wxLC_ALIGN_TOP
)
510 if ( oldStyle
& LVS_ALIGNLEFT
)
511 oldStyle
-= LVS_ALIGNLEFT
;
512 wstyle
|= LVS_ALIGNTOP
;
515 if ( style
& wxLC_AUTOARRANGE
)
516 wstyle
|= LVS_AUTOARRANGE
;
518 if ( style
& wxLC_NO_SORT_HEADER
)
519 wstyle
|= LVS_NOSORTHEADER
;
521 if ( style
& wxLC_NO_HEADER
)
522 wstyle
|= LVS_NOCOLUMNHEADER
;
524 if ( style
& wxLC_EDIT_LABELS
)
525 wstyle
|= LVS_EDITLABELS
;
527 if ( style
& wxLC_SINGLE_SEL
)
528 wstyle
|= LVS_SINGLESEL
;
530 if ( style
& wxLC_SORT_ASCENDING
)
532 if ( oldStyle
& LVS_SORTDESCENDING
)
533 oldStyle
-= LVS_SORTDESCENDING
;
534 wstyle
|= LVS_SORTASCENDING
;
537 if ( style
& wxLC_SORT_DESCENDING
)
539 if ( oldStyle
& LVS_SORTASCENDING
)
540 oldStyle
-= LVS_SORTASCENDING
;
541 wstyle
|= LVS_SORTDESCENDING
;
544 #if !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
545 if ( style
& wxLC_VIRTUAL
)
547 int ver
= wxTheApp
->GetComCtl32Version();
550 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."),
551 ver
/ 100, ver
% 100);
554 wstyle
|= LVS_OWNERDATA
;
561 // ----------------------------------------------------------------------------
563 // ----------------------------------------------------------------------------
565 // Sets the foreground, i.e. text, colour
566 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
568 if ( !wxWindow::SetForegroundColour(col
) )
571 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
576 // Sets the background colour
577 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
579 if ( !wxWindow::SetBackgroundColour(col
) )
582 // we set the same colour for both the "empty" background and the items
584 COLORREF color
= wxColourToRGB(col
);
585 ListView_SetBkColor(GetHwnd(), color
);
586 ListView_SetTextBkColor(GetHwnd(), color
);
591 // Gets information about this column
592 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
597 lvCol
.mask
= LVCF_WIDTH
;
599 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
601 lvCol
.mask
|= LVCF_TEXT
;
602 lvCol
.pszText
= new wxChar
[513];
603 lvCol
.cchTextMax
= 512;
606 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
608 lvCol
.mask
|= LVCF_FMT
;
611 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
613 lvCol
.mask
|= LVCF_IMAGE
;
616 bool success
= ListView_GetColumn(GetHwnd(), col
, &lvCol
) != 0;
618 // item.m_subItem = lvCol.iSubItem;
619 item
.m_width
= lvCol
.cx
;
621 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
623 item
.m_text
= lvCol
.pszText
;
624 delete[] lvCol
.pszText
;
627 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
629 switch (lvCol
.fmt
& LVCFMT_JUSTIFYMASK
) {
631 item
.m_format
= wxLIST_FORMAT_LEFT
;
634 item
.m_format
= wxLIST_FORMAT_RIGHT
;
637 item
.m_format
= wxLIST_FORMAT_CENTRE
;
640 item
.m_format
= -1; // Unknown?
645 #if _WIN32_IE >= 0x0300
646 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
648 item
.m_image
= lvCol
.iImage
;
655 // Sets information about this column
656 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
659 wxConvertToMSWListCol(col
, item
, lvCol
);
661 return ListView_SetColumn(GetHwnd(), col
, &lvCol
) != 0;
664 // Gets the column width
665 int wxListCtrl::GetColumnWidth(int col
) const
667 return ListView_GetColumnWidth(GetHwnd(), col
);
670 // Sets the column width
671 bool wxListCtrl::SetColumnWidth(int col
, int width
)
674 if ( m_windowStyle
& wxLC_LIST
)
678 if ( width2
== wxLIST_AUTOSIZE
)
679 width2
= LVSCW_AUTOSIZE
;
680 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
681 width2
= LVSCW_AUTOSIZE_USEHEADER
;
683 return ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0;
686 // Gets the number of items that can fit vertically in the
687 // visible area of the list control (list or report view)
688 // or the total number of items in the list control (icon
689 // or small icon view)
690 int wxListCtrl::GetCountPerPage() const
692 return ListView_GetCountPerPage(GetHwnd());
695 // Gets the edit control for editing labels.
696 wxTextCtrl
* wxListCtrl::GetEditControl() const
701 // Gets information about the item
702 bool wxListCtrl::GetItem(wxListItem
& info
) const
705 wxZeroMemory(lvItem
);
707 lvItem
.iItem
= info
.m_itemId
;
708 lvItem
.iSubItem
= info
.m_col
;
710 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
712 lvItem
.mask
|= LVIF_TEXT
;
713 lvItem
.pszText
= new wxChar
[513];
714 lvItem
.cchTextMax
= 512;
718 lvItem
.pszText
= NULL
;
721 if (info
.m_mask
& wxLIST_MASK_DATA
)
722 lvItem
.mask
|= LVIF_PARAM
;
724 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
725 lvItem
.mask
|= LVIF_IMAGE
;
727 if ( info
.m_mask
& wxLIST_MASK_STATE
)
729 lvItem
.mask
|= LVIF_STATE
;
730 // the other bits are hardly interesting anyhow
731 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
734 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
737 wxLogError(_("Couldn't retrieve information about list control item %d."),
742 // give NULL as hwnd as we already have everything we need
743 wxConvertFromMSWListItem(NULL
, info
, lvItem
);
747 delete[] lvItem
.pszText
;
752 // Sets information about the item
753 bool wxListCtrl::SetItem(wxListItem
& info
)
756 wxConvertToMSWListItem(this, info
, item
);
758 // we never update the lParam if it contains our pointer
759 // to the wxListItemInternalData structure
760 item
.mask
&= ~LVIF_PARAM
;
762 // check if setting attributes or lParam
763 if (info
.HasAttributes() || (info
.m_mask
& wxLIST_MASK_DATA
))
765 // get internal item data
766 // perhaps a cache here ?
767 wxListItemInternalData
*data
= wxGetInternalData(this, info
.m_itemId
);
772 m_AnyInternalData
= TRUE
;
773 data
= new wxListItemInternalData();
774 item
.lParam
= (LPARAM
) data
;
775 item
.mask
|= LVIF_PARAM
;
780 if (info
.m_mask
& wxLIST_MASK_DATA
)
781 data
->lParam
= info
.m_data
;
784 if (info
.HasAttributes())
787 *data
->attr
= *info
.GetAttributes();
789 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
794 // we could be changing only the attribute in which case we don't need to
795 // call ListView_SetItem() at all
799 if ( !ListView_SetItem(GetHwnd(), &item
) )
801 wxLogDebug(_T("ListView_SetItem() failed"));
807 // we need to update the item immediately to show the new image
808 bool updateNow
= (info
.m_mask
& wxLIST_MASK_IMAGE
) != 0;
810 // check whether it has any custom attributes
811 if ( info
.HasAttributes() )
815 // if the colour has changed, we must redraw the item
821 // we need this to make the change visible right now
822 RefreshItem(item
.iItem
);
828 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
832 info
.m_mask
= wxLIST_MASK_TEXT
;
833 info
.m_itemId
= index
;
837 info
.m_image
= imageId
;
838 info
.m_mask
|= wxLIST_MASK_IMAGE
;
840 return SetItem(info
);
844 // Gets the item state
845 int wxListCtrl::GetItemState(long item
, long stateMask
) const
849 info
.m_mask
= wxLIST_MASK_STATE
;
850 info
.m_stateMask
= stateMask
;
851 info
.m_itemId
= item
;
859 // Sets the item state
860 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
862 // NB: don't use SetItem() here as it doesn't work with the virtual list
865 wxZeroMemory(lvItem
);
867 wxConvertToMSWFlags(state
, stateMask
, lvItem
);
869 // for the virtual list controls we need to refresh the previously focused
870 // item manually when changing focus without changing selection
871 // programmatically because otherwise it keeps its focus rectangle until
872 // next repaint (yet another comctl32 bug)
875 (stateMask
& wxLIST_STATE_FOCUSED
) &&
876 (state
& wxLIST_STATE_FOCUSED
) )
878 focusOld
= GetNextItem(-1, wxLIST_NEXT_ALL
, wxLIST_STATE_FOCUSED
);
885 if ( !::SendMessage(GetHwnd(), LVM_SETITEMSTATE
,
886 (WPARAM
)item
, (LPARAM
)&lvItem
) )
888 wxLogLastError(_T("ListView_SetItemState"));
893 if ( focusOld
!= -1 )
895 // no need to refresh the item if it was previously selected, it would
896 // only result in annoying flicker
897 if ( !(GetItemState(focusOld
,
898 wxLIST_STATE_SELECTED
) & wxLIST_STATE_SELECTED
) )
900 RefreshItem(focusOld
);
907 // Sets the item image
908 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
912 info
.m_mask
= wxLIST_MASK_IMAGE
;
913 info
.m_image
= image
;
914 info
.m_itemId
= item
;
916 return SetItem(info
);
919 // Gets the item text
920 wxString
wxListCtrl::GetItemText(long item
) const
924 info
.m_mask
= wxLIST_MASK_TEXT
;
925 info
.m_itemId
= item
;
928 return wxEmptyString
;
932 // Sets the item text
933 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
937 info
.m_mask
= wxLIST_MASK_TEXT
;
938 info
.m_itemId
= item
;
944 // Gets the item data
945 long wxListCtrl::GetItemData(long item
) const
949 info
.m_mask
= wxLIST_MASK_DATA
;
950 info
.m_itemId
= item
;
957 // Sets the item data
958 bool wxListCtrl::SetItemData(long item
, long data
)
962 info
.m_mask
= wxLIST_MASK_DATA
;
963 info
.m_itemId
= item
;
966 return SetItem(info
);
969 // Gets the item rectangle
970 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
975 if ( code
== wxLIST_RECT_BOUNDS
)
976 codeWin
= LVIR_BOUNDS
;
977 else if ( code
== wxLIST_RECT_ICON
)
979 else if ( code
== wxLIST_RECT_LABEL
)
980 codeWin
= LVIR_LABEL
;
983 wxFAIL_MSG( _T("incorrect code in GetItemRect()") );
985 codeWin
= LVIR_BOUNDS
;
988 bool success
= ListView_GetItemRect(GetHwnd(), (int) item
, &rectWin
, codeWin
) != 0;
990 rect
.x
= rectWin
.left
;
991 rect
.y
= rectWin
.top
;
992 rect
.width
= rectWin
.right
- rectWin
.left
;
993 rect
.height
= rectWin
.bottom
- rectWin
.top
;
998 // Gets the item position
999 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
1003 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
1005 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
1009 // Sets the item position.
1010 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
1012 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
1015 // Gets the number of items in the list control
1016 int wxListCtrl::GetItemCount() const
1018 return ListView_GetItemCount(GetHwnd());
1021 // Retrieves the spacing between icons in pixels.
1022 // If small is TRUE, gets the spacing for the small icon
1023 // view, otherwise the large icon view.
1024 int wxListCtrl::GetItemSpacing(bool isSmall
) const
1026 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
1029 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1032 info
.m_itemId
= item
;
1033 info
.SetTextColour( col
);
1037 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1040 info
.m_itemId
= item
;
1042 return info
.GetTextColour();
1045 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1048 info
.m_itemId
= item
;
1049 info
.SetBackgroundColour( col
);
1053 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1056 info
.m_itemId
= item
;
1058 return info
.GetBackgroundColour();
1061 // Gets the number of selected items in the list control
1062 int wxListCtrl::GetSelectedItemCount() const
1064 return ListView_GetSelectedCount(GetHwnd());
1067 // Gets the text colour of the listview
1068 wxColour
wxListCtrl::GetTextColour() const
1070 COLORREF ref
= ListView_GetTextColor(GetHwnd());
1071 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
1075 // Sets the text colour of the listview
1076 void wxListCtrl::SetTextColour(const wxColour
& col
)
1078 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
1081 // Gets the index of the topmost visible item when in
1082 // list or report view
1083 long wxListCtrl::GetTopItem() const
1085 return (long) ListView_GetTopIndex(GetHwnd());
1088 // Searches for an item, starting from 'item'.
1089 // 'geometry' is one of
1090 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1091 // 'state' is a state bit flag, one or more of
1092 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1093 // item can be -1 to find the first item that matches the
1095 // Returns the item or -1 if unsuccessful.
1096 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1100 if ( geom
== wxLIST_NEXT_ABOVE
)
1101 flags
|= LVNI_ABOVE
;
1102 if ( geom
== wxLIST_NEXT_ALL
)
1104 if ( geom
== wxLIST_NEXT_BELOW
)
1105 flags
|= LVNI_BELOW
;
1106 if ( geom
== wxLIST_NEXT_LEFT
)
1107 flags
|= LVNI_TOLEFT
;
1108 if ( geom
== wxLIST_NEXT_RIGHT
)
1109 flags
|= LVNI_TORIGHT
;
1111 if ( state
& wxLIST_STATE_CUT
)
1113 if ( state
& wxLIST_STATE_DROPHILITED
)
1114 flags
|= LVNI_DROPHILITED
;
1115 if ( state
& wxLIST_STATE_FOCUSED
)
1116 flags
|= LVNI_FOCUSED
;
1117 if ( state
& wxLIST_STATE_SELECTED
)
1118 flags
|= LVNI_SELECTED
;
1120 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
1124 wxImageList
*wxListCtrl::GetImageList(int which
) const
1126 if ( which
== wxIMAGE_LIST_NORMAL
)
1128 return m_imageListNormal
;
1130 else if ( which
== wxIMAGE_LIST_SMALL
)
1132 return m_imageListSmall
;
1134 else if ( which
== wxIMAGE_LIST_STATE
)
1136 return m_imageListState
;
1141 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1144 if ( which
== wxIMAGE_LIST_NORMAL
)
1146 flags
= LVSIL_NORMAL
;
1147 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1148 m_imageListNormal
= imageList
;
1149 m_ownsImageListNormal
= FALSE
;
1151 else if ( which
== wxIMAGE_LIST_SMALL
)
1153 flags
= LVSIL_SMALL
;
1154 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1155 m_imageListSmall
= imageList
;
1156 m_ownsImageListSmall
= FALSE
;
1158 else if ( which
== wxIMAGE_LIST_STATE
)
1160 flags
= LVSIL_STATE
;
1161 if (m_ownsImageListState
) delete m_imageListState
;
1162 m_imageListState
= imageList
;
1163 m_ownsImageListState
= FALSE
;
1165 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
1168 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1170 SetImageList(imageList
, which
);
1171 if ( which
== wxIMAGE_LIST_NORMAL
)
1172 m_ownsImageListNormal
= TRUE
;
1173 else if ( which
== wxIMAGE_LIST_SMALL
)
1174 m_ownsImageListSmall
= TRUE
;
1175 else if ( which
== wxIMAGE_LIST_STATE
)
1176 m_ownsImageListState
= TRUE
;
1179 // ----------------------------------------------------------------------------
1181 // ----------------------------------------------------------------------------
1183 // Arranges the items
1184 bool wxListCtrl::Arrange(int flag
)
1187 if ( flag
== wxLIST_ALIGN_LEFT
)
1188 code
= LVA_ALIGNLEFT
;
1189 else if ( flag
== wxLIST_ALIGN_TOP
)
1190 code
= LVA_ALIGNTOP
;
1191 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
1193 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
1194 code
= LVA_SNAPTOGRID
;
1196 return (ListView_Arrange(GetHwnd(), code
) != 0);
1200 bool wxListCtrl::DeleteItem(long item
)
1202 if ( !ListView_DeleteItem(GetHwnd(), (int) item
) )
1204 wxLogLastError(_T("ListView_DeleteItem"));
1208 // the virtual list control doesn't refresh itself correctly, help it
1211 // we need to refresh all the lines below the one which was deleted
1213 if ( item
> 0 && GetItemCount() )
1215 GetItemRect(item
- 1, rectItem
);
1220 rectItem
.height
= 0;
1223 wxRect rectWin
= GetRect();
1224 rectWin
.height
= rectWin
.GetBottom() - rectItem
.GetBottom();
1225 rectWin
.y
= rectItem
.GetBottom();
1227 RefreshRect(rectWin
);
1233 // Deletes all items
1234 bool wxListCtrl::DeleteAllItems()
1236 return ListView_DeleteAllItems(GetHwnd()) != 0;
1239 // Deletes all items
1240 bool wxListCtrl::DeleteAllColumns()
1242 while ( m_colCount
> 0 )
1244 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
1246 wxLogLastError(wxT("ListView_DeleteColumn"));
1254 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1260 bool wxListCtrl::DeleteColumn(int col
)
1262 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1264 if ( success
&& (m_colCount
> 0) )
1269 // Clears items, and columns if there are any.
1270 void wxListCtrl::ClearAll()
1273 if ( m_colCount
> 0 )
1277 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1279 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1281 // ListView_EditLabel requires that the list has focus.
1284 WXHWND hWnd
= (WXHWND
) ListView_EditLabel(GetHwnd(), item
);
1287 // failed to start editing
1291 // [re]create the text control wrapping the HWND we got
1294 m_textCtrl
->SetHWND(0);
1295 m_textCtrl
->UnsubclassWin();
1299 m_textCtrl
= (wxTextCtrl
*)textControlClass
->CreateObject();
1300 m_textCtrl
->SetHWND(hWnd
);
1301 m_textCtrl
->SubclassWin(hWnd
);
1302 m_textCtrl
->SetParent(this);
1304 // we must disallow TABbing away from the control while the edit contol is
1305 // shown because this leaves it in some strange state (just try removing
1306 // this line and then pressing TAB while editing an item in listctrl
1308 m_textCtrl
->SetWindowStyle(m_textCtrl
->GetWindowStyle() | wxTE_PROCESS_TAB
);
1313 // End label editing, optionally cancelling the edit
1314 bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel
))
1316 wxFAIL_MSG( _T("not implemented") );
1321 // Ensures this item is visible
1322 bool wxListCtrl::EnsureVisible(long item
)
1324 return ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0;
1327 // Find an item whose label matches this string, starting from the item after 'start'
1328 // or the beginning if 'start' is -1.
1329 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1331 LV_FINDINFO findInfo
;
1333 findInfo
.flags
= LVFI_STRING
;
1335 findInfo
.flags
|= LVFI_PARTIAL
;
1338 // ListView_FindItem() excludes the first item from search and to look
1339 // through all the items you need to start from -1 which is unnatural and
1340 // inconsistent with the generic version - so we adjust the index
1343 return ListView_FindItem(GetHwnd(), (int) start
, &findInfo
);
1346 // Find an item whose data matches this data, starting from the item after 'start'
1347 // or the beginning if 'start' is -1.
1348 // NOTE : Lindsay Mathieson - 14-July-2002
1349 // No longer use ListView_FindItem as the data attribute is now stored
1350 // in a wxListItemInternalData structure refernced by the actual lParam
1351 long wxListCtrl::FindItem(long start
, long data
)
1353 long idx
= start
+ 1;
1354 long count
= GetItemCount();
1358 if (GetItemData(idx
) == data
)
1366 // Find an item nearest this position in the specified direction, starting from
1367 // the item after 'start' or the beginning if 'start' is -1.
1368 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1370 LV_FINDINFO findInfo
;
1372 findInfo
.flags
= LVFI_NEARESTXY
;
1373 findInfo
.pt
.x
= pt
.x
;
1374 findInfo
.pt
.y
= pt
.y
;
1375 findInfo
.vkDirection
= VK_RIGHT
;
1377 if ( direction
== wxLIST_FIND_UP
)
1378 findInfo
.vkDirection
= VK_UP
;
1379 else if ( direction
== wxLIST_FIND_DOWN
)
1380 findInfo
.vkDirection
= VK_DOWN
;
1381 else if ( direction
== wxLIST_FIND_LEFT
)
1382 findInfo
.vkDirection
= VK_LEFT
;
1383 else if ( direction
== wxLIST_FIND_RIGHT
)
1384 findInfo
.vkDirection
= VK_RIGHT
;
1386 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1389 // Determines which item (if any) is at the specified point,
1390 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1391 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1393 LV_HITTESTINFO hitTestInfo
;
1394 hitTestInfo
.pt
.x
= (int) point
.x
;
1395 hitTestInfo
.pt
.y
= (int) point
.y
;
1397 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1400 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1401 flags
|= wxLIST_HITTEST_ABOVE
;
1402 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1403 flags
|= wxLIST_HITTEST_BELOW
;
1404 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1405 flags
|= wxLIST_HITTEST_NOWHERE
;
1406 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1407 flags
|= wxLIST_HITTEST_ONITEMICON
;
1408 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1409 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1410 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1411 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1412 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1413 flags
|= wxLIST_HITTEST_TOLEFT
;
1414 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1415 flags
|= wxLIST_HITTEST_TORIGHT
;
1417 return (long) hitTestInfo
.iItem
;
1420 // Inserts an item, returning the index of the new item if successful,
1422 long wxListCtrl::InsertItem(wxListItem
& info
)
1424 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1427 wxConvertToMSWListItem(this, info
, item
);
1428 item
.mask
&= ~LVIF_PARAM
;
1430 // check wether we need to allocate our internal data
1431 bool needInternalData
= ((info
.m_mask
& wxLIST_MASK_DATA
) || info
.HasAttributes());
1432 if (needInternalData
)
1434 m_AnyInternalData
= TRUE
;
1435 item
.mask
|= LVIF_PARAM
;
1437 // internal stucture that manages data
1438 wxListItemInternalData
*data
= new wxListItemInternalData();
1439 item
.lParam
= (LPARAM
) data
;
1441 if (info
.m_mask
& wxLIST_MASK_DATA
)
1442 data
->lParam
= info
.m_data
;
1444 // check whether it has any custom attributes
1445 if ( info
.HasAttributes() )
1447 // take copy of attributes
1448 data
->attr
= new wxListItemAttr(*info
.GetAttributes());
1453 return (long) ListView_InsertItem(GetHwnd(), & item
);
1456 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1459 info
.m_text
= label
;
1460 info
.m_mask
= wxLIST_MASK_TEXT
;
1461 info
.m_itemId
= index
;
1462 return InsertItem(info
);
1465 // Inserts an image item
1466 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1469 info
.m_image
= imageIndex
;
1470 info
.m_mask
= wxLIST_MASK_IMAGE
;
1471 info
.m_itemId
= index
;
1472 return InsertItem(info
);
1475 // Inserts an image/string item
1476 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1479 info
.m_image
= imageIndex
;
1480 info
.m_text
= label
;
1481 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1482 info
.m_itemId
= index
;
1483 return InsertItem(info
);
1486 // For list view mode (only), inserts a column.
1487 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1490 wxConvertToMSWListCol(col
, item
, lvCol
);
1492 if ( !(lvCol
.mask
& LVCF_WIDTH
) )
1494 // always give some width to the new column: this one is compatible
1495 // with the generic version
1496 lvCol
.mask
|= LVCF_WIDTH
;
1500 // when we insert a column which can contain an image, we must specify this
1501 // flag right now as doing it later in SetColumn() has no effect
1503 // we use LVCFMT_BITMAP_ON_RIGHT by default because without it there is no
1504 // way to dynamically set/clear the bitmap as the column without a bitmap
1505 // on the left looks ugly (there is a hole)
1507 // unfortunately with my version of comctl32.dll (5.80), the left column
1508 // image is always on the left and it seems that it's a "feature" - I
1509 // didn't find any way to work around it in any case
1510 if ( lvCol
.mask
& LVCF_IMAGE
)
1512 lvCol
.mask
|= LVCF_FMT
;
1513 lvCol
.fmt
|= LVCFMT_BITMAP_ON_RIGHT
;
1516 bool success
= ListView_InsertColumn(GetHwnd(), col
, &lvCol
) != -1;
1523 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1530 long wxListCtrl::InsertColumn(long col
,
1531 const wxString
& heading
,
1536 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1537 item
.m_text
= heading
;
1540 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1541 item
.m_width
= width
;
1543 item
.m_format
= format
;
1545 return InsertColumn(col
, item
);
1548 // scroll the control by the given number of pixels (exception: in list view,
1549 // dx is interpreted as number of columns)
1550 bool wxListCtrl::ScrollList(int dx
, int dy
)
1552 if ( !ListView_Scroll(GetHwnd(), dx
, dy
) )
1554 wxLogDebug(_T("ListView_Scroll(%d, %d) failed"), dx
, dy
);
1564 // fn is a function which takes 3 long arguments: item1, item2, data.
1565 // item1 is the long data associated with a first item (NOT the index).
1566 // item2 is the long data associated with a second item (NOT the index).
1567 // data is the same value as passed to SortItems.
1568 // The return value is a negative number if the first item should precede the second
1569 // item, a positive number of the second item should precede the first,
1570 // or zero if the two items are equivalent.
1572 // data is arbitrary data to be passed to the sort function.
1574 // Internal structures for proxying the user compare function
1575 // so that we can pass it the *real* user data
1577 // translate lParam data and call user func
1578 struct wxInternalDataSort
1580 wxListCtrlCompare user_fn
;
1584 int CALLBACK
wxInternalDataCompareFunc(LPARAM lParam1
, LPARAM lParam2
, LPARAM lParamSort
)
1586 struct wxInternalDataSort
*internalData
= (struct wxInternalDataSort
*) lParamSort
;
1588 wxListItemInternalData
*data1
= (wxListItemInternalData
*) lParam1
;
1589 wxListItemInternalData
*data2
= (wxListItemInternalData
*) lParam2
;
1591 long d1
= (data1
== NULL
? 0 : data1
->lParam
);
1592 long d2
= (data2
== NULL
? 0 : data2
->lParam
);
1594 return internalData
->user_fn(d1
, d2
, internalData
->data
);
1598 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1600 struct wxInternalDataSort internalData
;
1601 internalData
.user_fn
= fn
;
1602 internalData
.data
= data
;
1604 // WPARAM cast is needed for mingw/cygwin
1605 if ( !ListView_SortItems(GetHwnd(),
1606 wxInternalDataCompareFunc
,
1607 (WPARAM
) &internalData
) )
1609 wxLogDebug(_T("ListView_SortItems() failed"));
1619 // ----------------------------------------------------------------------------
1620 // message processing
1621 // ----------------------------------------------------------------------------
1623 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1625 if (cmd
== EN_UPDATE
)
1627 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1628 event
.SetEventObject( this );
1629 ProcessCommand(event
);
1632 else if (cmd
== EN_KILLFOCUS
)
1634 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1635 event
.SetEventObject( this );
1636 ProcessCommand(event
);
1643 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1645 // prepare the event
1646 // -----------------
1648 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1649 event
.SetEventObject(this);
1651 wxEventType eventType
= wxEVT_NULL
;
1653 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1655 // if your compiler is as broken as this, you should really change it: this
1656 // code is needed for normal operation! #ifdef below is only useful for
1657 // automatic rebuilds which are done with a very old compiler version
1658 #ifdef HDN_BEGINTRACKA
1660 // check for messages from the header (in report view)
1661 HWND hwndHdr
= ListView_GetHeader(GetHwnd());
1663 // is it a message from the header?
1664 if ( nmhdr
->hwndFrom
== hwndHdr
)
1666 HD_NOTIFY
*nmHDR
= (HD_NOTIFY
*)nmhdr
;
1668 event
.m_itemIndex
= -1;
1670 switch ( nmhdr
->code
)
1672 // yet another comctl32.dll bug: under NT/W2K it sends Unicode
1673 // TRACK messages even to ANSI programs: on my system I get
1674 // HDN_BEGINTRACKW and HDN_ENDTRACKA and no HDN_TRACK at all!
1676 // work around is to simply catch both versions and hope that it
1677 // works (why should this message exist in ANSI and Unicode is
1678 // beyond me as it doesn't deal with strings at all...)
1680 // note that fr HDN_TRACK another possibility could be to use
1681 // HDN_ITEMCHANGING but it is sent even after HDN_ENDTRACK and when
1682 // something other than the item width changes so we'd have to
1683 // filter out the unwanted events then
1684 case HDN_BEGINTRACKA
:
1685 case HDN_BEGINTRACKW
:
1686 eventType
= wxEVT_COMMAND_LIST_COL_BEGIN_DRAG
;
1691 if ( eventType
== wxEVT_NULL
)
1692 eventType
= wxEVT_COMMAND_LIST_COL_DRAGGING
;
1697 if ( eventType
== wxEVT_NULL
)
1698 eventType
= wxEVT_COMMAND_LIST_COL_END_DRAG
;
1700 event
.m_item
.m_width
= nmHDR
->pitem
->cxy
;
1701 event
.m_col
= nmHDR
->iItem
;
1706 eventType
= wxEVT_COMMAND_LIST_COL_RIGHT_CLICK
;
1709 // find the column clicked: we have to search for it
1710 // ourselves as the notification message doesn't provide
1713 // where did the click occur?
1715 if ( !::GetCursorPos(&ptClick
) )
1717 wxLogLastError(_T("GetCursorPos"));
1720 if ( !::ScreenToClient(hwndHdr
, &ptClick
) )
1722 wxLogLastError(_T("ScreenToClient(listctrl header)"));
1725 event
.m_pointDrag
.x
= ptClick
.x
;
1726 event
.m_pointDrag
.y
= ptClick
.y
;
1728 int colCount
= Header_GetItemCount(hwndHdr
);
1731 for ( int col
= 0; col
< colCount
; col
++ )
1733 if ( Header_GetItemRect(hwndHdr
, col
, &rect
) )
1735 if ( ::PtInRect(&rect
, ptClick
) )
1745 case HDN_GETDISPINFOW
:
1747 LPNMHDDISPINFOW info
= (LPNMHDDISPINFOW
) lParam
;
1748 // This is a fix for a strange bug under XP.
1749 // Normally, info->iItem is a valid index, but
1750 // sometimes this is a silly (large) number
1751 // and when we return FALSE via wxControl::MSWOnNotify
1752 // to indicate that it hasn't yet been processed,
1753 // there's a GPF in Windows.
1754 // By returning TRUE here, we avoid further processing
1755 // of this strange message.
1756 if (info
->iItem
> GetColumnCount())
1762 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1766 #endif // defined(HDN_BEGINTRACKA)
1767 if ( nmhdr
->hwndFrom
== GetHwnd() )
1769 // almost all messages use NM_LISTVIEW
1770 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1772 const int iItem
= nmLV
->iItem
;
1774 // set the data event field for all messages for which the system gives
1775 // us a valid NM_LISTVIEW::lParam
1776 switch ( nmLV
->hdr
.code
)
1779 case LVN_BEGINRDRAG
:
1780 case LVN_COLUMNCLICK
:
1781 case LVN_ITEMCHANGED
:
1782 case LVN_ITEMCHANGING
:
1785 wxListItemInternalData
*internaldata
=
1786 (wxListItemInternalData
*) nmLV
->lParam
;
1789 event
.m_item
.m_data
= internaldata
->lParam
;
1797 switch ( nmhdr
->code
)
1799 case LVN_BEGINRDRAG
:
1800 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1804 if ( eventType
== wxEVT_NULL
)
1806 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1809 event
.m_itemIndex
= iItem
;
1810 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1811 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1814 // NB: we have to handle both *A and *W versions here because some
1815 // versions of comctl32.dll send ANSI message to an Unicode app
1816 case LVN_BEGINLABELEDITA
:
1818 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1819 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1820 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1821 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1824 case LVN_BEGINLABELEDITW
:
1826 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1827 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1828 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, item
);
1829 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1833 case LVN_ENDLABELEDITA
:
1835 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1836 wxLV_ITEM
item(((LV_DISPINFOA
*)lParam
)->item
);
1837 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1838 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1839 ((LV_ITEM
)item
).iItem
== -1 )
1842 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1845 case LVN_ENDLABELEDITW
:
1847 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1848 wxLV_ITEM
item(((LV_DISPINFOW
*)lParam
)->item
);
1849 wxConvertFromMSWListItem(NULL
, event
.m_item
, item
);
1850 if ( ((LV_ITEM
)item
).pszText
== NULL
||
1851 ((LV_ITEM
)item
).iItem
== -1 )
1854 event
.m_itemIndex
= event
.m_item
.m_itemId
;
1858 case LVN_COLUMNCLICK
:
1859 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1860 event
.m_itemIndex
= -1;
1861 event
.m_col
= nmLV
->iSubItem
;
1864 case LVN_DELETEALLITEMS
:
1865 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1866 event
.m_itemIndex
= -1;
1869 case LVN_DELETEITEM
:
1870 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1871 event
.m_itemIndex
= iItem
;
1872 // delete the assoicated internal data
1873 wxDeleteInternalData(this, iItem
);
1876 case LVN_SETDISPINFO
:
1878 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1879 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1880 wxConvertFromMSWListItem(GetHwnd(), event
.m_item
, info
->item
);
1884 case LVN_INSERTITEM
:
1885 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1886 event
.m_itemIndex
= iItem
;
1889 case LVN_ITEMCHANGED
:
1890 // we translate this catch all message into more interesting
1891 // (and more easy to process) wxWindows events
1893 // first of all, we deal with the state change events only and
1894 // only for valid items (item == -1 for the virtual list
1896 if ( nmLV
->uChanged
& LVIF_STATE
&& iItem
!= -1 )
1898 // temp vars for readability
1899 const UINT stOld
= nmLV
->uOldState
;
1900 const UINT stNew
= nmLV
->uNewState
;
1902 event
.m_item
.SetId(iItem
);
1903 event
.m_item
.SetMask(wxLIST_MASK_TEXT
|
1906 GetItem(event
.m_item
);
1908 // has the focus changed?
1909 if ( !(stOld
& LVIS_FOCUSED
) && (stNew
& LVIS_FOCUSED
) )
1911 eventType
= wxEVT_COMMAND_LIST_ITEM_FOCUSED
;
1912 event
.m_itemIndex
= iItem
;
1915 if ( (stNew
& LVIS_SELECTED
) != (stOld
& LVIS_SELECTED
) )
1917 if ( eventType
!= wxEVT_NULL
)
1919 // focus and selection have both changed: send the
1920 // focus event from here and the selection one
1922 event
.SetEventType(eventType
);
1923 (void)GetEventHandler()->ProcessEvent(event
);
1925 else // no focus event to send
1927 // then need to set m_itemIndex as it wasn't done
1929 event
.m_itemIndex
= iItem
;
1932 eventType
= stNew
& LVIS_SELECTED
1933 ? wxEVT_COMMAND_LIST_ITEM_SELECTED
1934 : wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1938 if ( eventType
== wxEVT_NULL
)
1940 // not an interesting event for us
1948 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1949 WORD wVKey
= info
->wVKey
;
1951 // get the current selection
1952 long lItem
= GetNextItem(-1,
1954 wxLIST_STATE_SELECTED
);
1956 // <Enter> or <Space> activate the selected item if any (but
1957 // not with Shift and/or Ctrl as then they have a predefined
1958 // meaning for the list view)
1960 (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) &&
1961 !(wxIsShiftDown() || wxIsCtrlDown()) )
1963 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1967 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1969 // wxCharCodeMSWToWX() returns 0 if the key is an ASCII
1970 // value which should be used as is
1971 int code
= wxCharCodeMSWToWX(wVKey
);
1972 event
.m_code
= code
? code
: wVKey
;
1976 event
.m_item
.m_itemId
= lItem
;
1980 // fill the other fields too
1981 event
.m_item
.m_text
= GetItemText(lItem
);
1982 event
.m_item
.m_data
= GetItemData(lItem
);
1988 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1990 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1995 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1996 // if it happened on an item (and not on empty place)
2003 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
2004 event
.m_itemIndex
= iItem
;
2005 event
.m_item
.m_text
= GetItemText(iItem
);
2006 event
.m_item
.m_data
= GetItemData(iItem
);
2010 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
2011 // don't do anything else
2012 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
2017 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
2018 LV_HITTESTINFO lvhti
;
2019 wxZeroMemory(lvhti
);
2021 ::GetCursorPos(&(lvhti
.pt
));
2022 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
2023 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
2025 if ( lvhti
.flags
& LVHT_ONITEM
)
2027 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
2028 event
.m_itemIndex
= lvhti
.iItem
;
2029 event
.m_pointDrag
.x
= lvhti
.pt
.x
;
2030 event
.m_pointDrag
.y
= lvhti
.pt
.y
;
2035 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2036 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 0 ) )
2038 *result
= OnCustomDraw(lParam
);
2041 #endif // _WIN32_IE >= 0x300
2043 case LVN_ODCACHEHINT
:
2045 const NM_CACHEHINT
*cacheHint
= (NM_CACHEHINT
*)lParam
;
2047 eventType
= wxEVT_COMMAND_LIST_CACHE_HINT
;
2049 // we get some really stupid cache hints like ones for items in
2050 // range 0..0 for an empty control or, after deleting an item,
2051 // for items in invalid range - filter this garbage out
2052 if ( cacheHint
->iFrom
< cacheHint
->iTo
)
2054 event
.m_oldItemIndex
= cacheHint
->iFrom
;
2056 long iMax
= GetItemCount();
2057 event
.m_itemIndex
= cacheHint
->iTo
< iMax
? cacheHint
->iTo
2067 case LVN_GETDISPINFO
:
2070 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
2072 LV_ITEM
& lvi
= info
->item
;
2073 long item
= lvi
.iItem
;
2075 if ( lvi
.mask
& LVIF_TEXT
)
2077 wxString text
= OnGetItemText(item
, lvi
.iSubItem
);
2078 wxStrncpy(lvi
.pszText
, text
, lvi
.cchTextMax
);
2081 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2082 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2083 if ( lvi
.mask
& LVIF_IMAGE
)
2085 lvi
.iImage
= OnGetItemImage(item
);
2089 // a little dose of healthy paranoia: as we never use
2090 // LVM_SETCALLBACKMASK we're not supposed to get these ones
2091 wxASSERT_MSG( !(lvi
.mask
& LVIF_STATE
),
2092 _T("we don't support state callbacks yet!") );
2099 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
2104 // where did this one come from?
2108 // process the event
2109 // -----------------
2111 event
.SetEventType(eventType
);
2113 if ( !GetEventHandler()->ProcessEvent(event
) )
2119 switch ( nmhdr
->code
)
2121 case LVN_DELETEALLITEMS
:
2122 // always return TRUE to suppress all additional LVN_DELETEITEM
2123 // notifications - this makes deleting all items from a list ctrl
2129 case LVN_ENDLABELEDITA
:
2130 case LVN_ENDLABELEDITW
:
2131 // logic here is inversed compared to all the other messages
2132 *result
= event
.IsAllowed();
2134 // don't keep a stale wxTextCtrl around
2137 // EDIT control will be deleted by the list control itself so
2138 // prevent us from deleting it as well
2139 m_textCtrl
->SetHWND(0);
2140 m_textCtrl
->UnsubclassWin();
2148 *result
= !event
.IsAllowed();
2153 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
2155 WXLPARAM
wxListCtrl::OnCustomDraw(WXLPARAM lParam
)
2157 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
2158 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
2159 switch ( nmcd
.dwDrawStage
)
2162 // if we've got any items with non standard attributes,
2163 // notify us before painting each item
2165 // for virtual controls, always suppose that we have attributes as
2166 // there is no way to check for this
2167 return IsVirtual() || m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
2170 case CDDS_ITEMPREPAINT
:
2172 size_t item
= (size_t)nmcd
.dwItemSpec
;
2173 if ( item
>= (size_t)GetItemCount() )
2175 // we get this message with item == 0 for an empty control,
2176 // we must ignore it as calling OnGetItemAttr() would be
2178 return CDRF_DODEFAULT
;
2181 wxListItemAttr
*attr
=
2182 IsVirtual() ? OnGetItemAttr(item
)
2183 : wxGetInternalDataAttr(this, item
);
2187 // nothing to do for this item
2188 return CDRF_DODEFAULT
;
2192 wxColour colText
, colBack
;
2193 if ( attr
->HasFont() )
2195 wxFont font
= attr
->GetFont();
2196 hFont
= (HFONT
)font
.GetResourceHandle();
2203 if ( attr
->HasTextColour() )
2205 colText
= attr
->GetTextColour();
2209 colText
= GetTextColour();
2212 if ( attr
->HasBackgroundColour() )
2214 colBack
= attr
->GetBackgroundColour();
2218 colBack
= GetBackgroundColour();
2221 lplvcd
->clrText
= wxColourToRGB(colText
);
2222 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
2224 // note that if we wanted to set colours for
2225 // individual columns (subitems), we would have
2226 // returned CDRF_NOTIFYSUBITEMREDRAW from here
2229 ::SelectObject(nmcd
.hdc
, hFont
);
2231 return CDRF_NEWFONT
;
2234 // fall through to return CDRF_DODEFAULT
2237 return CDRF_DODEFAULT
;
2241 #endif // NM_CUSTOMDRAW supported
2243 // Necessary for drawing hrules and vrules, if specified
2244 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
2248 wxControl::OnPaint(event
);
2250 // Reset the device origin since it may have been set
2251 dc
.SetDeviceOrigin(0, 0);
2253 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
2254 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
2256 if (!drawHRules
&& !drawVRules
)
2258 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
2261 wxPen
pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
2263 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2265 wxSize clientSize
= GetClientSize();
2269 int itemCount
= GetItemCount();
2273 long top
= GetTopItem();
2274 for (i
= top
; i
< top
+ GetCountPerPage() + 1; i
++)
2276 if (GetItemRect(i
, itemRect
))
2278 cy
= itemRect
.GetTop();
2279 if (i
!= 0) // Don't draw the first one
2281 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2284 if (i
== itemCount
- 1)
2286 cy
= itemRect
.GetBottom();
2287 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
2293 if (drawVRules
&& (i
> -1))
2295 wxRect firstItemRect
;
2296 GetItemRect(0, firstItemRect
);
2298 if (GetItemRect(i
, itemRect
))
2301 int x
= itemRect
.GetX();
2302 for (col
= 0; col
< GetColumnCount(); col
++)
2304 int colWidth
= GetColumnWidth(col
);
2306 dc
.DrawLine(x
-1, firstItemRect
.GetY() - 2, x
-1, itemRect
.GetBottom());
2312 // ----------------------------------------------------------------------------
2313 // virtual list controls
2314 // ----------------------------------------------------------------------------
2316 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
2318 // this is a pure virtual function, in fact - which is not really pure
2319 // because the controls which are not virtual don't need to implement it
2320 wxFAIL_MSG( _T("not supposed to be called") );
2322 return wxEmptyString
;
2325 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
2328 wxFAIL_MSG( _T("not supposed to be called") );
2333 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
2335 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
2336 _T("invalid item index in OnGetItemAttr()") );
2338 // no attributes by default
2342 void wxListCtrl::SetItemCount(long count
)
2344 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
2346 if ( !::SendMessage(GetHwnd(), LVM_SETITEMCOUNT
, (WPARAM
)count
, 0) )
2348 wxLogLastError(_T("ListView_SetItemCount"));
2352 void wxListCtrl::RefreshItem(long item
)
2354 // strangely enough, ListView_Update() results in much more flicker here
2355 // than a dumb Refresh() -- why?
2357 if ( !ListView_Update(GetHwnd(), item
) )
2359 wxLogLastError(_T("ListView_Update"));
2363 GetItemRect(item
, rect
);
2368 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
2370 wxRect rect1
, rect2
;
2371 GetItemRect(itemFrom
, rect1
);
2372 GetItemRect(itemTo
, rect2
);
2374 wxRect rect
= rect1
;
2375 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
2380 static wxListItemInternalData
*wxGetInternalData(HWND hwnd
, long itemId
)
2383 it
.mask
= LVIF_PARAM
;
2386 bool success
= ListView_GetItem(hwnd
, &it
) != 0;
2388 return (wxListItemInternalData
*) it
.lParam
;
2393 static wxListItemInternalData
*wxGetInternalData(wxListCtrl
*ctl
, long itemId
)
2395 return wxGetInternalData((HWND
) ctl
->GetHWND(), itemId
);
2398 static wxListItemAttr
*wxGetInternalDataAttr(wxListCtrl
*ctl
, long itemId
)
2400 wxListItemInternalData
*data
= wxGetInternalData(ctl
, itemId
);
2407 static void wxDeleteInternalData(wxListCtrl
* ctl
, long itemId
)
2409 wxListItemInternalData
*data
= wxGetInternalData(ctl
, itemId
);
2414 memset(&item
, 0, sizeof(item
));
2415 item
.iItem
= itemId
;
2416 item
.mask
= LVIF_PARAM
;
2417 item
.lParam
= (LPARAM
) 0;
2418 ListView_SetItem((HWND
)ctl
->GetHWND(), &item
);
2422 static void wxConvertFromMSWListItem(HWND hwndListCtrl
,
2426 wxListItemInternalData
*internaldata
=
2427 (wxListItemInternalData
*) lvItem
.lParam
;
2430 info
.m_data
= internaldata
->lParam
;
2434 info
.m_stateMask
= 0;
2435 info
.m_itemId
= lvItem
.iItem
;
2437 long oldMask
= lvItem
.mask
;
2439 bool needText
= FALSE
;
2440 if (hwndListCtrl
!= 0)
2442 if ( lvItem
.mask
& LVIF_TEXT
)
2449 lvItem
.pszText
= new wxChar
[513];
2450 lvItem
.cchTextMax
= 512;
2452 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
2453 ::SendMessage(hwndListCtrl
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
2456 if ( lvItem
.mask
& LVIF_STATE
)
2458 info
.m_mask
|= wxLIST_MASK_STATE
;
2460 if ( lvItem
.stateMask
& LVIS_CUT
)
2462 info
.m_stateMask
|= wxLIST_STATE_CUT
;
2463 if ( lvItem
.state
& LVIS_CUT
)
2464 info
.m_state
|= wxLIST_STATE_CUT
;
2466 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
2468 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
2469 if ( lvItem
.state
& LVIS_DROPHILITED
)
2470 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
2472 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
2474 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
2475 if ( lvItem
.state
& LVIS_FOCUSED
)
2476 info
.m_state
|= wxLIST_STATE_FOCUSED
;
2478 if ( lvItem
.stateMask
& LVIS_SELECTED
)
2480 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
2481 if ( lvItem
.state
& LVIS_SELECTED
)
2482 info
.m_state
|= wxLIST_STATE_SELECTED
;
2486 if ( lvItem
.mask
& LVIF_TEXT
)
2488 info
.m_mask
|= wxLIST_MASK_TEXT
;
2489 info
.m_text
= lvItem
.pszText
;
2491 if ( lvItem
.mask
& LVIF_IMAGE
)
2493 info
.m_mask
|= wxLIST_MASK_IMAGE
;
2494 info
.m_image
= lvItem
.iImage
;
2496 if ( lvItem
.mask
& LVIF_PARAM
)
2497 info
.m_mask
|= wxLIST_MASK_DATA
;
2498 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
2499 info
.m_mask
|= wxLIST_SET_ITEM
;
2500 info
.m_col
= lvItem
.iSubItem
;
2505 delete[] lvItem
.pszText
;
2507 lvItem
.mask
= oldMask
;
2510 static void wxConvertToMSWFlags(long state
, long stateMask
, LV_ITEM
& lvItem
)
2512 if (stateMask
& wxLIST_STATE_CUT
)
2514 lvItem
.stateMask
|= LVIS_CUT
;
2515 if (state
& wxLIST_STATE_CUT
)
2516 lvItem
.state
|= LVIS_CUT
;
2518 if (stateMask
& wxLIST_STATE_DROPHILITED
)
2520 lvItem
.stateMask
|= LVIS_DROPHILITED
;
2521 if (state
& wxLIST_STATE_DROPHILITED
)
2522 lvItem
.state
|= LVIS_DROPHILITED
;
2524 if (stateMask
& wxLIST_STATE_FOCUSED
)
2526 lvItem
.stateMask
|= LVIS_FOCUSED
;
2527 if (state
& wxLIST_STATE_FOCUSED
)
2528 lvItem
.state
|= LVIS_FOCUSED
;
2530 if (stateMask
& wxLIST_STATE_SELECTED
)
2532 lvItem
.stateMask
|= LVIS_SELECTED
;
2533 if (state
& wxLIST_STATE_SELECTED
)
2534 lvItem
.state
|= LVIS_SELECTED
;
2538 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
,
2539 const wxListItem
& info
,
2542 lvItem
.iItem
= (int) info
.m_itemId
;
2544 lvItem
.iImage
= info
.m_image
;
2545 lvItem
.stateMask
= 0;
2548 lvItem
.iSubItem
= info
.m_col
;
2550 if (info
.m_mask
& wxLIST_MASK_STATE
)
2552 lvItem
.mask
|= LVIF_STATE
;
2554 wxConvertToMSWFlags(info
.m_state
, info
.m_stateMask
, lvItem
);
2557 if (info
.m_mask
& wxLIST_MASK_TEXT
)
2559 lvItem
.mask
|= LVIF_TEXT
;
2560 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
2562 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
2566 // pszText is not const, hence the cast
2567 lvItem
.pszText
= (wxChar
*)info
.m_text
.c_str();
2568 if ( lvItem
.pszText
)
2569 lvItem
.cchTextMax
= info
.m_text
.Length();
2571 lvItem
.cchTextMax
= 0;
2574 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
2575 lvItem
.mask
|= LVIF_IMAGE
;
2578 static void wxConvertToMSWListCol(int WXUNUSED(col
), const wxListItem
& item
,
2581 wxZeroMemory(lvCol
);
2583 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
2585 lvCol
.mask
|= LVCF_TEXT
;
2586 lvCol
.pszText
= (wxChar
*)item
.m_text
.c_str(); // cast is safe
2589 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
2591 lvCol
.mask
|= LVCF_FMT
;
2593 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
2594 lvCol
.fmt
= LVCFMT_LEFT
;
2595 else if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
2596 lvCol
.fmt
= LVCFMT_RIGHT
;
2597 else if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
2598 lvCol
.fmt
= LVCFMT_CENTER
;
2601 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
2603 lvCol
.mask
|= LVCF_WIDTH
;
2604 if ( item
.m_width
== wxLIST_AUTOSIZE
)
2605 lvCol
.cx
= LVSCW_AUTOSIZE
;
2606 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
2607 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
2609 lvCol
.cx
= item
.m_width
;
2612 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300 \
2613 && !( defined(__GNUWIN32__) && !wxCHECK_W32API_VERSION( 1, 1 ) )
2614 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
2616 if ( wxTheApp
->GetComCtl32Version() >= 470 )
2618 lvCol
.mask
|= LVCF_IMAGE
;
2619 lvCol
.iImage
= item
.m_image
;
2621 //else: it doesn't support item images anyhow
2626 #endif // wxUSE_LISTCTRL