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 // ----------------------------------------------------------------------------
72 // wxListCtrl construction
73 // ----------------------------------------------------------------------------
75 void wxListCtrl::Init()
77 m_imageListNormal
= NULL
;
78 m_imageListSmall
= NULL
;
79 m_imageListState
= NULL
;
86 bool wxListCtrl::Create(wxWindow
*parent
,
91 const wxValidator
& validator
,
94 SetValidator(validator
);
102 m_windowStyle
= style
;
115 m_windowId
= (id
== -1) ? NewControlId() : id
;
117 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
118 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
119 if ( wxStyleHasBorder(m_windowStyle
) )
121 m_baseStyle
= wstyle
;
123 if ( !DoCreateControl(x
, y
, width
, height
) )
127 parent
->AddChild(this);
132 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
134 DWORD wstyle
= m_baseStyle
;
137 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
139 // Even with extended styles, need to combine with WS_BORDER
140 // for them to look right.
144 long oldStyle
= 0; // Dummy
145 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
147 // Create the ListView control.
148 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
153 GetWinHwnd(GetParent()),
160 wxLogError(wxT("Can't create list control window."));
165 // for comctl32.dll v 4.70+ we want to have this attribute because it's
166 // prettier (and also because wxGTK does it like this)
167 #ifdef ListView_SetExtendedListViewStyle
168 if ( wstyle
& LVS_REPORT
)
170 ListView_SetExtendedListViewStyle(GetHwnd(),
171 LVS_EX_FULLROWSELECT
);
173 #endif // ListView_SetExtendedListViewStyle
175 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
176 SetForegroundColour(GetParent()->GetForegroundColour());
183 void wxListCtrl::UpdateStyle()
187 // The new window view style
189 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
190 dwStyleNew
|= m_baseStyle
;
192 // Get the current window style.
193 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
195 // Only set the window style if the view bits have changed.
196 if ( dwStyleOld
!= dwStyleNew
)
198 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
203 wxListCtrl::~wxListCtrl()
207 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
209 delete (wxListItemAttr
*)node
->Data();
215 m_textCtrl
->UnsubclassWin();
216 m_textCtrl
->SetHWND(0);
222 // ----------------------------------------------------------------------------
223 // set/get/change style
224 // ----------------------------------------------------------------------------
226 // Add or remove a single window style
227 void wxListCtrl::SetSingleStyle(long style
, bool add
)
229 long flag
= GetWindowStyleFlag();
231 // Get rid of conflicting styles
234 if ( style
& wxLC_MASK_TYPE
)
235 flag
= flag
& ~wxLC_MASK_TYPE
;
236 if ( style
& wxLC_MASK_ALIGN
)
237 flag
= flag
& ~wxLC_MASK_ALIGN
;
238 if ( style
& wxLC_MASK_SORT
)
239 flag
= flag
& ~wxLC_MASK_SORT
;
255 m_windowStyle
= flag
;
260 // Set the whole window style
261 void wxListCtrl::SetWindowStyleFlag(long flag
)
263 m_windowStyle
= flag
;
268 // Can be just a single style, or a bitlist
269 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
272 if ( style
& wxLC_ICON
)
274 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
275 oldStyle
-= LVS_SMALLICON
;
276 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
277 oldStyle
-= LVS_REPORT
;
278 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
279 oldStyle
-= LVS_LIST
;
283 if ( style
& wxLC_SMALL_ICON
)
285 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
286 oldStyle
-= LVS_ICON
;
287 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
288 oldStyle
-= LVS_REPORT
;
289 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
290 oldStyle
-= LVS_LIST
;
291 wstyle
|= LVS_SMALLICON
;
294 if ( style
& wxLC_LIST
)
296 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
297 oldStyle
-= LVS_ICON
;
298 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
299 oldStyle
-= LVS_REPORT
;
300 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
301 oldStyle
-= LVS_SMALLICON
;
305 if ( style
& wxLC_REPORT
)
307 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
308 oldStyle
-= LVS_ICON
;
309 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
310 oldStyle
-= LVS_LIST
;
311 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
312 oldStyle
-= LVS_SMALLICON
;
314 wstyle
|= LVS_REPORT
;
317 if ( style
& wxLC_ALIGN_LEFT
)
319 if ( oldStyle
& LVS_ALIGNTOP
)
320 oldStyle
-= LVS_ALIGNTOP
;
321 wstyle
|= LVS_ALIGNLEFT
;
324 if ( style
& wxLC_ALIGN_TOP
)
326 if ( oldStyle
& LVS_ALIGNLEFT
)
327 oldStyle
-= LVS_ALIGNLEFT
;
328 wstyle
|= LVS_ALIGNTOP
;
331 if ( style
& wxLC_AUTOARRANGE
)
332 wstyle
|= LVS_AUTOARRANGE
;
334 // Apparently, no such style (documentation wrong?)
336 if ( style & wxLC_BUTTON )
337 wstyle |= LVS_BUTTON;
340 if ( style
& wxLC_NO_SORT_HEADER
)
341 wstyle
|= LVS_NOSORTHEADER
;
343 if ( style
& wxLC_NO_HEADER
)
344 wstyle
|= LVS_NOCOLUMNHEADER
;
346 if ( style
& wxLC_EDIT_LABELS
)
347 wstyle
|= LVS_EDITLABELS
;
349 if ( style
& wxLC_SINGLE_SEL
)
350 wstyle
|= LVS_SINGLESEL
;
352 if ( style
& wxLC_SORT_ASCENDING
)
354 if ( oldStyle
& LVS_SORTDESCENDING
)
355 oldStyle
-= LVS_SORTDESCENDING
;
356 wstyle
|= LVS_SORTASCENDING
;
359 if ( style
& wxLC_SORT_DESCENDING
)
361 if ( oldStyle
& LVS_SORTASCENDING
)
362 oldStyle
-= LVS_SORTASCENDING
;
363 wstyle
|= LVS_SORTDESCENDING
;
369 // ----------------------------------------------------------------------------
371 // ----------------------------------------------------------------------------
373 // Sets the background colour (GetBackgroundColour already implicit in
375 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
377 if ( !wxWindow::SetBackgroundColour(col
) )
380 ListView_SetBkColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
385 // Gets information about this column
386 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
391 lvCol
.pszText
= NULL
;
393 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
395 lvCol
.mask
|= LVCF_TEXT
;
396 lvCol
.pszText
= new wxChar
[513];
397 lvCol
.cchTextMax
= 512;
400 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
402 // item.m_subItem = lvCol.iSubItem;
403 item
.m_width
= lvCol
.cx
;
405 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
407 item
.m_text
= lvCol
.pszText
;
408 delete[] lvCol
.pszText
;
411 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
413 if (lvCol
.fmt
== LVCFMT_LEFT
)
414 item
.m_format
= wxLIST_FORMAT_LEFT
;
415 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
416 item
.m_format
= wxLIST_FORMAT_RIGHT
;
417 else if (lvCol
.fmt
== LVCFMT_CENTER
)
418 item
.m_format
= wxLIST_FORMAT_CENTRE
;
424 // Sets information about this column
425 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
430 lvCol
.pszText
= NULL
;
432 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
434 lvCol
.mask
|= LVCF_TEXT
;
435 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
436 lvCol
.cchTextMax
= 0; // Ignored
438 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
440 lvCol
.mask
|= LVCF_FMT
;
442 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
443 lvCol
.fmt
= LVCFMT_LEFT
;
444 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
445 lvCol
.fmt
= LVCFMT_RIGHT
;
446 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
447 lvCol
.fmt
= LVCFMT_CENTER
;
450 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
452 lvCol
.mask
|= LVCF_WIDTH
;
453 lvCol
.cx
= item
.m_width
;
455 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
456 lvCol
.cx
= LVSCW_AUTOSIZE
;
457 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
458 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
460 lvCol
.mask
|= LVCF_SUBITEM
;
461 lvCol
.iSubItem
= col
;
462 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
465 // Gets the column width
466 int wxListCtrl::GetColumnWidth(int col
) const
468 return ListView_GetColumnWidth(GetHwnd(), col
);
471 // Sets the column width
472 bool wxListCtrl::SetColumnWidth(int col
, int width
)
475 if ( m_windowStyle
& wxLC_LIST
)
479 if ( width2
== wxLIST_AUTOSIZE
)
480 width2
= LVSCW_AUTOSIZE
;
481 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
482 width2
= LVSCW_AUTOSIZE_USEHEADER
;
484 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
487 // Gets the number of items that can fit vertically in the
488 // visible area of the list control (list or report view)
489 // or the total number of items in the list control (icon
490 // or small icon view)
491 int wxListCtrl::GetCountPerPage(void) const
493 return ListView_GetCountPerPage(GetHwnd());
496 // Gets the edit control for editing labels.
497 wxTextCtrl
* wxListCtrl::GetEditControl(void) const
502 // Gets information about the item
503 bool wxListCtrl::GetItem(wxListItem
& info
) const
506 wxZeroMemory(lvItem
);
508 lvItem
.iItem
= info
.m_itemId
;
509 lvItem
.iSubItem
= info
.m_col
;
511 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
513 lvItem
.mask
|= LVIF_TEXT
;
514 lvItem
.pszText
= new wxChar
[513];
515 lvItem
.cchTextMax
= 512;
519 lvItem
.pszText
= NULL
;
522 if (info
.m_mask
& wxLIST_MASK_DATA
)
523 lvItem
.mask
|= LVIF_PARAM
;
525 if ( info
.m_mask
& wxLIST_MASK_STATE
)
527 lvItem
.mask
|= LVIF_STATE
;
528 // the other bits are hardly interesting anyhow
529 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
532 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
535 wxLogError(_("Couldn't retrieve information about list control item %d."),
540 wxConvertFromMSWListItem(this, info
, lvItem
);
544 delete[] lvItem
.pszText
;
549 // Sets information about the item
550 bool wxListCtrl::SetItem(wxListItem
& info
)
553 wxConvertToMSWListItem(this, info
, item
);
555 // check whether it has any custom attributes
556 if ( info
.HasAttributes() )
558 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
564 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
565 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
567 // make the change visible
568 ListView_Update(GetHwnd(), item
.iItem
);
574 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
578 info
.m_mask
= wxLIST_MASK_TEXT
;
579 info
.m_itemId
= index
;
583 info
.m_image
= imageId
;
584 info
.m_mask
|= wxLIST_MASK_IMAGE
;
586 return SetItem(info
);
590 // Gets the item state
591 int wxListCtrl::GetItemState(long item
, long stateMask
) const
595 info
.m_mask
= wxLIST_MASK_STATE
;
596 info
.m_stateMask
= stateMask
;
597 info
.m_itemId
= item
;
605 // Sets the item state
606 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
610 info
.m_mask
= wxLIST_MASK_STATE
;
611 info
.m_state
= state
;
612 info
.m_stateMask
= stateMask
;
613 info
.m_itemId
= item
;
615 return SetItem(info
);
618 // Sets the item image
619 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
623 info
.m_mask
= wxLIST_MASK_IMAGE
;
624 info
.m_image
= image
;
625 info
.m_itemId
= item
;
627 return SetItem(info
);
630 // Gets the item text
631 wxString
wxListCtrl::GetItemText(long item
) const
635 info
.m_mask
= wxLIST_MASK_TEXT
;
636 info
.m_itemId
= item
;
643 // Sets the item text
644 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
648 info
.m_mask
= wxLIST_MASK_TEXT
;
649 info
.m_itemId
= item
;
655 // Gets the item data
656 long wxListCtrl::GetItemData(long item
) const
660 info
.m_mask
= wxLIST_MASK_DATA
;
661 info
.m_itemId
= item
;
668 // Sets the item data
669 bool wxListCtrl::SetItemData(long item
, long data
)
673 info
.m_mask
= wxLIST_MASK_DATA
;
674 info
.m_itemId
= item
;
677 return SetItem(info
);
680 // Gets the item rectangle
681 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
685 int code2
= LVIR_BOUNDS
;
686 if ( code
== wxLIST_RECT_BOUNDS
)
688 else if ( code
== wxLIST_RECT_ICON
)
690 else if ( code
== wxLIST_RECT_LABEL
)
694 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
696 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
701 rect
.width
= rect2
.right
- rect2
.left
;
702 rect
.height
= rect2
.bottom
- rect2
.left
;
706 // Gets the item position
707 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
711 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
713 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
717 // Sets the item position.
718 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
720 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
723 // Gets the number of items in the list control
724 int wxListCtrl::GetItemCount(void) const
726 return ListView_GetItemCount(GetHwnd());
729 // Retrieves the spacing between icons in pixels.
730 // If small is TRUE, gets the spacing for the small icon
731 // view, otherwise the large icon view.
732 int wxListCtrl::GetItemSpacing(bool isSmall
) const
734 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
737 // Gets the number of selected items in the list control
738 int wxListCtrl::GetSelectedItemCount(void) const
740 return ListView_GetSelectedCount(GetHwnd());
743 // Gets the text colour of the listview
744 wxColour
wxListCtrl::GetTextColour(void) const
746 COLORREF ref
= ListView_GetTextColor(GetHwnd());
747 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
751 // Sets the text colour of the listview
752 void wxListCtrl::SetTextColour(const wxColour
& col
)
754 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
757 // Gets the index of the topmost visible item when in
758 // list or report view
759 long wxListCtrl::GetTopItem(void) const
761 return (long) ListView_GetTopIndex(GetHwnd());
764 // Searches for an item, starting from 'item'.
765 // 'geometry' is one of
766 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
767 // 'state' is a state bit flag, one or more of
768 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
769 // item can be -1 to find the first item that matches the
771 // Returns the item or -1 if unsuccessful.
772 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
776 if ( geom
== wxLIST_NEXT_ABOVE
)
778 if ( geom
== wxLIST_NEXT_ALL
)
780 if ( geom
== wxLIST_NEXT_BELOW
)
782 if ( geom
== wxLIST_NEXT_LEFT
)
783 flags
|= LVNI_TOLEFT
;
784 if ( geom
== wxLIST_NEXT_RIGHT
)
785 flags
|= LVNI_TORIGHT
;
787 if ( state
& wxLIST_STATE_CUT
)
789 if ( state
& wxLIST_STATE_DROPHILITED
)
790 flags
|= LVNI_DROPHILITED
;
791 if ( state
& wxLIST_STATE_FOCUSED
)
792 flags
|= LVNI_FOCUSED
;
793 if ( state
& wxLIST_STATE_SELECTED
)
794 flags
|= LVNI_SELECTED
;
796 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
800 wxImageList
*wxListCtrl::GetImageList(int which
) const
802 if ( which
== wxIMAGE_LIST_NORMAL
)
804 return m_imageListNormal
;
806 else if ( which
== wxIMAGE_LIST_SMALL
)
808 return m_imageListSmall
;
810 else if ( which
== wxIMAGE_LIST_STATE
)
812 return m_imageListState
;
817 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
820 if ( which
== wxIMAGE_LIST_NORMAL
)
822 flags
= LVSIL_NORMAL
;
823 m_imageListNormal
= imageList
;
825 else if ( which
== wxIMAGE_LIST_SMALL
)
828 m_imageListSmall
= imageList
;
830 else if ( which
== wxIMAGE_LIST_STATE
)
833 m_imageListState
= imageList
;
835 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
838 // ----------------------------------------------------------------------------
840 // ----------------------------------------------------------------------------
842 // Arranges the items
843 bool wxListCtrl::Arrange(int flag
)
846 if ( flag
== wxLIST_ALIGN_LEFT
)
847 code
= LVA_ALIGNLEFT
;
848 else if ( flag
== wxLIST_ALIGN_TOP
)
850 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
852 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
853 code
= LVA_SNAPTOGRID
;
855 return (ListView_Arrange(GetHwnd(), code
) != 0);
859 bool wxListCtrl::DeleteItem(long item
)
861 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
865 bool wxListCtrl::DeleteAllItems()
867 return (ListView_DeleteAllItems(GetHwnd()) != 0);
871 bool wxListCtrl::DeleteAllColumns()
873 while ( m_colCount
> 0 )
875 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
877 wxLogLastError("ListView_DeleteColumn");
885 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
891 bool wxListCtrl::DeleteColumn(int col
)
893 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
895 if ( success
&& (m_colCount
> 0) )
900 // Clears items, and columns if there are any.
901 void wxListCtrl::ClearAll()
904 if ( m_colCount
> 0 )
908 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
910 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
912 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
916 m_textCtrl
->UnsubclassWin();
917 m_textCtrl
->SetHWND(0);
922 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
923 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
924 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
929 // End label editing, optionally cancelling the edit
930 bool wxListCtrl::EndEditLabel(bool cancel
)
934 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
936 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
940 m_textCtrl->UnsubclassWin();
941 m_textCtrl->SetHWND(0);
951 // Ensures this item is visible
952 bool wxListCtrl::EnsureVisible(long item
)
954 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
957 // Find an item whose label matches this string, starting from the item after 'start'
958 // or the beginning if 'start' is -1.
959 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
961 LV_FINDINFO findInfo
;
963 findInfo
.flags
= LVFI_STRING
;
965 findInfo
.flags
|= LVFI_STRING
;
966 findInfo
.psz
= WXSTRINGCAST str
;
968 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
971 // Find an item whose data matches this data, starting from the item after 'start'
972 // or the beginning if 'start' is -1.
973 long wxListCtrl::FindItem(long start
, long data
)
975 LV_FINDINFO findInfo
;
977 findInfo
.flags
= LVFI_PARAM
;
978 findInfo
.lParam
= data
;
980 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
983 // Find an item nearest this position in the specified direction, starting from
984 // the item after 'start' or the beginning if 'start' is -1.
985 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
987 LV_FINDINFO findInfo
;
989 findInfo
.flags
= LVFI_NEARESTXY
;
990 findInfo
.pt
.x
= pt
.x
;
991 findInfo
.pt
.y
= pt
.y
;
992 findInfo
.vkDirection
= VK_RIGHT
;
994 if ( direction
== wxLIST_FIND_UP
)
995 findInfo
.vkDirection
= VK_UP
;
996 else if ( direction
== wxLIST_FIND_DOWN
)
997 findInfo
.vkDirection
= VK_DOWN
;
998 else if ( direction
== wxLIST_FIND_LEFT
)
999 findInfo
.vkDirection
= VK_LEFT
;
1000 else if ( direction
== wxLIST_FIND_RIGHT
)
1001 findInfo
.vkDirection
= VK_RIGHT
;
1003 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1006 // Determines which item (if any) is at the specified point,
1007 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1008 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1010 LV_HITTESTINFO hitTestInfo
;
1011 hitTestInfo
.pt
.x
= (int) point
.x
;
1012 hitTestInfo
.pt
.y
= (int) point
.y
;
1014 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1017 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1018 flags
|= wxLIST_HITTEST_ABOVE
;
1019 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1020 flags
|= wxLIST_HITTEST_BELOW
;
1021 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1022 flags
|= wxLIST_HITTEST_NOWHERE
;
1023 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1024 flags
|= wxLIST_HITTEST_ONITEMICON
;
1025 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1026 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1027 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1028 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1029 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1030 flags
|= wxLIST_HITTEST_TOLEFT
;
1031 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1032 flags
|= wxLIST_HITTEST_TORIGHT
;
1034 return (long) hitTestInfo
.iItem
;
1037 // Inserts an item, returning the index of the new item if successful,
1039 long wxListCtrl::InsertItem(wxListItem
& info
)
1042 wxConvertToMSWListItem(this, info
, item
);
1044 // check whether it has any custom attributes
1045 if ( info
.HasAttributes() )
1047 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1049 m_hasAnyAttr
= TRUE
;
1052 return (long) ListView_InsertItem(GetHwnd(), & item
);
1055 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1058 info
.m_text
= label
;
1059 info
.m_mask
= wxLIST_MASK_TEXT
;
1060 info
.m_itemId
= index
;
1061 return InsertItem(info
);
1064 // Inserts an image item
1065 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1068 info
.m_image
= imageIndex
;
1069 info
.m_mask
= wxLIST_MASK_IMAGE
;
1070 info
.m_itemId
= index
;
1071 return InsertItem(info
);
1074 // Inserts an image/string item
1075 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1078 info
.m_image
= imageIndex
;
1079 info
.m_text
= label
;
1080 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1081 info
.m_itemId
= index
;
1082 return InsertItem(info
);
1085 // For list view mode (only), inserts a column.
1086 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1091 lvCol
.pszText
= NULL
;
1093 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1095 lvCol
.mask
|= LVCF_TEXT
;
1096 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1097 lvCol
.cchTextMax
= 0; // Ignored
1099 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1101 lvCol
.mask
|= LVCF_FMT
;
1103 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1104 lvCol
.fmt
= LVCFMT_LEFT
;
1105 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1106 lvCol
.fmt
= LVCFMT_RIGHT
;
1107 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1108 lvCol
.fmt
= LVCFMT_CENTER
;
1111 lvCol
.mask
|= LVCF_WIDTH
;
1112 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1114 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1115 lvCol
.cx
= LVSCW_AUTOSIZE
;
1116 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1117 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1119 lvCol
.cx
= item
.m_width
;
1123 // always give some width to the new column: this one is compatible
1128 lvCol
.mask
|= LVCF_SUBITEM
;
1129 lvCol
.iSubItem
= col
;
1131 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1138 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1145 long wxListCtrl::InsertColumn(long col
,
1146 const wxString
& heading
,
1151 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1152 item
.m_text
= heading
;
1155 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1156 item
.m_width
= width
;
1158 item
.m_format
= format
;
1160 return InsertColumn(col
, item
);
1163 // Scrolls the list control. If in icon, small icon or report view mode,
1164 // x specifies the number of pixels to scroll. If in list view mode, x
1165 // specifies the number of columns to scroll.
1166 // If in icon, small icon or list view mode, y specifies the number of pixels
1167 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1168 bool wxListCtrl::ScrollList(int dx
, int dy
)
1170 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1175 // fn is a function which takes 3 long arguments: item1, item2, data.
1176 // item1 is the long data associated with a first item (NOT the index).
1177 // item2 is the long data associated with a second item (NOT the index).
1178 // data is the same value as passed to SortItems.
1179 // The return value is a negative number if the first item should precede the second
1180 // item, a positive number of the second item should precede the first,
1181 // or zero if the two items are equivalent.
1183 // data is arbitrary data to be passed to the sort function.
1184 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1186 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1189 // ----------------------------------------------------------------------------
1190 // message processing
1191 // ----------------------------------------------------------------------------
1193 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1195 if (cmd
== EN_UPDATE
)
1197 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1198 event
.SetEventObject( this );
1199 ProcessCommand(event
);
1202 else if (cmd
== EN_KILLFOCUS
)
1204 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1205 event
.SetEventObject( this );
1206 ProcessCommand(event
);
1213 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1215 // prepare the event
1216 // -----------------
1218 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1219 wxEventType eventType
= wxEVT_NULL
;
1220 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1221 switch ( nmhdr
->code
)
1223 case LVN_BEGINRDRAG
:
1224 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1228 if ( eventType
== wxEVT_NULL
)
1230 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1234 NM_LISTVIEW
*hdr
= (NM_LISTVIEW
*)lParam
;
1235 event
.m_itemIndex
= hdr
->iItem
;
1236 event
.m_pointDrag
.x
= hdr
->ptAction
.x
;
1237 event
.m_pointDrag
.y
= hdr
->ptAction
.y
;
1241 case LVN_BEGINLABELEDIT
:
1243 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1244 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1245 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1249 case LVN_COLUMNCLICK
:
1251 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1252 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1253 event
.m_itemIndex
= -1;
1254 event
.m_col
= hdr
->iSubItem
;
1258 case LVN_DELETEALLITEMS
:
1259 // what's the sense of generating a wxWin event for this when
1260 // it's absolutely not portable?
1262 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1263 event
.m_itemIndex
= -1;
1266 // return TRUE to suppress all additional LVN_DELETEITEM
1267 // notifications - this makes deleting all items from a list ctrl
1273 case LVN_DELETEITEM
:
1275 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1276 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1277 event
.m_itemIndex
= hdr
->iItem
;
1281 delete (wxListItemAttr
*)m_attrs
.Delete(hdr
->iItem
);
1286 case LVN_ENDLABELEDIT
:
1288 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1289 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1290 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1291 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1296 case LVN_SETDISPINFO
:
1298 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1299 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1300 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1304 case LVN_GETDISPINFO
:
1305 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1306 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1310 // TODO: some text buffering here, I think
1311 // TODO: API for getting Windows to retrieve values
1313 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1314 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1315 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1322 case LVN_INSERTITEM
:
1324 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1325 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1326 event
.m_itemIndex
= hdr
->iItem
;
1330 case LVN_ITEMCHANGED
:
1332 // This needs to be sent to wxListCtrl as a rather more
1333 // concrete event. For now, just detect a selection
1335 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1336 if ( (hdr
->uNewState
& LVIS_SELECTED
) && !(hdr
->uOldState
& LVIS_SELECTED
) )
1338 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1339 event
.m_itemIndex
= hdr
->iItem
;
1341 else if ( !(hdr
->uNewState
& LVIS_SELECTED
) && (hdr
->uOldState
& LVIS_SELECTED
) )
1343 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1344 event
.m_itemIndex
= hdr
->iItem
;
1353 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1354 WORD wVKey
= info
->wVKey
;
1356 // get the current selection
1357 long lItem
= GetNextItem(-1,
1359 wxLIST_STATE_SELECTED
);
1361 // <Enter> or <Space> activate the selected item if any
1362 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1364 // TODO this behaviour probably should be optional
1365 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1366 event
.m_itemIndex
= lItem
;
1370 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1371 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1377 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1379 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1384 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1386 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1387 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1388 event
.m_itemIndex
= hdr
->iItem
;
1393 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1394 subclass and check for the actual WM_RBUTTONDOWN message, because
1395 NM_RCLICK waits for the WM_RBUTTONUP message as well before firing off.
1396 We want to have notify events for both down -and- up. */
1398 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), don't do
1400 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) ) {
1404 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1405 LV_HITTESTINFO lvhti
;
1406 wxZeroMemory(lvhti
);
1408 ::GetCursorPos(&(lvhti
.pt
));
1409 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1410 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1412 if ( lvhti
.flags
& LVHT_ONITEM
)
1414 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1415 event
.m_itemIndex
= lvhti
.iItem
;
1422 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1424 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1426 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1431 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1432 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1433 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1434 event
.m_itemIndex
= hdr
->iItem
;
1439 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1442 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1443 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1444 switch( nmcd
.dwDrawStage
)
1447 // if we've got any items with non standard attributes,
1448 // notify us before painting each item
1449 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1453 case CDDS_ITEMPREPAINT
:
1455 wxListItemAttr
*attr
=
1456 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1460 // nothing to do for this item
1461 return CDRF_DODEFAULT
;
1465 wxColour colText
, colBack
;
1466 if ( attr
->HasFont() )
1468 wxFont font
= attr
->GetFont();
1469 hFont
= (HFONT
)font
.GetResourceHandle();
1476 if ( attr
->HasTextColour() )
1478 colText
= attr
->GetTextColour();
1482 colText
= GetTextColour();
1485 if ( attr
->HasBackgroundColour() )
1487 colBack
= attr
->GetBackgroundColour();
1491 colBack
= GetBackgroundColour();
1494 // note that if we wanted to set colours for
1495 // individual columns (subitems), we would have
1496 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1499 ::SelectObject(nmcd
.hdc
, hFont
);
1501 *result
= CDRF_NEWFONT
;
1505 *result
= CDRF_DODEFAULT
;
1508 lplvcd
->clrText
= wxColourToRGB(colText
);
1509 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1515 *result
= CDRF_DODEFAULT
;
1520 #endif // _WIN32_IE >= 0x300
1523 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1526 // process the event
1527 // -----------------
1529 event
.SetEventObject( this );
1530 event
.SetEventType(eventType
);
1532 if ( !GetEventHandler()->ProcessEvent(event
) )
1538 switch ( (int)nmhdr
->code
)
1540 case LVN_GETDISPINFO
:
1542 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1543 if ( info
->item
.mask
& LVIF_TEXT
)
1545 if ( !event
.m_item
.m_text
.IsNull() )
1547 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1548 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1551 // wxConvertToMSWListItem(this, event.m_item, info->item);
1554 case LVN_ENDLABELEDIT
:
1556 *result
= event
.IsAllowed();
1563 *result
= !event
.IsAllowed();
1568 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1570 // Remove the first element if 3 strings exist
1571 if ( m_stringPool
.Number() == 3 )
1573 wxNode
*node
= m_stringPool
.First();
1574 delete[] (char *)node
->Data();
1577 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1578 return (wxChar
*)node
->Data();
1581 // ----------------------------------------------------------------------------
1583 // ----------------------------------------------------------------------------
1585 // List item structure
1586 wxListItem::wxListItem()
1596 m_format
= wxLIST_FORMAT_CENTRE
;
1602 void wxListItem::Clear()
1611 m_format
= wxLIST_FORMAT_CENTRE
;
1613 m_text
= wxEmptyString
;
1615 if (m_attr
) delete m_attr
;
1619 void wxListItem::ClearAttributes()
1621 if (m_attr
) delete m_attr
;
1625 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1627 info
.m_data
= lvItem
.lParam
;
1630 info
.m_stateMask
= 0;
1631 info
.m_itemId
= lvItem
.iItem
;
1633 long oldMask
= lvItem
.mask
;
1635 bool needText
= FALSE
;
1636 if (getFullInfo
!= 0)
1638 if ( lvItem
.mask
& LVIF_TEXT
)
1645 lvItem
.pszText
= new wxChar
[513];
1646 lvItem
.cchTextMax
= 512;
1648 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1649 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1650 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1653 if ( lvItem
.mask
& LVIF_STATE
)
1655 info
.m_mask
|= wxLIST_MASK_STATE
;
1657 if ( lvItem
.stateMask
& LVIS_CUT
)
1659 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1660 if ( lvItem
.state
& LVIS_CUT
)
1661 info
.m_state
|= wxLIST_STATE_CUT
;
1663 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1665 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1666 if ( lvItem
.state
& LVIS_DROPHILITED
)
1667 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1669 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1671 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1672 if ( lvItem
.state
& LVIS_FOCUSED
)
1673 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1675 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1677 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1678 if ( lvItem
.state
& LVIS_SELECTED
)
1679 info
.m_state
|= wxLIST_STATE_SELECTED
;
1683 if ( lvItem
.mask
& LVIF_TEXT
)
1685 info
.m_mask
|= wxLIST_MASK_TEXT
;
1686 info
.m_text
= lvItem
.pszText
;
1688 if ( lvItem
.mask
& LVIF_IMAGE
)
1690 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1691 info
.m_image
= lvItem
.iImage
;
1693 if ( lvItem
.mask
& LVIF_PARAM
)
1694 info
.m_mask
|= wxLIST_MASK_DATA
;
1695 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1696 info
.m_mask
|= wxLIST_SET_ITEM
;
1697 info
.m_col
= lvItem
.iSubItem
;
1702 delete[] lvItem
.pszText
;
1704 lvItem
.mask
= oldMask
;
1707 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1709 lvItem
.iItem
= (int) info
.m_itemId
;
1711 lvItem
.iImage
= info
.m_image
;
1712 lvItem
.lParam
= info
.m_data
;
1713 lvItem
.stateMask
= 0;
1716 lvItem
.iSubItem
= info
.m_col
;
1718 if (info
.m_mask
& wxLIST_MASK_STATE
)
1720 lvItem
.mask
|= LVIF_STATE
;
1721 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1723 lvItem
.stateMask
|= LVIS_CUT
;
1724 if (info
.m_state
& wxLIST_STATE_CUT
)
1725 lvItem
.state
|= LVIS_CUT
;
1727 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1729 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1730 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1731 lvItem
.state
|= LVIS_DROPHILITED
;
1733 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1735 lvItem
.stateMask
|= LVIS_FOCUSED
;
1736 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1737 lvItem
.state
|= LVIS_FOCUSED
;
1739 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1741 lvItem
.stateMask
|= LVIS_SELECTED
;
1742 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1743 lvItem
.state
|= LVIS_SELECTED
;
1747 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1749 lvItem
.mask
|= LVIF_TEXT
;
1750 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1752 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1756 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1757 if ( lvItem
.pszText
)
1758 lvItem
.cchTextMax
= info
.m_text
.Length();
1760 lvItem
.cchTextMax
= 0;
1763 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1764 lvItem
.mask
|= LVIF_IMAGE
;
1765 if (info
.m_mask
& wxLIST_MASK_DATA
)
1766 lvItem
.mask
|= LVIF_PARAM
;
1769 // ----------------------------------------------------------------------------
1771 // ----------------------------------------------------------------------------
1773 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1775 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1776 : wxNotifyEvent(commandType
, id
)
1782 m_cancelled
= FALSE
;