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 #if !USE_SHARED_LIBRARY
65 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
66 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
67 #endif // USE_SHARED_LIBRARY
69 // ============================================================================
71 // ============================================================================
73 // ----------------------------------------------------------------------------
74 // wxListCtrl construction
75 // ----------------------------------------------------------------------------
77 void wxListCtrl::Init()
79 m_imageListNormal
= NULL
;
80 m_imageListSmall
= NULL
;
81 m_imageListState
= NULL
;
88 bool wxListCtrl::Create(wxWindow
*parent
,
93 const wxValidator
& validator
,
96 SetValidator(validator
);
104 m_windowStyle
= style
;
117 m_windowId
= (id
== -1) ? NewControlId() : id
;
119 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
120 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
121 if ( wxStyleHasBorder(m_windowStyle
) )
123 m_baseStyle
= wstyle
;
125 if ( !DoCreateControl(x
, y
, width
, height
) )
129 parent
->AddChild(this);
134 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
136 DWORD wstyle
= m_baseStyle
;
139 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
141 // Even with extended styles, need to combine with WS_BORDER
142 // for them to look right.
146 long oldStyle
= 0; // Dummy
147 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
149 // Create the ListView control.
150 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
155 GetWinHwnd(GetParent()),
162 wxLogError(wxT("Can't create list control window."));
167 // for comctl32.dll v 4.70+ we want to have this attribute because it's
168 // prettier (and also because wxGTK does it like this)
169 #ifdef ListView_SetExtendedListViewStyle
170 if ( wstyle
& LVS_REPORT
)
172 ListView_SetExtendedListViewStyle(GetHwnd(),
173 LVS_EX_FULLROWSELECT
);
175 #endif // ListView_SetExtendedListViewStyle
177 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
178 SetForegroundColour(GetParent()->GetForegroundColour());
185 void wxListCtrl::UpdateStyle()
189 // The new window view style
191 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
192 dwStyleNew
|= m_baseStyle
;
194 // Get the current window style.
195 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
197 // Only set the window style if the view bits have changed.
198 if ( dwStyleOld
!= dwStyleNew
)
200 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
205 wxListCtrl::~wxListCtrl()
209 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
211 delete (wxListItemAttr
*)node
->Data();
217 m_textCtrl
->UnsubclassWin();
218 m_textCtrl
->SetHWND(0);
224 // ----------------------------------------------------------------------------
225 // set/get/change style
226 // ----------------------------------------------------------------------------
228 // Add or remove a single window style
229 void wxListCtrl::SetSingleStyle(long style
, bool add
)
231 long flag
= GetWindowStyleFlag();
233 // Get rid of conflicting styles
236 if ( style
& wxLC_MASK_TYPE
)
237 flag
= flag
& ~wxLC_MASK_TYPE
;
238 if ( style
& wxLC_MASK_ALIGN
)
239 flag
= flag
& ~wxLC_MASK_ALIGN
;
240 if ( style
& wxLC_MASK_SORT
)
241 flag
= flag
& ~wxLC_MASK_SORT
;
257 m_windowStyle
= flag
;
262 // Set the whole window style
263 void wxListCtrl::SetWindowStyleFlag(long flag
)
265 m_windowStyle
= flag
;
270 // Can be just a single style, or a bitlist
271 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
274 if ( style
& wxLC_ICON
)
276 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
277 oldStyle
-= LVS_SMALLICON
;
278 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
279 oldStyle
-= LVS_REPORT
;
280 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
281 oldStyle
-= LVS_LIST
;
285 if ( style
& wxLC_SMALL_ICON
)
287 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
288 oldStyle
-= LVS_ICON
;
289 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
290 oldStyle
-= LVS_REPORT
;
291 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
292 oldStyle
-= LVS_LIST
;
293 wstyle
|= LVS_SMALLICON
;
296 if ( style
& wxLC_LIST
)
298 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
299 oldStyle
-= LVS_ICON
;
300 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
301 oldStyle
-= LVS_REPORT
;
302 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
303 oldStyle
-= LVS_SMALLICON
;
307 if ( style
& wxLC_REPORT
)
309 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
310 oldStyle
-= LVS_ICON
;
311 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
312 oldStyle
-= LVS_LIST
;
313 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
314 oldStyle
-= LVS_SMALLICON
;
316 wstyle
|= LVS_REPORT
;
319 if ( style
& wxLC_ALIGN_LEFT
)
321 if ( oldStyle
& LVS_ALIGNTOP
)
322 oldStyle
-= LVS_ALIGNTOP
;
323 wstyle
|= LVS_ALIGNLEFT
;
326 if ( style
& wxLC_ALIGN_TOP
)
328 if ( oldStyle
& LVS_ALIGNLEFT
)
329 oldStyle
-= LVS_ALIGNLEFT
;
330 wstyle
|= LVS_ALIGNTOP
;
333 if ( style
& wxLC_AUTOARRANGE
)
334 wstyle
|= LVS_AUTOARRANGE
;
336 // Apparently, no such style (documentation wrong?)
338 if ( style & wxLC_BUTTON )
339 wstyle |= LVS_BUTTON;
342 if ( style
& wxLC_NO_SORT_HEADER
)
343 wstyle
|= LVS_NOSORTHEADER
;
345 if ( style
& wxLC_NO_HEADER
)
346 wstyle
|= LVS_NOCOLUMNHEADER
;
348 if ( style
& wxLC_EDIT_LABELS
)
349 wstyle
|= LVS_EDITLABELS
;
351 if ( style
& wxLC_SINGLE_SEL
)
352 wstyle
|= LVS_SINGLESEL
;
354 if ( style
& wxLC_SORT_ASCENDING
)
356 if ( oldStyle
& LVS_SORTDESCENDING
)
357 oldStyle
-= LVS_SORTDESCENDING
;
358 wstyle
|= LVS_SORTASCENDING
;
361 if ( style
& wxLC_SORT_DESCENDING
)
363 if ( oldStyle
& LVS_SORTASCENDING
)
364 oldStyle
-= LVS_SORTASCENDING
;
365 wstyle
|= LVS_SORTDESCENDING
;
371 // ----------------------------------------------------------------------------
373 // ----------------------------------------------------------------------------
375 // Sets the background colour (GetBackgroundColour already implicit in
377 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
379 if ( !wxWindow::SetBackgroundColour(col
) )
382 ListView_SetBkColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
387 // Gets information about this column
388 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
393 lvCol
.pszText
= NULL
;
395 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
397 lvCol
.mask
|= LVCF_TEXT
;
398 lvCol
.pszText
= new wxChar
[513];
399 lvCol
.cchTextMax
= 512;
402 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
404 // item.m_subItem = lvCol.iSubItem;
405 item
.m_width
= lvCol
.cx
;
407 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
409 item
.m_text
= lvCol
.pszText
;
410 delete[] lvCol
.pszText
;
413 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
415 if (lvCol
.fmt
== LVCFMT_LEFT
)
416 item
.m_format
= wxLIST_FORMAT_LEFT
;
417 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
418 item
.m_format
= wxLIST_FORMAT_RIGHT
;
419 else if (lvCol
.fmt
== LVCFMT_CENTER
)
420 item
.m_format
= wxLIST_FORMAT_CENTRE
;
426 // Sets information about this column
427 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
432 lvCol
.pszText
= NULL
;
434 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
436 lvCol
.mask
|= LVCF_TEXT
;
437 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
438 lvCol
.cchTextMax
= 0; // Ignored
440 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
442 lvCol
.mask
|= LVCF_FMT
;
444 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
445 lvCol
.fmt
= LVCFMT_LEFT
;
446 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
447 lvCol
.fmt
= LVCFMT_RIGHT
;
448 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
449 lvCol
.fmt
= LVCFMT_CENTER
;
452 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
454 lvCol
.mask
|= LVCF_WIDTH
;
455 lvCol
.cx
= item
.m_width
;
457 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
458 lvCol
.cx
= LVSCW_AUTOSIZE
;
459 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
460 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
462 lvCol
.mask
|= LVCF_SUBITEM
;
463 lvCol
.iSubItem
= col
;
464 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
467 // Gets the column width
468 int wxListCtrl::GetColumnWidth(int col
) const
470 return ListView_GetColumnWidth(GetHwnd(), col
);
473 // Sets the column width
474 bool wxListCtrl::SetColumnWidth(int col
, int width
)
477 if ( m_windowStyle
& wxLC_LIST
)
481 if ( width2
== wxLIST_AUTOSIZE
)
482 width2
= LVSCW_AUTOSIZE
;
483 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
484 width2
= LVSCW_AUTOSIZE_USEHEADER
;
486 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
489 // Gets the number of items that can fit vertically in the
490 // visible area of the list control (list or report view)
491 // or the total number of items in the list control (icon
492 // or small icon view)
493 int wxListCtrl::GetCountPerPage(void) const
495 return ListView_GetCountPerPage(GetHwnd());
498 // Gets the edit control for editing labels.
499 wxTextCtrl
* wxListCtrl::GetEditControl(void) const
504 // Gets information about the item
505 bool wxListCtrl::GetItem(wxListItem
& info
) const
508 wxZeroMemory(lvItem
);
510 lvItem
.iItem
= info
.m_itemId
;
511 lvItem
.iSubItem
= info
.m_col
;
513 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
515 lvItem
.mask
|= LVIF_TEXT
;
516 lvItem
.pszText
= new wxChar
[513];
517 lvItem
.cchTextMax
= 512;
521 lvItem
.pszText
= NULL
;
524 if (info
.m_mask
& wxLIST_MASK_DATA
)
525 lvItem
.mask
|= LVIF_PARAM
;
527 if ( info
.m_mask
& wxLIST_MASK_STATE
)
529 lvItem
.mask
|= LVIF_STATE
;
530 // the other bits are hardly interesting anyhow
531 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
534 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
537 wxLogError(_("Couldn't retrieve information about list control item %d."),
542 wxConvertFromMSWListItem(this, info
, lvItem
);
546 delete[] lvItem
.pszText
;
551 // Sets information about the item
552 bool wxListCtrl::SetItem(wxListItem
& info
)
555 wxConvertToMSWListItem(this, info
, item
);
557 // check whether it has any custom attributes
558 if ( info
.HasAttributes() )
560 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
566 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
567 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
569 // make the change visible
570 ListView_Update(GetHwnd(), item
.iItem
);
576 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
580 info
.m_mask
= wxLIST_MASK_TEXT
;
581 info
.m_itemId
= index
;
585 info
.m_image
= imageId
;
586 info
.m_mask
|= wxLIST_MASK_IMAGE
;
588 return SetItem(info
);
592 // Gets the item state
593 int wxListCtrl::GetItemState(long item
, long stateMask
) const
597 info
.m_mask
= wxLIST_MASK_STATE
;
598 info
.m_stateMask
= stateMask
;
599 info
.m_itemId
= item
;
607 // Sets the item state
608 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
612 info
.m_mask
= wxLIST_MASK_STATE
;
613 info
.m_state
= state
;
614 info
.m_stateMask
= stateMask
;
615 info
.m_itemId
= item
;
617 return SetItem(info
);
620 // Sets the item image
621 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
625 info
.m_mask
= wxLIST_MASK_IMAGE
;
626 info
.m_image
= image
;
627 info
.m_itemId
= item
;
629 return SetItem(info
);
632 // Gets the item text
633 wxString
wxListCtrl::GetItemText(long item
) const
637 info
.m_mask
= wxLIST_MASK_TEXT
;
638 info
.m_itemId
= item
;
645 // Sets the item text
646 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
650 info
.m_mask
= wxLIST_MASK_TEXT
;
651 info
.m_itemId
= item
;
657 // Gets the item data
658 long wxListCtrl::GetItemData(long item
) const
662 info
.m_mask
= wxLIST_MASK_DATA
;
663 info
.m_itemId
= item
;
670 // Sets the item data
671 bool wxListCtrl::SetItemData(long item
, long data
)
675 info
.m_mask
= wxLIST_MASK_DATA
;
676 info
.m_itemId
= item
;
679 return SetItem(info
);
682 // Gets the item rectangle
683 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
687 int code2
= LVIR_BOUNDS
;
688 if ( code
== wxLIST_RECT_BOUNDS
)
690 else if ( code
== wxLIST_RECT_ICON
)
692 else if ( code
== wxLIST_RECT_LABEL
)
696 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
698 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
703 rect
.width
= rect2
.right
- rect2
.left
;
704 rect
.height
= rect2
.bottom
- rect2
.left
;
708 // Gets the item position
709 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
713 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
715 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
719 // Sets the item position.
720 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
722 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
725 // Gets the number of items in the list control
726 int wxListCtrl::GetItemCount(void) const
728 return ListView_GetItemCount(GetHwnd());
731 // Retrieves the spacing between icons in pixels.
732 // If small is TRUE, gets the spacing for the small icon
733 // view, otherwise the large icon view.
734 int wxListCtrl::GetItemSpacing(bool isSmall
) const
736 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
739 // Gets the number of selected items in the list control
740 int wxListCtrl::GetSelectedItemCount(void) const
742 return ListView_GetSelectedCount(GetHwnd());
745 // Gets the text colour of the listview
746 wxColour
wxListCtrl::GetTextColour(void) const
748 COLORREF ref
= ListView_GetTextColor(GetHwnd());
749 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
753 // Sets the text colour of the listview
754 void wxListCtrl::SetTextColour(const wxColour
& col
)
756 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
759 // Gets the index of the topmost visible item when in
760 // list or report view
761 long wxListCtrl::GetTopItem(void) const
763 return (long) ListView_GetTopIndex(GetHwnd());
766 // Searches for an item, starting from 'item'.
767 // 'geometry' is one of
768 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
769 // 'state' is a state bit flag, one or more of
770 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
771 // item can be -1 to find the first item that matches the
773 // Returns the item or -1 if unsuccessful.
774 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
778 if ( geom
== wxLIST_NEXT_ABOVE
)
780 if ( geom
== wxLIST_NEXT_ALL
)
782 if ( geom
== wxLIST_NEXT_BELOW
)
784 if ( geom
== wxLIST_NEXT_LEFT
)
785 flags
|= LVNI_TOLEFT
;
786 if ( geom
== wxLIST_NEXT_RIGHT
)
787 flags
|= LVNI_TORIGHT
;
789 if ( state
& wxLIST_STATE_CUT
)
791 if ( state
& wxLIST_STATE_DROPHILITED
)
792 flags
|= LVNI_DROPHILITED
;
793 if ( state
& wxLIST_STATE_FOCUSED
)
794 flags
|= LVNI_FOCUSED
;
795 if ( state
& wxLIST_STATE_SELECTED
)
796 flags
|= LVNI_SELECTED
;
798 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
802 wxImageList
*wxListCtrl::GetImageList(int which
) const
804 if ( which
== wxIMAGE_LIST_NORMAL
)
806 return m_imageListNormal
;
808 else if ( which
== wxIMAGE_LIST_SMALL
)
810 return m_imageListSmall
;
812 else if ( which
== wxIMAGE_LIST_STATE
)
814 return m_imageListState
;
819 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
822 if ( which
== wxIMAGE_LIST_NORMAL
)
824 flags
= LVSIL_NORMAL
;
825 m_imageListNormal
= imageList
;
827 else if ( which
== wxIMAGE_LIST_SMALL
)
830 m_imageListSmall
= imageList
;
832 else if ( which
== wxIMAGE_LIST_STATE
)
835 m_imageListState
= imageList
;
837 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
840 // ----------------------------------------------------------------------------
842 // ----------------------------------------------------------------------------
844 // Arranges the items
845 bool wxListCtrl::Arrange(int flag
)
848 if ( flag
== wxLIST_ALIGN_LEFT
)
849 code
= LVA_ALIGNLEFT
;
850 else if ( flag
== wxLIST_ALIGN_TOP
)
852 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
854 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
855 code
= LVA_SNAPTOGRID
;
857 return (ListView_Arrange(GetHwnd(), code
) != 0);
861 bool wxListCtrl::DeleteItem(long item
)
863 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
867 bool wxListCtrl::DeleteAllItems()
869 return (ListView_DeleteAllItems(GetHwnd()) != 0);
873 bool wxListCtrl::DeleteAllColumns()
875 while ( m_colCount
> 0 )
877 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
879 wxLogLastError("ListView_DeleteColumn");
887 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
893 bool wxListCtrl::DeleteColumn(int col
)
895 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
897 if ( success
&& (m_colCount
> 0) )
902 // Clears items, and columns if there are any.
903 void wxListCtrl::ClearAll()
906 if ( m_colCount
> 0 )
910 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
912 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
914 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
918 m_textCtrl
->UnsubclassWin();
919 m_textCtrl
->SetHWND(0);
924 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
925 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
926 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
931 // End label editing, optionally cancelling the edit
932 bool wxListCtrl::EndEditLabel(bool cancel
)
936 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
938 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
942 m_textCtrl->UnsubclassWin();
943 m_textCtrl->SetHWND(0);
953 // Ensures this item is visible
954 bool wxListCtrl::EnsureVisible(long item
)
956 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
959 // Find an item whose label matches this string, starting from the item after 'start'
960 // or the beginning if 'start' is -1.
961 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
963 LV_FINDINFO findInfo
;
965 findInfo
.flags
= LVFI_STRING
;
967 findInfo
.flags
|= LVFI_STRING
;
968 findInfo
.psz
= WXSTRINGCAST str
;
970 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
973 // Find an item whose data matches this data, starting from the item after 'start'
974 // or the beginning if 'start' is -1.
975 long wxListCtrl::FindItem(long start
, long data
)
977 LV_FINDINFO findInfo
;
979 findInfo
.flags
= LVFI_PARAM
;
980 findInfo
.lParam
= data
;
982 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
985 // Find an item nearest this position in the specified direction, starting from
986 // the item after 'start' or the beginning if 'start' is -1.
987 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
989 LV_FINDINFO findInfo
;
991 findInfo
.flags
= LVFI_NEARESTXY
;
992 findInfo
.pt
.x
= pt
.x
;
993 findInfo
.pt
.y
= pt
.y
;
994 findInfo
.vkDirection
= VK_RIGHT
;
996 if ( direction
== wxLIST_FIND_UP
)
997 findInfo
.vkDirection
= VK_UP
;
998 else if ( direction
== wxLIST_FIND_DOWN
)
999 findInfo
.vkDirection
= VK_DOWN
;
1000 else if ( direction
== wxLIST_FIND_LEFT
)
1001 findInfo
.vkDirection
= VK_LEFT
;
1002 else if ( direction
== wxLIST_FIND_RIGHT
)
1003 findInfo
.vkDirection
= VK_RIGHT
;
1005 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1008 // Determines which item (if any) is at the specified point,
1009 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1010 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1012 LV_HITTESTINFO hitTestInfo
;
1013 hitTestInfo
.pt
.x
= (int) point
.x
;
1014 hitTestInfo
.pt
.y
= (int) point
.y
;
1016 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1019 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1020 flags
|= wxLIST_HITTEST_ABOVE
;
1021 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1022 flags
|= wxLIST_HITTEST_BELOW
;
1023 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1024 flags
|= wxLIST_HITTEST_NOWHERE
;
1025 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1026 flags
|= wxLIST_HITTEST_ONITEMICON
;
1027 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1028 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1029 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1030 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1031 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1032 flags
|= wxLIST_HITTEST_TOLEFT
;
1033 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1034 flags
|= wxLIST_HITTEST_TORIGHT
;
1036 return (long) hitTestInfo
.iItem
;
1039 // Inserts an item, returning the index of the new item if successful,
1041 long wxListCtrl::InsertItem(wxListItem
& info
)
1044 wxConvertToMSWListItem(this, info
, item
);
1046 // check whether it has any custom attributes
1047 if ( info
.HasAttributes() )
1049 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1051 m_hasAnyAttr
= TRUE
;
1054 return (long) ListView_InsertItem(GetHwnd(), & item
);
1057 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1060 info
.m_text
= label
;
1061 info
.m_mask
= wxLIST_MASK_TEXT
;
1062 info
.m_itemId
= index
;
1063 return InsertItem(info
);
1066 // Inserts an image item
1067 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1070 info
.m_image
= imageIndex
;
1071 info
.m_mask
= wxLIST_MASK_IMAGE
;
1072 info
.m_itemId
= index
;
1073 return InsertItem(info
);
1076 // Inserts an image/string item
1077 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1080 info
.m_image
= imageIndex
;
1081 info
.m_text
= label
;
1082 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1083 info
.m_itemId
= index
;
1084 return InsertItem(info
);
1087 // For list view mode (only), inserts a column.
1088 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1093 lvCol
.pszText
= NULL
;
1095 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1097 lvCol
.mask
|= LVCF_TEXT
;
1098 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1099 lvCol
.cchTextMax
= 0; // Ignored
1101 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1103 lvCol
.mask
|= LVCF_FMT
;
1105 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1106 lvCol
.fmt
= LVCFMT_LEFT
;
1107 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1108 lvCol
.fmt
= LVCFMT_RIGHT
;
1109 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1110 lvCol
.fmt
= LVCFMT_CENTER
;
1113 lvCol
.mask
|= LVCF_WIDTH
;
1114 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1116 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1117 lvCol
.cx
= LVSCW_AUTOSIZE
;
1118 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1119 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1121 lvCol
.cx
= item
.m_width
;
1125 // always give some width to the new column: this one is compatible
1130 lvCol
.mask
|= LVCF_SUBITEM
;
1131 lvCol
.iSubItem
= col
;
1133 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1140 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1147 long wxListCtrl::InsertColumn(long col
,
1148 const wxString
& heading
,
1153 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1154 item
.m_text
= heading
;
1157 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1158 item
.m_width
= width
;
1160 item
.m_format
= format
;
1162 return InsertColumn(col
, item
);
1165 // Scrolls the list control. If in icon, small icon or report view mode,
1166 // x specifies the number of pixels to scroll. If in list view mode, x
1167 // specifies the number of columns to scroll.
1168 // If in icon, small icon or list view mode, y specifies the number of pixels
1169 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1170 bool wxListCtrl::ScrollList(int dx
, int dy
)
1172 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1177 // fn is a function which takes 3 long arguments: item1, item2, data.
1178 // item1 is the long data associated with a first item (NOT the index).
1179 // item2 is the long data associated with a second item (NOT the index).
1180 // data is the same value as passed to SortItems.
1181 // The return value is a negative number if the first item should precede the second
1182 // item, a positive number of the second item should precede the first,
1183 // or zero if the two items are equivalent.
1185 // data is arbitrary data to be passed to the sort function.
1186 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1188 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1191 // ----------------------------------------------------------------------------
1192 // message processing
1193 // ----------------------------------------------------------------------------
1195 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1197 if (cmd
== EN_UPDATE
)
1199 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1200 event
.SetEventObject( this );
1201 ProcessCommand(event
);
1204 else if (cmd
== EN_KILLFOCUS
)
1206 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1207 event
.SetEventObject( this );
1208 ProcessCommand(event
);
1215 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1217 // prepare the event
1218 // -----------------
1220 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1221 wxEventType eventType
= wxEVT_NULL
;
1222 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1223 switch ( nmhdr
->code
)
1225 case LVN_BEGINRDRAG
:
1226 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1230 if ( eventType
== wxEVT_NULL
)
1232 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1236 NM_LISTVIEW
*hdr
= (NM_LISTVIEW
*)lParam
;
1237 event
.m_itemIndex
= hdr
->iItem
;
1238 event
.m_pointDrag
.x
= hdr
->ptAction
.x
;
1239 event
.m_pointDrag
.y
= hdr
->ptAction
.y
;
1243 case LVN_BEGINLABELEDIT
:
1245 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1246 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1247 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1251 case LVN_COLUMNCLICK
:
1253 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1254 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1255 event
.m_itemIndex
= -1;
1256 event
.m_col
= hdr
->iSubItem
;
1260 case LVN_DELETEALLITEMS
:
1261 // what's the sense of generating a wxWin event for this when
1262 // it's absolutely not portable?
1264 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1265 event
.m_itemIndex
= -1;
1268 // return TRUE to suppress all additional LVN_DELETEITEM
1269 // notifications - this makes deleting all items from a list ctrl
1275 case LVN_DELETEITEM
:
1277 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1278 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1279 event
.m_itemIndex
= hdr
->iItem
;
1283 delete m_attrs
.Delete(hdr
->iItem
);
1288 case LVN_ENDLABELEDIT
:
1290 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1291 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1292 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1293 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1298 case LVN_SETDISPINFO
:
1300 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1301 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1302 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1306 case LVN_GETDISPINFO
:
1307 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1308 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1312 // TODO: some text buffering here, I think
1313 // TODO: API for getting Windows to retrieve values
1315 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1316 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1317 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1324 case LVN_INSERTITEM
:
1326 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1327 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1328 event
.m_itemIndex
= hdr
->iItem
;
1332 case LVN_ITEMCHANGED
:
1334 // This needs to be sent to wxListCtrl as a rather more
1335 // concrete event. For now, just detect a selection
1337 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1338 if ( (hdr
->uNewState
& LVIS_SELECTED
) && !(hdr
->uOldState
& LVIS_SELECTED
) )
1340 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1341 event
.m_itemIndex
= hdr
->iItem
;
1343 else if ( !(hdr
->uNewState
& LVIS_SELECTED
) && (hdr
->uOldState
& LVIS_SELECTED
) )
1345 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1346 event
.m_itemIndex
= hdr
->iItem
;
1355 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1356 WORD wVKey
= info
->wVKey
;
1358 // get the current selection
1359 long lItem
= GetNextItem(-1,
1361 wxLIST_STATE_SELECTED
);
1363 // <Enter> or <Space> activate the selected item if any
1364 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1366 // TODO this behaviour probably should be optional
1367 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1368 event
.m_itemIndex
= lItem
;
1372 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1373 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1379 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1381 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1386 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1388 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1389 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1390 event
.m_itemIndex
= hdr
->iItem
;
1395 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1396 subclass and check for the actual WM_RBUTTONDOWN message, because
1397 NM_RCLICK waits for the WM_RBUTTONUP message as well before firing off.
1398 We want to have notify events for both down -and- up. */
1400 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), don't do
1402 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) ) {
1406 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1407 LV_HITTESTINFO lvhti
;
1408 wxZeroMemory(lvhti
);
1410 ::GetCursorPos(&(lvhti
.pt
));
1411 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1412 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1414 if ( lvhti
.flags
& LVHT_ONITEM
)
1416 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1417 event
.m_itemIndex
= lvhti
.iItem
;
1424 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1426 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1428 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1433 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1434 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1435 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1436 event
.m_itemIndex
= hdr
->iItem
;
1441 #ifdef NM_CUSTOMDRAW
1444 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1445 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1446 switch( nmcd
.dwDrawStage
)
1449 // if we've got any items with non standard attributes,
1450 // notify us before painting each item
1451 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1455 case CDDS_ITEMPREPAINT
:
1457 wxListItemAttr
*attr
=
1458 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1462 // nothing to do for this item
1463 return CDRF_DODEFAULT
;
1467 wxColour colText
, colBack
;
1468 if ( attr
->HasFont() )
1470 wxFont font
= attr
->GetFont();
1471 hFont
= (HFONT
)font
.GetResourceHandle();
1478 if ( attr
->HasTextColour() )
1480 colText
= attr
->GetTextColour();
1484 colText
= GetTextColour();
1487 if ( attr
->HasBackgroundColour() )
1489 colBack
= attr
->GetBackgroundColour();
1493 colBack
= GetBackgroundColour();
1496 // note that if we wanted to set colours for
1497 // individual columns (subitems), we would have
1498 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1501 ::SelectObject(nmcd
.hdc
, hFont
);
1503 *result
= CDRF_NEWFONT
;
1507 *result
= CDRF_DODEFAULT
;
1510 lplvcd
->clrText
= wxColourToRGB(colText
);
1511 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1517 *result
= CDRF_DODEFAULT
;
1522 #endif // NM_CUSTOMDRAW
1525 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1528 // process the event
1529 // -----------------
1531 event
.SetEventObject( this );
1532 event
.SetEventType(eventType
);
1534 if ( !GetEventHandler()->ProcessEvent(event
) )
1540 switch ( (int)nmhdr
->code
)
1542 case LVN_GETDISPINFO
:
1544 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1545 if ( info
->item
.mask
& LVIF_TEXT
)
1547 if ( !event
.m_item
.m_text
.IsNull() )
1549 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1550 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1553 // wxConvertToMSWListItem(this, event.m_item, info->item);
1556 case LVN_ENDLABELEDIT
:
1558 *result
= event
.IsAllowed();
1565 *result
= !event
.IsAllowed();
1570 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1572 // Remove the first element if 3 strings exist
1573 if ( m_stringPool
.Number() == 3 )
1575 wxNode
*node
= m_stringPool
.First();
1576 delete[] (char *)node
->Data();
1579 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1580 return (wxChar
*)node
->Data();
1583 // ----------------------------------------------------------------------------
1585 // ----------------------------------------------------------------------------
1587 // List item structure
1588 wxListItem::wxListItem()
1598 m_format
= wxLIST_FORMAT_CENTRE
;
1604 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1606 info
.m_data
= lvItem
.lParam
;
1609 info
.m_stateMask
= 0;
1610 info
.m_itemId
= lvItem
.iItem
;
1612 long oldMask
= lvItem
.mask
;
1614 bool needText
= FALSE
;
1615 if (getFullInfo
!= 0)
1617 if ( lvItem
.mask
& LVIF_TEXT
)
1624 lvItem
.pszText
= new wxChar
[513];
1625 lvItem
.cchTextMax
= 512;
1627 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1628 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1629 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1632 if ( lvItem
.mask
& LVIF_STATE
)
1634 info
.m_mask
|= wxLIST_MASK_STATE
;
1636 if ( lvItem
.stateMask
& LVIS_CUT
)
1638 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1639 if ( lvItem
.state
& LVIS_CUT
)
1640 info
.m_state
|= wxLIST_STATE_CUT
;
1642 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1644 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1645 if ( lvItem
.state
& LVIS_DROPHILITED
)
1646 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1648 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1650 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1651 if ( lvItem
.state
& LVIS_FOCUSED
)
1652 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1654 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1656 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1657 if ( lvItem
.state
& LVIS_SELECTED
)
1658 info
.m_state
|= wxLIST_STATE_SELECTED
;
1662 if ( lvItem
.mask
& LVIF_TEXT
)
1664 info
.m_mask
|= wxLIST_MASK_TEXT
;
1665 info
.m_text
= lvItem
.pszText
;
1667 if ( lvItem
.mask
& LVIF_IMAGE
)
1669 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1670 info
.m_image
= lvItem
.iImage
;
1672 if ( lvItem
.mask
& LVIF_PARAM
)
1673 info
.m_mask
|= wxLIST_MASK_DATA
;
1674 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1675 info
.m_mask
|= wxLIST_SET_ITEM
;
1676 info
.m_col
= lvItem
.iSubItem
;
1681 delete[] lvItem
.pszText
;
1683 lvItem
.mask
= oldMask
;
1686 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1688 lvItem
.iItem
= (int) info
.m_itemId
;
1690 lvItem
.iImage
= info
.m_image
;
1691 lvItem
.lParam
= info
.m_data
;
1692 lvItem
.stateMask
= 0;
1695 lvItem
.iSubItem
= info
.m_col
;
1697 if (info
.m_mask
& wxLIST_MASK_STATE
)
1699 lvItem
.mask
|= LVIF_STATE
;
1700 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1702 lvItem
.stateMask
|= LVIS_CUT
;
1703 if (info
.m_state
& wxLIST_STATE_CUT
)
1704 lvItem
.state
|= LVIS_CUT
;
1706 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1708 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1709 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1710 lvItem
.state
|= LVIS_DROPHILITED
;
1712 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1714 lvItem
.stateMask
|= LVIS_FOCUSED
;
1715 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1716 lvItem
.state
|= LVIS_FOCUSED
;
1718 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1720 lvItem
.stateMask
|= LVIS_SELECTED
;
1721 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1722 lvItem
.state
|= LVIS_SELECTED
;
1726 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1728 lvItem
.mask
|= LVIF_TEXT
;
1729 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1731 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1735 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1736 if ( lvItem
.pszText
)
1737 lvItem
.cchTextMax
= info
.m_text
.Length();
1739 lvItem
.cchTextMax
= 0;
1742 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1743 lvItem
.mask
|= LVIF_IMAGE
;
1744 if (info
.m_mask
& wxLIST_MASK_DATA
)
1745 lvItem
.mask
|= LVIF_PARAM
;
1748 // ----------------------------------------------------------------------------
1750 // ----------------------------------------------------------------------------
1752 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1754 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1755 : wxNotifyEvent(commandType
, id
)
1761 m_cancelled
= FALSE
;