1 /////////////////////////////////////////////////////////////////////////////
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"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/listctrl.h"
40 #include "wx/msw/private.h"
42 #if defined(__GNUWIN32__) && !defined(wxUSE_NORLANDER_HEADERS)
43 #include "wx/msw/gnuwin32/extra.h"
50 (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& tvItem
);
58 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& tvItem
, HWND getFullInfo
= 0);
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
65 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
67 // ============================================================================
69 // ============================================================================
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 void wxListEvent::CopyObject(wxObject
& object_dest
) const
77 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
79 wxNotifyEvent::CopyObject(object_dest
);
82 obj
->m_itemIndex
= m_itemIndex
;
83 obj
->m_oldItemIndex
= m_oldItemIndex
;
85 obj
->m_cancelled
= m_cancelled
;
86 obj
->m_pointDrag
= m_pointDrag
;
87 obj
->m_item
.m_mask
= m_item
.m_mask
;
88 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
89 obj
->m_item
.m_col
= m_item
.m_col
;
90 obj
->m_item
.m_state
= m_item
.m_state
;
91 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
92 obj
->m_item
.m_text
= m_item
.m_text
;
93 obj
->m_item
.m_image
= m_item
.m_image
;
94 obj
->m_item
.m_data
= m_item
.m_data
;
95 obj
->m_item
.m_format
= m_item
.m_format
;
96 obj
->m_item
.m_width
= m_item
.m_width
;
98 if ( m_item
.HasAttributes() )
100 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
101 obj
->m_item
.SetBackgroundColour(m_item
.GetBackgroundColour());
102 obj
->m_item
.SetFont(m_item
.GetFont());
106 // ----------------------------------------------------------------------------
107 // wxListCtrl construction
108 // ----------------------------------------------------------------------------
110 void wxListCtrl::Init()
112 m_imageListNormal
= NULL
;
113 m_imageListSmall
= NULL
;
114 m_imageListState
= NULL
;
118 m_hasAnyAttr
= FALSE
;
121 bool wxListCtrl::Create(wxWindow
*parent
,
126 const wxValidator
& validator
,
127 const wxString
& name
)
130 SetValidator(validator
);
131 #endif // wxUSE_VALIDATORS
140 m_windowStyle
= style
;
153 m_windowId
= (id
== -1) ? NewControlId() : id
;
155 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
156 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
157 if ( wxStyleHasBorder(m_windowStyle
) )
159 m_baseStyle
= wstyle
;
161 if ( !DoCreateControl(x
, y
, width
, height
) )
165 parent
->AddChild(this);
170 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
172 DWORD wstyle
= m_baseStyle
;
175 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
177 // Even with extended styles, need to combine with WS_BORDER
178 // for them to look right.
182 long oldStyle
= 0; // Dummy
183 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
185 // Create the ListView control.
186 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
191 GetWinHwnd(GetParent()),
198 wxLogError(wxT("Can't create list control window."));
203 // for comctl32.dll v 4.70+ we want to have this attribute because it's
204 // prettier (and also because wxGTK does it like this)
205 #ifdef ListView_SetExtendedListViewStyle
206 if ( wstyle
& LVS_REPORT
)
208 ListView_SetExtendedListViewStyle(GetHwnd(),
209 LVS_EX_FULLROWSELECT
);
211 #endif // ListView_SetExtendedListViewStyle
213 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
214 SetForegroundColour(GetParent()->GetForegroundColour());
221 void wxListCtrl::UpdateStyle()
225 // The new window view style
227 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
228 dwStyleNew
|= m_baseStyle
;
230 // Get the current window style.
231 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
233 // Only set the window style if the view bits have changed.
234 if ( dwStyleOld
!= dwStyleNew
)
236 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
241 wxListCtrl::~wxListCtrl()
245 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
247 delete (wxListItemAttr
*)node
->Data();
253 m_textCtrl
->UnsubclassWin();
254 m_textCtrl
->SetHWND(0);
260 // ----------------------------------------------------------------------------
261 // set/get/change style
262 // ----------------------------------------------------------------------------
264 // Add or remove a single window style
265 void wxListCtrl::SetSingleStyle(long style
, bool add
)
267 long flag
= GetWindowStyleFlag();
269 // Get rid of conflicting styles
272 if ( style
& wxLC_MASK_TYPE
)
273 flag
= flag
& ~wxLC_MASK_TYPE
;
274 if ( style
& wxLC_MASK_ALIGN
)
275 flag
= flag
& ~wxLC_MASK_ALIGN
;
276 if ( style
& wxLC_MASK_SORT
)
277 flag
= flag
& ~wxLC_MASK_SORT
;
293 m_windowStyle
= flag
;
298 // Set the whole window style
299 void wxListCtrl::SetWindowStyleFlag(long flag
)
301 m_windowStyle
= flag
;
306 // Can be just a single style, or a bitlist
307 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
310 if ( style
& wxLC_ICON
)
312 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
313 oldStyle
-= LVS_SMALLICON
;
314 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
315 oldStyle
-= LVS_REPORT
;
316 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
317 oldStyle
-= LVS_LIST
;
321 if ( style
& wxLC_SMALL_ICON
)
323 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
324 oldStyle
-= LVS_ICON
;
325 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
326 oldStyle
-= LVS_REPORT
;
327 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
328 oldStyle
-= LVS_LIST
;
329 wstyle
|= LVS_SMALLICON
;
332 if ( style
& wxLC_LIST
)
334 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
335 oldStyle
-= LVS_ICON
;
336 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
337 oldStyle
-= LVS_REPORT
;
338 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
339 oldStyle
-= LVS_SMALLICON
;
343 if ( style
& wxLC_REPORT
)
345 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
346 oldStyle
-= LVS_ICON
;
347 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
348 oldStyle
-= LVS_LIST
;
349 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
350 oldStyle
-= LVS_SMALLICON
;
352 wstyle
|= LVS_REPORT
;
355 if ( style
& wxLC_ALIGN_LEFT
)
357 if ( oldStyle
& LVS_ALIGNTOP
)
358 oldStyle
-= LVS_ALIGNTOP
;
359 wstyle
|= LVS_ALIGNLEFT
;
362 if ( style
& wxLC_ALIGN_TOP
)
364 if ( oldStyle
& LVS_ALIGNLEFT
)
365 oldStyle
-= LVS_ALIGNLEFT
;
366 wstyle
|= LVS_ALIGNTOP
;
369 if ( style
& wxLC_AUTOARRANGE
)
370 wstyle
|= LVS_AUTOARRANGE
;
372 // Apparently, no such style (documentation wrong?)
374 if ( style & wxLC_BUTTON )
375 wstyle |= LVS_BUTTON;
378 if ( style
& wxLC_NO_SORT_HEADER
)
379 wstyle
|= LVS_NOSORTHEADER
;
381 if ( style
& wxLC_NO_HEADER
)
382 wstyle
|= LVS_NOCOLUMNHEADER
;
384 if ( style
& wxLC_EDIT_LABELS
)
385 wstyle
|= LVS_EDITLABELS
;
387 if ( style
& wxLC_SINGLE_SEL
)
388 wstyle
|= LVS_SINGLESEL
;
390 if ( style
& wxLC_SORT_ASCENDING
)
392 if ( oldStyle
& LVS_SORTDESCENDING
)
393 oldStyle
-= LVS_SORTDESCENDING
;
394 wstyle
|= LVS_SORTASCENDING
;
397 if ( style
& wxLC_SORT_DESCENDING
)
399 if ( oldStyle
& LVS_SORTASCENDING
)
400 oldStyle
-= LVS_SORTASCENDING
;
401 wstyle
|= LVS_SORTDESCENDING
;
407 // ----------------------------------------------------------------------------
409 // ----------------------------------------------------------------------------
411 // Sets the background colour (GetBackgroundColour already implicit in
413 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
415 if ( !wxWindow::SetBackgroundColour(col
) )
418 ListView_SetBkColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
423 // Gets information about this column
424 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
429 lvCol
.pszText
= NULL
;
431 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
433 lvCol
.mask
|= LVCF_TEXT
;
434 lvCol
.pszText
= new wxChar
[513];
435 lvCol
.cchTextMax
= 512;
438 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
440 // item.m_subItem = lvCol.iSubItem;
441 item
.m_width
= lvCol
.cx
;
443 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
445 item
.m_text
= lvCol
.pszText
;
446 delete[] lvCol
.pszText
;
449 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
451 if (lvCol
.fmt
== LVCFMT_LEFT
)
452 item
.m_format
= wxLIST_FORMAT_LEFT
;
453 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
454 item
.m_format
= wxLIST_FORMAT_RIGHT
;
455 else if (lvCol
.fmt
== LVCFMT_CENTER
)
456 item
.m_format
= wxLIST_FORMAT_CENTRE
;
462 // Sets information about this column
463 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
468 lvCol
.pszText
= NULL
;
470 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
472 lvCol
.mask
|= LVCF_TEXT
;
473 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
474 lvCol
.cchTextMax
= 0; // Ignored
476 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
478 lvCol
.mask
|= LVCF_FMT
;
480 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
481 lvCol
.fmt
= LVCFMT_LEFT
;
482 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
483 lvCol
.fmt
= LVCFMT_RIGHT
;
484 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
485 lvCol
.fmt
= LVCFMT_CENTER
;
488 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
490 lvCol
.mask
|= LVCF_WIDTH
;
491 lvCol
.cx
= item
.m_width
;
493 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
494 lvCol
.cx
= LVSCW_AUTOSIZE
;
495 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
496 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
498 lvCol
.mask
|= LVCF_SUBITEM
;
499 lvCol
.iSubItem
= col
;
500 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
503 // Gets the column width
504 int wxListCtrl::GetColumnWidth(int col
) const
506 return ListView_GetColumnWidth(GetHwnd(), col
);
509 // Sets the column width
510 bool wxListCtrl::SetColumnWidth(int col
, int width
)
513 if ( m_windowStyle
& wxLC_LIST
)
517 if ( width2
== wxLIST_AUTOSIZE
)
518 width2
= LVSCW_AUTOSIZE
;
519 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
520 width2
= LVSCW_AUTOSIZE_USEHEADER
;
522 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
525 // Gets the number of items that can fit vertically in the
526 // visible area of the list control (list or report view)
527 // or the total number of items in the list control (icon
528 // or small icon view)
529 int wxListCtrl::GetCountPerPage(void) const
531 return ListView_GetCountPerPage(GetHwnd());
534 // Gets the edit control for editing labels.
535 wxTextCtrl
* wxListCtrl::GetEditControl(void) const
540 // Gets information about the item
541 bool wxListCtrl::GetItem(wxListItem
& info
) const
544 wxZeroMemory(lvItem
);
546 lvItem
.iItem
= info
.m_itemId
;
547 lvItem
.iSubItem
= info
.m_col
;
549 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
551 lvItem
.mask
|= LVIF_TEXT
;
552 lvItem
.pszText
= new wxChar
[513];
553 lvItem
.cchTextMax
= 512;
557 lvItem
.pszText
= NULL
;
560 if (info
.m_mask
& wxLIST_MASK_DATA
)
561 lvItem
.mask
|= LVIF_PARAM
;
563 if ( info
.m_mask
& wxLIST_MASK_STATE
)
565 lvItem
.mask
|= LVIF_STATE
;
566 // the other bits are hardly interesting anyhow
567 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
570 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
573 wxLogError(_("Couldn't retrieve information about list control item %d."),
578 wxConvertFromMSWListItem(this, info
, lvItem
);
582 delete[] lvItem
.pszText
;
587 // Sets information about the item
588 bool wxListCtrl::SetItem(wxListItem
& info
)
591 wxConvertToMSWListItem(this, info
, item
);
593 // check whether it has any custom attributes
594 if ( info
.HasAttributes() )
596 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
602 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
603 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
605 // make the change visible
606 ListView_Update(GetHwnd(), item
.iItem
);
612 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
616 info
.m_mask
= wxLIST_MASK_TEXT
;
617 info
.m_itemId
= index
;
621 info
.m_image
= imageId
;
622 info
.m_mask
|= wxLIST_MASK_IMAGE
;
624 return SetItem(info
);
628 // Gets the item state
629 int wxListCtrl::GetItemState(long item
, long stateMask
) const
633 info
.m_mask
= wxLIST_MASK_STATE
;
634 info
.m_stateMask
= stateMask
;
635 info
.m_itemId
= item
;
643 // Sets the item state
644 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
648 info
.m_mask
= wxLIST_MASK_STATE
;
649 info
.m_state
= state
;
650 info
.m_stateMask
= stateMask
;
651 info
.m_itemId
= item
;
653 return SetItem(info
);
656 // Sets the item image
657 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
661 info
.m_mask
= wxLIST_MASK_IMAGE
;
662 info
.m_image
= image
;
663 info
.m_itemId
= item
;
665 return SetItem(info
);
668 // Gets the item text
669 wxString
wxListCtrl::GetItemText(long item
) const
673 info
.m_mask
= wxLIST_MASK_TEXT
;
674 info
.m_itemId
= item
;
681 // Sets the item text
682 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
686 info
.m_mask
= wxLIST_MASK_TEXT
;
687 info
.m_itemId
= item
;
693 // Gets the item data
694 long wxListCtrl::GetItemData(long item
) const
698 info
.m_mask
= wxLIST_MASK_DATA
;
699 info
.m_itemId
= item
;
706 // Sets the item data
707 bool wxListCtrl::SetItemData(long item
, long data
)
711 info
.m_mask
= wxLIST_MASK_DATA
;
712 info
.m_itemId
= item
;
715 return SetItem(info
);
718 // Gets the item rectangle
719 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
723 int code2
= LVIR_BOUNDS
;
724 if ( code
== wxLIST_RECT_BOUNDS
)
726 else if ( code
== wxLIST_RECT_ICON
)
728 else if ( code
== wxLIST_RECT_LABEL
)
732 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
734 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
739 rect
.width
= rect2
.right
- rect2
.left
;
740 rect
.height
= rect2
.bottom
- rect2
.left
;
744 // Gets the item position
745 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
749 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
751 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
755 // Sets the item position.
756 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
758 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
761 // Gets the number of items in the list control
762 int wxListCtrl::GetItemCount(void) const
764 return ListView_GetItemCount(GetHwnd());
767 // Retrieves the spacing between icons in pixels.
768 // If small is TRUE, gets the spacing for the small icon
769 // view, otherwise the large icon view.
770 int wxListCtrl::GetItemSpacing(bool isSmall
) const
772 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
775 // Gets the number of selected items in the list control
776 int wxListCtrl::GetSelectedItemCount(void) const
778 return ListView_GetSelectedCount(GetHwnd());
781 // Gets the text colour of the listview
782 wxColour
wxListCtrl::GetTextColour(void) const
784 COLORREF ref
= ListView_GetTextColor(GetHwnd());
785 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
789 // Sets the text colour of the listview
790 void wxListCtrl::SetTextColour(const wxColour
& col
)
792 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
795 // Gets the index of the topmost visible item when in
796 // list or report view
797 long wxListCtrl::GetTopItem(void) const
799 return (long) ListView_GetTopIndex(GetHwnd());
802 // Searches for an item, starting from 'item'.
803 // 'geometry' is one of
804 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
805 // 'state' is a state bit flag, one or more of
806 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
807 // item can be -1 to find the first item that matches the
809 // Returns the item or -1 if unsuccessful.
810 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
814 if ( geom
== wxLIST_NEXT_ABOVE
)
816 if ( geom
== wxLIST_NEXT_ALL
)
818 if ( geom
== wxLIST_NEXT_BELOW
)
820 if ( geom
== wxLIST_NEXT_LEFT
)
821 flags
|= LVNI_TOLEFT
;
822 if ( geom
== wxLIST_NEXT_RIGHT
)
823 flags
|= LVNI_TORIGHT
;
825 if ( state
& wxLIST_STATE_CUT
)
827 if ( state
& wxLIST_STATE_DROPHILITED
)
828 flags
|= LVNI_DROPHILITED
;
829 if ( state
& wxLIST_STATE_FOCUSED
)
830 flags
|= LVNI_FOCUSED
;
831 if ( state
& wxLIST_STATE_SELECTED
)
832 flags
|= LVNI_SELECTED
;
834 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
838 wxImageList
*wxListCtrl::GetImageList(int which
) const
840 if ( which
== wxIMAGE_LIST_NORMAL
)
842 return m_imageListNormal
;
844 else if ( which
== wxIMAGE_LIST_SMALL
)
846 return m_imageListSmall
;
848 else if ( which
== wxIMAGE_LIST_STATE
)
850 return m_imageListState
;
855 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
858 if ( which
== wxIMAGE_LIST_NORMAL
)
860 flags
= LVSIL_NORMAL
;
861 m_imageListNormal
= imageList
;
863 else if ( which
== wxIMAGE_LIST_SMALL
)
866 m_imageListSmall
= imageList
;
868 else if ( which
== wxIMAGE_LIST_STATE
)
871 m_imageListState
= imageList
;
873 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
876 // ----------------------------------------------------------------------------
878 // ----------------------------------------------------------------------------
880 // Arranges the items
881 bool wxListCtrl::Arrange(int flag
)
884 if ( flag
== wxLIST_ALIGN_LEFT
)
885 code
= LVA_ALIGNLEFT
;
886 else if ( flag
== wxLIST_ALIGN_TOP
)
888 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
890 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
891 code
= LVA_SNAPTOGRID
;
893 return (ListView_Arrange(GetHwnd(), code
) != 0);
897 bool wxListCtrl::DeleteItem(long item
)
899 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
903 bool wxListCtrl::DeleteAllItems()
905 return (ListView_DeleteAllItems(GetHwnd()) != 0);
909 bool wxListCtrl::DeleteAllColumns()
911 while ( m_colCount
> 0 )
913 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
915 wxLogLastError("ListView_DeleteColumn");
923 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
929 bool wxListCtrl::DeleteColumn(int col
)
931 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
933 if ( success
&& (m_colCount
> 0) )
938 // Clears items, and columns if there are any.
939 void wxListCtrl::ClearAll()
942 if ( m_colCount
> 0 )
946 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
948 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
950 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
954 m_textCtrl
->UnsubclassWin();
955 m_textCtrl
->SetHWND(0);
960 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
961 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
962 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
967 // End label editing, optionally cancelling the edit
968 bool wxListCtrl::EndEditLabel(bool cancel
)
972 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
974 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
978 m_textCtrl->UnsubclassWin();
979 m_textCtrl->SetHWND(0);
989 // Ensures this item is visible
990 bool wxListCtrl::EnsureVisible(long item
)
992 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
995 // Find an item whose label matches this string, starting from the item after 'start'
996 // or the beginning if 'start' is -1.
997 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
999 LV_FINDINFO findInfo
;
1001 findInfo
.flags
= LVFI_STRING
;
1003 findInfo
.flags
|= LVFI_STRING
;
1004 findInfo
.psz
= WXSTRINGCAST str
;
1006 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1009 // Find an item whose data matches this data, starting from the item after 'start'
1010 // or the beginning if 'start' is -1.
1011 long wxListCtrl::FindItem(long start
, long data
)
1013 LV_FINDINFO findInfo
;
1015 findInfo
.flags
= LVFI_PARAM
;
1016 findInfo
.lParam
= data
;
1018 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1021 // Find an item nearest this position in the specified direction, starting from
1022 // the item after 'start' or the beginning if 'start' is -1.
1023 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1025 LV_FINDINFO findInfo
;
1027 findInfo
.flags
= LVFI_NEARESTXY
;
1028 findInfo
.pt
.x
= pt
.x
;
1029 findInfo
.pt
.y
= pt
.y
;
1030 findInfo
.vkDirection
= VK_RIGHT
;
1032 if ( direction
== wxLIST_FIND_UP
)
1033 findInfo
.vkDirection
= VK_UP
;
1034 else if ( direction
== wxLIST_FIND_DOWN
)
1035 findInfo
.vkDirection
= VK_DOWN
;
1036 else if ( direction
== wxLIST_FIND_LEFT
)
1037 findInfo
.vkDirection
= VK_LEFT
;
1038 else if ( direction
== wxLIST_FIND_RIGHT
)
1039 findInfo
.vkDirection
= VK_RIGHT
;
1041 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1044 // Determines which item (if any) is at the specified point,
1045 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1046 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1048 LV_HITTESTINFO hitTestInfo
;
1049 hitTestInfo
.pt
.x
= (int) point
.x
;
1050 hitTestInfo
.pt
.y
= (int) point
.y
;
1052 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1055 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1056 flags
|= wxLIST_HITTEST_ABOVE
;
1057 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1058 flags
|= wxLIST_HITTEST_BELOW
;
1059 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1060 flags
|= wxLIST_HITTEST_NOWHERE
;
1061 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1062 flags
|= wxLIST_HITTEST_ONITEMICON
;
1063 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1064 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1065 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1066 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1067 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1068 flags
|= wxLIST_HITTEST_TOLEFT
;
1069 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1070 flags
|= wxLIST_HITTEST_TORIGHT
;
1072 return (long) hitTestInfo
.iItem
;
1075 // Inserts an item, returning the index of the new item if successful,
1077 long wxListCtrl::InsertItem(wxListItem
& info
)
1080 wxConvertToMSWListItem(this, info
, item
);
1082 // check whether it has any custom attributes
1083 if ( info
.HasAttributes() )
1085 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1087 m_hasAnyAttr
= TRUE
;
1090 return (long) ListView_InsertItem(GetHwnd(), & item
);
1093 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1096 info
.m_text
= label
;
1097 info
.m_mask
= wxLIST_MASK_TEXT
;
1098 info
.m_itemId
= index
;
1099 return InsertItem(info
);
1102 // Inserts an image item
1103 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1106 info
.m_image
= imageIndex
;
1107 info
.m_mask
= wxLIST_MASK_IMAGE
;
1108 info
.m_itemId
= index
;
1109 return InsertItem(info
);
1112 // Inserts an image/string item
1113 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1116 info
.m_image
= imageIndex
;
1117 info
.m_text
= label
;
1118 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1119 info
.m_itemId
= index
;
1120 return InsertItem(info
);
1123 // For list view mode (only), inserts a column.
1124 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1129 lvCol
.pszText
= NULL
;
1131 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1133 lvCol
.mask
|= LVCF_TEXT
;
1134 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1135 lvCol
.cchTextMax
= 0; // Ignored
1137 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1139 lvCol
.mask
|= LVCF_FMT
;
1141 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1142 lvCol
.fmt
= LVCFMT_LEFT
;
1143 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1144 lvCol
.fmt
= LVCFMT_RIGHT
;
1145 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1146 lvCol
.fmt
= LVCFMT_CENTER
;
1149 lvCol
.mask
|= LVCF_WIDTH
;
1150 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1152 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1153 lvCol
.cx
= LVSCW_AUTOSIZE
;
1154 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1155 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1157 lvCol
.cx
= item
.m_width
;
1161 // always give some width to the new column: this one is compatible
1166 lvCol
.mask
|= LVCF_SUBITEM
;
1167 lvCol
.iSubItem
= col
;
1169 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1176 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1183 long wxListCtrl::InsertColumn(long col
,
1184 const wxString
& heading
,
1189 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1190 item
.m_text
= heading
;
1193 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1194 item
.m_width
= width
;
1196 item
.m_format
= format
;
1198 return InsertColumn(col
, item
);
1201 // Scrolls the list control. If in icon, small icon or report view mode,
1202 // x specifies the number of pixels to scroll. If in list view mode, x
1203 // specifies the number of columns to scroll.
1204 // If in icon, small icon or list view mode, y specifies the number of pixels
1205 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1206 bool wxListCtrl::ScrollList(int dx
, int dy
)
1208 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1213 // fn is a function which takes 3 long arguments: item1, item2, data.
1214 // item1 is the long data associated with a first item (NOT the index).
1215 // item2 is the long data associated with a second item (NOT the index).
1216 // data is the same value as passed to SortItems.
1217 // The return value is a negative number if the first item should precede the second
1218 // item, a positive number of the second item should precede the first,
1219 // or zero if the two items are equivalent.
1221 // data is arbitrary data to be passed to the sort function.
1222 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1224 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1227 // ----------------------------------------------------------------------------
1228 // message processing
1229 // ----------------------------------------------------------------------------
1231 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1233 if (cmd
== EN_UPDATE
)
1235 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1236 event
.SetEventObject( this );
1237 ProcessCommand(event
);
1240 else if (cmd
== EN_KILLFOCUS
)
1242 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1243 event
.SetEventObject( this );
1244 ProcessCommand(event
);
1251 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1253 // prepare the event
1254 // -----------------
1256 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1257 wxEventType eventType
= wxEVT_NULL
;
1258 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1259 switch ( nmhdr
->code
)
1261 case LVN_BEGINRDRAG
:
1262 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1266 if ( eventType
== wxEVT_NULL
)
1268 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1272 NM_LISTVIEW
*hdr
= (NM_LISTVIEW
*)lParam
;
1273 event
.m_itemIndex
= hdr
->iItem
;
1274 event
.m_pointDrag
.x
= hdr
->ptAction
.x
;
1275 event
.m_pointDrag
.y
= hdr
->ptAction
.y
;
1279 case LVN_BEGINLABELEDIT
:
1281 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1282 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1283 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1287 case LVN_COLUMNCLICK
:
1289 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1290 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1291 event
.m_itemIndex
= -1;
1292 event
.m_col
= hdr
->iSubItem
;
1296 case LVN_DELETEALLITEMS
:
1297 // what's the sense of generating a wxWin event for this when
1298 // it's absolutely not portable?
1300 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1301 event
.m_itemIndex
= -1;
1304 // return TRUE to suppress all additional LVN_DELETEITEM
1305 // notifications - this makes deleting all items from a list ctrl
1311 case LVN_DELETEITEM
:
1313 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1314 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1315 event
.m_itemIndex
= hdr
->iItem
;
1319 delete (wxListItemAttr
*)m_attrs
.Delete(hdr
->iItem
);
1324 case LVN_ENDLABELEDIT
:
1326 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1327 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1328 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1329 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1334 case LVN_SETDISPINFO
:
1336 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1337 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1338 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1342 case LVN_GETDISPINFO
:
1343 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1344 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1348 // TODO: some text buffering here, I think
1349 // TODO: API for getting Windows to retrieve values
1351 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1352 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1353 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1360 case LVN_INSERTITEM
:
1362 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1363 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1364 event
.m_itemIndex
= hdr
->iItem
;
1368 case LVN_ITEMCHANGED
:
1370 // This needs to be sent to wxListCtrl as a rather more
1371 // concrete event. For now, just detect a selection
1373 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1374 if ( (hdr
->uNewState
& LVIS_SELECTED
) && !(hdr
->uOldState
& LVIS_SELECTED
) )
1376 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1377 event
.m_itemIndex
= hdr
->iItem
;
1379 else if ( !(hdr
->uNewState
& LVIS_SELECTED
) && (hdr
->uOldState
& LVIS_SELECTED
) )
1381 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1382 event
.m_itemIndex
= hdr
->iItem
;
1391 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1392 WORD wVKey
= info
->wVKey
;
1394 // get the current selection
1395 long lItem
= GetNextItem(-1,
1397 wxLIST_STATE_SELECTED
);
1399 // <Enter> or <Space> activate the selected item if any
1400 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1402 // TODO this behaviour probably should be optional
1403 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1404 event
.m_itemIndex
= lItem
;
1408 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1409 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1415 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1417 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1422 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1423 // if it happened on an item (and not on empty place)
1425 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1426 if ( hdr
->iItem
== -1 )
1432 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1433 event
.m_itemIndex
= hdr
->iItem
;
1438 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1439 subclass and check for the actual WM_RBUTTONDOWN message, because
1440 NM_RCLICK waits for the WM_RBUTTONUP message as well before firing off.
1441 We want to have notify events for both down -and- up. */
1443 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), don't do
1445 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) ) {
1449 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1450 LV_HITTESTINFO lvhti
;
1451 wxZeroMemory(lvhti
);
1453 ::GetCursorPos(&(lvhti
.pt
));
1454 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1455 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1457 if ( lvhti
.flags
& LVHT_ONITEM
)
1459 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1460 event
.m_itemIndex
= lvhti
.iItem
;
1467 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1469 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1471 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1476 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1477 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1478 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1479 event
.m_itemIndex
= hdr
->iItem
;
1484 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1487 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1488 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1489 switch( nmcd
.dwDrawStage
)
1492 // if we've got any items with non standard attributes,
1493 // notify us before painting each item
1494 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1498 case CDDS_ITEMPREPAINT
:
1500 wxListItemAttr
*attr
=
1501 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1505 // nothing to do for this item
1506 return CDRF_DODEFAULT
;
1510 wxColour colText
, colBack
;
1511 if ( attr
->HasFont() )
1513 wxFont font
= attr
->GetFont();
1514 hFont
= (HFONT
)font
.GetResourceHandle();
1521 if ( attr
->HasTextColour() )
1523 colText
= attr
->GetTextColour();
1527 colText
= GetTextColour();
1530 if ( attr
->HasBackgroundColour() )
1532 colBack
= attr
->GetBackgroundColour();
1536 colBack
= GetBackgroundColour();
1539 // note that if we wanted to set colours for
1540 // individual columns (subitems), we would have
1541 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1544 ::SelectObject(nmcd
.hdc
, hFont
);
1546 *result
= CDRF_NEWFONT
;
1550 *result
= CDRF_DODEFAULT
;
1553 lplvcd
->clrText
= wxColourToRGB(colText
);
1554 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1560 *result
= CDRF_DODEFAULT
;
1565 #endif // _WIN32_IE >= 0x300
1568 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1571 // process the event
1572 // -----------------
1574 event
.SetEventObject( this );
1575 event
.SetEventType(eventType
);
1577 if ( !GetEventHandler()->ProcessEvent(event
) )
1583 switch ( (int)nmhdr
->code
)
1585 case LVN_GETDISPINFO
:
1587 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1588 if ( info
->item
.mask
& LVIF_TEXT
)
1590 if ( !event
.m_item
.m_text
.IsNull() )
1592 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1593 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1596 // wxConvertToMSWListItem(this, event.m_item, info->item);
1599 case LVN_ENDLABELEDIT
:
1601 *result
= event
.IsAllowed();
1608 *result
= !event
.IsAllowed();
1613 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1615 // Remove the first element if 3 strings exist
1616 if ( m_stringPool
.Number() == 3 )
1618 wxNode
*node
= m_stringPool
.First();
1619 delete[] (char *)node
->Data();
1622 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1623 return (wxChar
*)node
->Data();
1626 // ----------------------------------------------------------------------------
1628 // ----------------------------------------------------------------------------
1630 // List item structure
1631 wxListItem::wxListItem()
1641 m_format
= wxLIST_FORMAT_CENTRE
;
1647 void wxListItem::Clear()
1656 m_format
= wxLIST_FORMAT_CENTRE
;
1658 m_text
= wxEmptyString
;
1660 if (m_attr
) delete m_attr
;
1664 void wxListItem::ClearAttributes()
1666 if (m_attr
) delete m_attr
;
1670 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1672 info
.m_data
= lvItem
.lParam
;
1675 info
.m_stateMask
= 0;
1676 info
.m_itemId
= lvItem
.iItem
;
1678 long oldMask
= lvItem
.mask
;
1680 bool needText
= FALSE
;
1681 if (getFullInfo
!= 0)
1683 if ( lvItem
.mask
& LVIF_TEXT
)
1690 lvItem
.pszText
= new wxChar
[513];
1691 lvItem
.cchTextMax
= 512;
1693 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1694 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1695 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1698 if ( lvItem
.mask
& LVIF_STATE
)
1700 info
.m_mask
|= wxLIST_MASK_STATE
;
1702 if ( lvItem
.stateMask
& LVIS_CUT
)
1704 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1705 if ( lvItem
.state
& LVIS_CUT
)
1706 info
.m_state
|= wxLIST_STATE_CUT
;
1708 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1710 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1711 if ( lvItem
.state
& LVIS_DROPHILITED
)
1712 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1714 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1716 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1717 if ( lvItem
.state
& LVIS_FOCUSED
)
1718 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1720 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1722 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1723 if ( lvItem
.state
& LVIS_SELECTED
)
1724 info
.m_state
|= wxLIST_STATE_SELECTED
;
1728 if ( lvItem
.mask
& LVIF_TEXT
)
1730 info
.m_mask
|= wxLIST_MASK_TEXT
;
1731 info
.m_text
= lvItem
.pszText
;
1733 if ( lvItem
.mask
& LVIF_IMAGE
)
1735 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1736 info
.m_image
= lvItem
.iImage
;
1738 if ( lvItem
.mask
& LVIF_PARAM
)
1739 info
.m_mask
|= wxLIST_MASK_DATA
;
1740 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1741 info
.m_mask
|= wxLIST_SET_ITEM
;
1742 info
.m_col
= lvItem
.iSubItem
;
1747 delete[] lvItem
.pszText
;
1749 lvItem
.mask
= oldMask
;
1752 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1754 lvItem
.iItem
= (int) info
.m_itemId
;
1756 lvItem
.iImage
= info
.m_image
;
1757 lvItem
.lParam
= info
.m_data
;
1758 lvItem
.stateMask
= 0;
1761 lvItem
.iSubItem
= info
.m_col
;
1763 if (info
.m_mask
& wxLIST_MASK_STATE
)
1765 lvItem
.mask
|= LVIF_STATE
;
1766 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1768 lvItem
.stateMask
|= LVIS_CUT
;
1769 if (info
.m_state
& wxLIST_STATE_CUT
)
1770 lvItem
.state
|= LVIS_CUT
;
1772 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1774 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1775 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1776 lvItem
.state
|= LVIS_DROPHILITED
;
1778 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1780 lvItem
.stateMask
|= LVIS_FOCUSED
;
1781 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1782 lvItem
.state
|= LVIS_FOCUSED
;
1784 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1786 lvItem
.stateMask
|= LVIS_SELECTED
;
1787 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1788 lvItem
.state
|= LVIS_SELECTED
;
1792 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1794 lvItem
.mask
|= LVIF_TEXT
;
1795 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1797 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1801 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1802 if ( lvItem
.pszText
)
1803 lvItem
.cchTextMax
= info
.m_text
.Length();
1805 lvItem
.cchTextMax
= 0;
1808 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1809 lvItem
.mask
|= LVIF_IMAGE
;
1810 if (info
.m_mask
& wxLIST_MASK_DATA
)
1811 lvItem
.mask
|= LVIF_PARAM
;
1814 // ----------------------------------------------------------------------------
1816 // ----------------------------------------------------------------------------
1818 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1820 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1821 : wxNotifyEvent(commandType
, id
)
1827 m_cancelled
= FALSE
;