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 m_textCtrl
->UnsubclassWin();
210 m_textCtrl
->SetHWND(0);
216 // ----------------------------------------------------------------------------
217 // set/get/change style
218 // ----------------------------------------------------------------------------
220 // Add or remove a single window style
221 void wxListCtrl::SetSingleStyle(long style
, bool add
)
223 long flag
= GetWindowStyleFlag();
225 // Get rid of conflicting styles
228 if ( style
& wxLC_MASK_TYPE
)
229 flag
= flag
& ~wxLC_MASK_TYPE
;
230 if ( style
& wxLC_MASK_ALIGN
)
231 flag
= flag
& ~wxLC_MASK_ALIGN
;
232 if ( style
& wxLC_MASK_SORT
)
233 flag
= flag
& ~wxLC_MASK_SORT
;
249 m_windowStyle
= flag
;
254 // Set the whole window style
255 void wxListCtrl::SetWindowStyleFlag(long flag
)
257 m_windowStyle
= flag
;
262 // Can be just a single style, or a bitlist
263 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
266 if ( style
& wxLC_ICON
)
268 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
269 oldStyle
-= LVS_SMALLICON
;
270 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
271 oldStyle
-= LVS_REPORT
;
272 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
273 oldStyle
-= LVS_LIST
;
277 if ( style
& wxLC_SMALL_ICON
)
279 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
280 oldStyle
-= LVS_ICON
;
281 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
282 oldStyle
-= LVS_REPORT
;
283 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
284 oldStyle
-= LVS_LIST
;
285 wstyle
|= LVS_SMALLICON
;
288 if ( style
& wxLC_LIST
)
290 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
291 oldStyle
-= LVS_ICON
;
292 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
293 oldStyle
-= LVS_REPORT
;
294 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
295 oldStyle
-= LVS_SMALLICON
;
299 if ( style
& wxLC_REPORT
)
301 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
302 oldStyle
-= LVS_ICON
;
303 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
304 oldStyle
-= LVS_LIST
;
305 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
306 oldStyle
-= LVS_SMALLICON
;
308 wstyle
|= LVS_REPORT
;
311 if ( style
& wxLC_ALIGN_LEFT
)
313 if ( oldStyle
& LVS_ALIGNTOP
)
314 oldStyle
-= LVS_ALIGNTOP
;
315 wstyle
|= LVS_ALIGNLEFT
;
318 if ( style
& wxLC_ALIGN_TOP
)
320 if ( oldStyle
& LVS_ALIGNLEFT
)
321 oldStyle
-= LVS_ALIGNLEFT
;
322 wstyle
|= LVS_ALIGNTOP
;
325 if ( style
& wxLC_AUTOARRANGE
)
326 wstyle
|= LVS_AUTOARRANGE
;
328 // Apparently, no such style (documentation wrong?)
330 if ( style & wxLC_BUTTON )
331 wstyle |= LVS_BUTTON;
334 if ( style
& wxLC_NO_SORT_HEADER
)
335 wstyle
|= LVS_NOSORTHEADER
;
337 if ( style
& wxLC_NO_HEADER
)
338 wstyle
|= LVS_NOCOLUMNHEADER
;
340 if ( style
& wxLC_EDIT_LABELS
)
341 wstyle
|= LVS_EDITLABELS
;
343 if ( style
& wxLC_SINGLE_SEL
)
344 wstyle
|= LVS_SINGLESEL
;
346 if ( style
& wxLC_SORT_ASCENDING
)
348 if ( oldStyle
& LVS_SORTDESCENDING
)
349 oldStyle
-= LVS_SORTDESCENDING
;
350 wstyle
|= LVS_SORTASCENDING
;
353 if ( style
& wxLC_SORT_DESCENDING
)
355 if ( oldStyle
& LVS_SORTASCENDING
)
356 oldStyle
-= LVS_SORTASCENDING
;
357 wstyle
|= LVS_SORTDESCENDING
;
363 // ----------------------------------------------------------------------------
365 // ----------------------------------------------------------------------------
367 // Sets the background colour (GetBackgroundColour already implicit in
369 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
371 if ( !wxWindow::SetBackgroundColour(col
) )
374 ListView_SetBkColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
379 // Gets information about this column
380 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
385 lvCol
.pszText
= NULL
;
387 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
389 lvCol
.mask
|= LVCF_TEXT
;
390 lvCol
.pszText
= new wxChar
[513];
391 lvCol
.cchTextMax
= 512;
394 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
396 // item.m_subItem = lvCol.iSubItem;
397 item
.m_width
= lvCol
.cx
;
399 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
401 item
.m_text
= lvCol
.pszText
;
402 delete[] lvCol
.pszText
;
405 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
407 if (lvCol
.fmt
== LVCFMT_LEFT
)
408 item
.m_format
= wxLIST_FORMAT_LEFT
;
409 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
410 item
.m_format
= wxLIST_FORMAT_RIGHT
;
411 else if (lvCol
.fmt
== LVCFMT_CENTER
)
412 item
.m_format
= wxLIST_FORMAT_CENTRE
;
418 // Sets information about this column
419 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
424 lvCol
.pszText
= NULL
;
426 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
428 lvCol
.mask
|= LVCF_TEXT
;
429 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
430 lvCol
.cchTextMax
= 0; // Ignored
432 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
434 lvCol
.mask
|= LVCF_FMT
;
436 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
437 lvCol
.fmt
= LVCFMT_LEFT
;
438 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
439 lvCol
.fmt
= LVCFMT_RIGHT
;
440 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
441 lvCol
.fmt
= LVCFMT_CENTER
;
444 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
446 lvCol
.mask
|= LVCF_WIDTH
;
447 lvCol
.cx
= item
.m_width
;
449 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
450 lvCol
.cx
= LVSCW_AUTOSIZE
;
451 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
452 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
454 lvCol
.mask
|= LVCF_SUBITEM
;
455 lvCol
.iSubItem
= col
;
456 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
459 // Gets the column width
460 int wxListCtrl::GetColumnWidth(int col
) const
462 return ListView_GetColumnWidth(GetHwnd(), col
);
465 // Sets the column width
466 bool wxListCtrl::SetColumnWidth(int col
, int width
)
469 if ( m_windowStyle
& wxLC_LIST
)
473 if ( width2
== wxLIST_AUTOSIZE
)
474 width2
= LVSCW_AUTOSIZE
;
475 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
476 width2
= LVSCW_AUTOSIZE_USEHEADER
;
478 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
481 // Gets the number of items that can fit vertically in the
482 // visible area of the list control (list or report view)
483 // or the total number of items in the list control (icon
484 // or small icon view)
485 int wxListCtrl::GetCountPerPage(void) const
487 return ListView_GetCountPerPage(GetHwnd());
490 // Gets the edit control for editing labels.
491 wxTextCtrl
* wxListCtrl::GetEditControl(void) const
496 // Gets information about the item
497 bool wxListCtrl::GetItem(wxListItem
& info
) const
500 wxZeroMemory(lvItem
);
502 lvItem
.iItem
= info
.m_itemId
;
503 lvItem
.iSubItem
= info
.m_col
;
505 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
507 lvItem
.mask
|= LVIF_TEXT
;
508 lvItem
.pszText
= new wxChar
[513];
509 lvItem
.cchTextMax
= 512;
513 lvItem
.pszText
= NULL
;
516 if (info
.m_mask
& wxLIST_MASK_DATA
)
517 lvItem
.mask
|= LVIF_PARAM
;
519 if ( info
.m_mask
& wxLIST_MASK_STATE
)
521 lvItem
.mask
|= LVIF_STATE
;
522 // the other bits are hardly interesting anyhow
523 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
526 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
529 wxLogError(_("Couldn't retrieve information about list control item %d."),
534 wxConvertFromMSWListItem(this, info
, lvItem
);
538 delete[] lvItem
.pszText
;
543 // Sets information about the item
544 bool wxListCtrl::SetItem(wxListItem
& info
)
547 wxConvertToMSWListItem(this, info
, item
);
549 // check whether it has any custom attributes
550 if ( info
.HasAttributes() )
552 // FIXME it should be...
553 wxASSERT_MSG( !info
.GetData(),
554 _T("can't have custom attributes and client data") );
556 item
.mask
|= LVIF_PARAM
;
557 item
.lParam
= (long)info
.GetAttributes();
561 else if ( m_hasAnyAttr
)
563 item
.mask
|= LVIF_PARAM
;
568 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
569 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
571 // make the change visible
572 ListView_Update(GetHwnd(), item
.iItem
);
578 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
582 info
.m_mask
= wxLIST_MASK_TEXT
;
583 info
.m_itemId
= index
;
587 info
.m_image
= imageId
;
588 info
.m_mask
|= wxLIST_MASK_IMAGE
;
590 return SetItem(info
);
594 // Gets the item state
595 int wxListCtrl::GetItemState(long item
, long stateMask
) const
599 info
.m_mask
= wxLIST_MASK_STATE
;
600 info
.m_stateMask
= stateMask
;
601 info
.m_itemId
= item
;
609 // Sets the item state
610 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
614 info
.m_mask
= wxLIST_MASK_STATE
;
615 info
.m_state
= state
;
616 info
.m_stateMask
= stateMask
;
617 info
.m_itemId
= item
;
619 return SetItem(info
);
622 // Sets the item image
623 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
627 info
.m_mask
= wxLIST_MASK_IMAGE
;
628 info
.m_image
= image
;
629 info
.m_itemId
= item
;
631 return SetItem(info
);
634 // Gets the item text
635 wxString
wxListCtrl::GetItemText(long item
) const
639 info
.m_mask
= wxLIST_MASK_TEXT
;
640 info
.m_itemId
= item
;
647 // Sets the item text
648 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
652 info
.m_mask
= wxLIST_MASK_TEXT
;
653 info
.m_itemId
= item
;
659 // Gets the item data
660 long wxListCtrl::GetItemData(long item
) const
664 info
.m_mask
= wxLIST_MASK_DATA
;
665 info
.m_itemId
= item
;
672 // Sets the item data
673 bool wxListCtrl::SetItemData(long item
, long data
)
677 info
.m_mask
= wxLIST_MASK_DATA
;
678 info
.m_itemId
= item
;
681 return SetItem(info
);
684 // Gets the item rectangle
685 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
689 int code2
= LVIR_BOUNDS
;
690 if ( code
== wxLIST_RECT_BOUNDS
)
692 else if ( code
== wxLIST_RECT_ICON
)
694 else if ( code
== wxLIST_RECT_LABEL
)
698 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
700 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
705 rect
.width
= rect2
.right
- rect2
.left
;
706 rect
.height
= rect2
.bottom
- rect2
.left
;
710 // Gets the item position
711 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
715 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
717 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
721 // Sets the item position.
722 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
724 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
727 // Gets the number of items in the list control
728 int wxListCtrl::GetItemCount(void) const
730 return ListView_GetItemCount(GetHwnd());
733 // Retrieves the spacing between icons in pixels.
734 // If small is TRUE, gets the spacing for the small icon
735 // view, otherwise the large icon view.
736 int wxListCtrl::GetItemSpacing(bool isSmall
) const
738 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
741 // Gets the number of selected items in the list control
742 int wxListCtrl::GetSelectedItemCount(void) const
744 return ListView_GetSelectedCount(GetHwnd());
747 // Gets the text colour of the listview
748 wxColour
wxListCtrl::GetTextColour(void) const
750 COLORREF ref
= ListView_GetTextColor(GetHwnd());
751 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
755 // Sets the text colour of the listview
756 void wxListCtrl::SetTextColour(const wxColour
& col
)
758 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
761 // Gets the index of the topmost visible item when in
762 // list or report view
763 long wxListCtrl::GetTopItem(void) const
765 return (long) ListView_GetTopIndex(GetHwnd());
768 // Searches for an item, starting from 'item'.
769 // 'geometry' is one of
770 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
771 // 'state' is a state bit flag, one or more of
772 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
773 // item can be -1 to find the first item that matches the
775 // Returns the item or -1 if unsuccessful.
776 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
780 if ( geom
== wxLIST_NEXT_ABOVE
)
782 if ( geom
== wxLIST_NEXT_ALL
)
784 if ( geom
== wxLIST_NEXT_BELOW
)
786 if ( geom
== wxLIST_NEXT_LEFT
)
787 flags
|= LVNI_TOLEFT
;
788 if ( geom
== wxLIST_NEXT_RIGHT
)
789 flags
|= LVNI_TORIGHT
;
791 if ( state
& wxLIST_STATE_CUT
)
793 if ( state
& wxLIST_STATE_DROPHILITED
)
794 flags
|= LVNI_DROPHILITED
;
795 if ( state
& wxLIST_STATE_FOCUSED
)
796 flags
|= LVNI_FOCUSED
;
797 if ( state
& wxLIST_STATE_SELECTED
)
798 flags
|= LVNI_SELECTED
;
800 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
804 wxImageList
*wxListCtrl::GetImageList(int which
) const
806 if ( which
== wxIMAGE_LIST_NORMAL
)
808 return m_imageListNormal
;
810 else if ( which
== wxIMAGE_LIST_SMALL
)
812 return m_imageListSmall
;
814 else if ( which
== wxIMAGE_LIST_STATE
)
816 return m_imageListState
;
821 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
824 if ( which
== wxIMAGE_LIST_NORMAL
)
826 flags
= LVSIL_NORMAL
;
827 m_imageListNormal
= imageList
;
829 else if ( which
== wxIMAGE_LIST_SMALL
)
832 m_imageListSmall
= imageList
;
834 else if ( which
== wxIMAGE_LIST_STATE
)
837 m_imageListState
= imageList
;
839 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
842 // ----------------------------------------------------------------------------
844 // ----------------------------------------------------------------------------
846 // Arranges the items
847 bool wxListCtrl::Arrange(int flag
)
850 if ( flag
== wxLIST_ALIGN_LEFT
)
851 code
= LVA_ALIGNLEFT
;
852 else if ( flag
== wxLIST_ALIGN_TOP
)
854 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
856 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
857 code
= LVA_SNAPTOGRID
;
859 return (ListView_Arrange(GetHwnd(), code
) != 0);
863 bool wxListCtrl::DeleteItem(long item
)
865 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
869 bool wxListCtrl::DeleteAllItems()
871 return (ListView_DeleteAllItems(GetHwnd()) != 0);
875 bool wxListCtrl::DeleteAllColumns()
877 while ( m_colCount
> 0 )
879 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
881 wxLogLastError("ListView_DeleteColumn");
889 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
895 bool wxListCtrl::DeleteColumn(int col
)
897 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
899 if ( success
&& (m_colCount
> 0) )
904 // Clears items, and columns if there are any.
905 void wxListCtrl::ClearAll()
908 if ( m_colCount
> 0 )
912 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
914 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
916 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
920 m_textCtrl
->UnsubclassWin();
921 m_textCtrl
->SetHWND(0);
926 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
927 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
928 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
933 // End label editing, optionally cancelling the edit
934 bool wxListCtrl::EndEditLabel(bool cancel
)
938 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
940 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
944 m_textCtrl->UnsubclassWin();
945 m_textCtrl->SetHWND(0);
955 // Ensures this item is visible
956 bool wxListCtrl::EnsureVisible(long item
)
958 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
961 // Find an item whose label matches this string, starting from the item after 'start'
962 // or the beginning if 'start' is -1.
963 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
965 LV_FINDINFO findInfo
;
967 findInfo
.flags
= LVFI_STRING
;
969 findInfo
.flags
|= LVFI_STRING
;
970 findInfo
.psz
= WXSTRINGCAST str
;
972 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
975 // Find an item whose data matches this data, starting from the item after 'start'
976 // or the beginning if 'start' is -1.
977 long wxListCtrl::FindItem(long start
, long data
)
979 LV_FINDINFO findInfo
;
981 findInfo
.flags
= LVFI_PARAM
;
982 findInfo
.lParam
= data
;
984 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
987 // Find an item nearest this position in the specified direction, starting from
988 // the item after 'start' or the beginning if 'start' is -1.
989 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
991 LV_FINDINFO findInfo
;
993 findInfo
.flags
= LVFI_NEARESTXY
;
994 findInfo
.pt
.x
= pt
.x
;
995 findInfo
.pt
.y
= pt
.y
;
996 findInfo
.vkDirection
= VK_RIGHT
;
998 if ( direction
== wxLIST_FIND_UP
)
999 findInfo
.vkDirection
= VK_UP
;
1000 else if ( direction
== wxLIST_FIND_DOWN
)
1001 findInfo
.vkDirection
= VK_DOWN
;
1002 else if ( direction
== wxLIST_FIND_LEFT
)
1003 findInfo
.vkDirection
= VK_LEFT
;
1004 else if ( direction
== wxLIST_FIND_RIGHT
)
1005 findInfo
.vkDirection
= VK_RIGHT
;
1007 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1010 // Determines which item (if any) is at the specified point,
1011 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1012 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1014 LV_HITTESTINFO hitTestInfo
;
1015 hitTestInfo
.pt
.x
= (int) point
.x
;
1016 hitTestInfo
.pt
.y
= (int) point
.y
;
1018 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1021 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1022 flags
|= wxLIST_HITTEST_ABOVE
;
1023 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1024 flags
|= wxLIST_HITTEST_BELOW
;
1025 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1026 flags
|= wxLIST_HITTEST_NOWHERE
;
1027 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1028 flags
|= wxLIST_HITTEST_ONITEMICON
;
1029 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1030 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1031 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1032 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1033 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1034 flags
|= wxLIST_HITTEST_TOLEFT
;
1035 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1036 flags
|= wxLIST_HITTEST_TORIGHT
;
1038 return (long) hitTestInfo
.iItem
;
1041 // Inserts an item, returning the index of the new item if successful,
1043 long wxListCtrl::InsertItem(wxListItem
& info
)
1046 wxConvertToMSWListItem(this, info
, item
);
1048 // check whether it has any custom attributes
1049 if ( info
.HasAttributes() )
1051 // FIXME it should be...
1052 wxASSERT_MSG( !info
.GetData(),
1053 _T("can't have custom attributes and client data") );
1055 item
.mask
|= LVIF_PARAM
;
1056 item
.lParam
= (long)info
.GetAttributes();
1058 m_hasAnyAttr
= TRUE
;
1060 else if ( m_hasAnyAttr
)
1062 item
.mask
|= LVIF_PARAM
;
1066 return (long) ListView_InsertItem(GetHwnd(), & item
);
1069 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1072 info
.m_text
= label
;
1073 info
.m_mask
= wxLIST_MASK_TEXT
;
1074 info
.m_itemId
= index
;
1075 return InsertItem(info
);
1078 // Inserts an image item
1079 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1082 info
.m_image
= imageIndex
;
1083 info
.m_mask
= wxLIST_MASK_IMAGE
;
1084 info
.m_itemId
= index
;
1085 return InsertItem(info
);
1088 // Inserts an image/string item
1089 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1092 info
.m_image
= imageIndex
;
1093 info
.m_text
= label
;
1094 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1095 info
.m_itemId
= index
;
1096 return InsertItem(info
);
1099 // For list view mode (only), inserts a column.
1100 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1105 lvCol
.pszText
= NULL
;
1107 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1109 lvCol
.mask
|= LVCF_TEXT
;
1110 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1111 lvCol
.cchTextMax
= 0; // Ignored
1113 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1115 lvCol
.mask
|= LVCF_FMT
;
1117 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1118 lvCol
.fmt
= LVCFMT_LEFT
;
1119 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1120 lvCol
.fmt
= LVCFMT_RIGHT
;
1121 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1122 lvCol
.fmt
= LVCFMT_CENTER
;
1125 lvCol
.mask
|= LVCF_WIDTH
;
1126 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1128 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1129 lvCol
.cx
= LVSCW_AUTOSIZE
;
1130 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1131 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1133 lvCol
.cx
= item
.m_width
;
1137 // always give some width to the new column: this one is compatible
1142 lvCol
.mask
|= LVCF_SUBITEM
;
1143 lvCol
.iSubItem
= col
;
1145 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1152 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1159 long wxListCtrl::InsertColumn(long col
,
1160 const wxString
& heading
,
1165 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1166 item
.m_text
= heading
;
1169 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1170 item
.m_width
= width
;
1172 item
.m_format
= format
;
1174 return InsertColumn(col
, item
);
1177 // Scrolls the list control. If in icon, small icon or report view mode,
1178 // x specifies the number of pixels to scroll. If in list view mode, x
1179 // specifies the number of columns to scroll.
1180 // If in icon, small icon or list view mode, y specifies the number of pixels
1181 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1182 bool wxListCtrl::ScrollList(int dx
, int dy
)
1184 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1189 // fn is a function which takes 3 long arguments: item1, item2, data.
1190 // item1 is the long data associated with a first item (NOT the index).
1191 // item2 is the long data associated with a second item (NOT the index).
1192 // data is the same value as passed to SortItems.
1193 // The return value is a negative number if the first item should precede the second
1194 // item, a positive number of the second item should precede the first,
1195 // or zero if the two items are equivalent.
1197 // data is arbitrary data to be passed to the sort function.
1198 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1200 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1203 // ----------------------------------------------------------------------------
1204 // message processing
1205 // ----------------------------------------------------------------------------
1207 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1209 if (cmd
== EN_UPDATE
)
1211 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1212 event
.SetEventObject( this );
1213 ProcessCommand(event
);
1216 else if (cmd
== EN_KILLFOCUS
)
1218 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1219 event
.SetEventObject( this );
1220 ProcessCommand(event
);
1227 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1229 // prepare the event
1230 // -----------------
1232 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1233 wxEventType eventType
= wxEVT_NULL
;
1234 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1235 switch ( nmhdr
->code
)
1237 case LVN_BEGINRDRAG
:
1238 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1242 if ( eventType
== wxEVT_NULL
)
1244 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1248 NM_LISTVIEW
*hdr
= (NM_LISTVIEW
*)lParam
;
1249 event
.m_itemIndex
= hdr
->iItem
;
1250 event
.m_pointDrag
.x
= hdr
->ptAction
.x
;
1251 event
.m_pointDrag
.y
= hdr
->ptAction
.y
;
1255 case LVN_BEGINLABELEDIT
:
1257 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1258 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1259 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1263 case LVN_COLUMNCLICK
:
1265 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1266 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1267 event
.m_itemIndex
= -1;
1268 event
.m_col
= hdr
->iSubItem
;
1272 case LVN_DELETEALLITEMS
:
1273 // what's the sense of generating a wxWin event for this when
1274 // it's absolutely not portable?
1276 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1277 event
.m_itemIndex
= -1;
1280 // return TRUE to suppress all additional LVN_DELETEITEM
1281 // notifications - this makes deleting all items from a list ctrl
1282 // much faster (but we can't do it if we have any custom drawn
1283 // items because we need to delete their attributes in
1284 // LVN_DELETEITEM below)
1285 if ( !m_hasAnyAttr
)
1293 case LVN_DELETEITEM
:
1295 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1296 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1297 event
.m_itemIndex
= hdr
->iItem
;
1301 wxListItemAttr
*attr
= (wxListItemAttr
*)hdr
->lParam
;
1307 case LVN_ENDLABELEDIT
:
1309 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1310 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1311 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1312 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1317 case LVN_SETDISPINFO
:
1319 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1320 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1321 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1325 case LVN_GETDISPINFO
:
1326 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1327 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1331 // TODO: some text buffering here, I think
1332 // TODO: API for getting Windows to retrieve values
1334 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1335 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1336 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1343 case LVN_INSERTITEM
:
1345 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1346 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1347 event
.m_itemIndex
= hdr
->iItem
;
1351 case LVN_ITEMCHANGED
:
1353 // This needs to be sent to wxListCtrl as a rather more
1354 // concrete event. For now, just detect a selection
1356 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1357 if ( (hdr
->uNewState
& LVIS_SELECTED
) && !(hdr
->uOldState
& LVIS_SELECTED
) )
1359 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1360 event
.m_itemIndex
= hdr
->iItem
;
1362 else if ( !(hdr
->uNewState
& LVIS_SELECTED
) && (hdr
->uOldState
& LVIS_SELECTED
) )
1364 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1365 event
.m_itemIndex
= hdr
->iItem
;
1374 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1375 WORD wVKey
= info
->wVKey
;
1377 // get the current selection
1378 long lItem
= GetNextItem(-1,
1380 wxLIST_STATE_SELECTED
);
1382 // <Enter> or <Space> activate the selected item if any
1383 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1385 // TODO this behaviour probably should be optional
1386 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1387 event
.m_itemIndex
= lItem
;
1391 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1392 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1398 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1400 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1405 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1407 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1408 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1409 event
.m_itemIndex
= hdr
->iItem
;
1414 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1415 subclass and check for the actual WM_RBUTTONDOWN message, because
1416 NM_RCLICK waits for the WM_RBUTTONUP message as well before firing off.
1417 We want to have notify events for both down -and- up. */
1419 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), don't do
1421 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) ) {
1425 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1426 LV_HITTESTINFO lvhti
;
1427 wxZeroMemory(lvhti
);
1429 ::GetCursorPos(&(lvhti
.pt
));
1430 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1431 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1433 if ( lvhti
.flags
& LVHT_ONITEM
)
1435 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1436 event
.m_itemIndex
= lvhti
.iItem
;
1443 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1445 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1447 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1452 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1453 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1454 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1455 event
.m_itemIndex
= hdr
->iItem
;
1460 #ifdef NM_CUSTOMDRAW
1463 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1464 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1465 switch( nmcd
.dwDrawStage
)
1467 case CDDS_PREPAINT
:
1468 // if we've got any items with non standard attributes,
1469 // notify us before painting each item
1470 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1474 case CDDS_ITEMPREPAINT
:
1476 if ( !nmcd
.lItemlParam
)
1478 // nothing to do for this item
1479 return CDRF_DODEFAULT
;
1482 wxListItemAttr
*attr
=
1483 (wxListItemAttr
*)nmcd
.lItemlParam
;
1485 ::SelectObject(nmcd
.hdc
,
1486 (HFONT
)((wxFont
&)attr
->GetFont()).
1487 GetResourceHandle());
1489 wxColourToRGB(attr
->GetTextColour());
1491 wxColourToRGB(attr
->GetBackgroundColour());
1493 // if we wanted to set colours for individual
1494 // columns (subitems), we would have returned
1495 // CDRF_NOTIFYSUBITEMREDRAW from here
1496 *result
= CDRF_NEWFONT
;
1503 #endif // NM_CUSTOMDRAW
1506 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1509 // process the event
1510 // -----------------
1512 event
.SetEventObject( this );
1513 event
.SetEventType(eventType
);
1515 if ( !GetEventHandler()->ProcessEvent(event
) )
1521 switch ( (int)nmhdr
->code
)
1523 case LVN_GETDISPINFO
:
1525 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1526 if ( info
->item
.mask
& LVIF_TEXT
)
1528 if ( !event
.m_item
.m_text
.IsNull() )
1530 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1531 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1534 // wxConvertToMSWListItem(this, event.m_item, info->item);
1537 case LVN_ENDLABELEDIT
:
1539 *result
= event
.IsAllowed();
1546 *result
= !event
.IsAllowed();
1551 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1553 // Remove the first element if 3 strings exist
1554 if ( m_stringPool
.Number() == 3 )
1556 wxNode
*node
= m_stringPool
.First();
1557 delete[] (char *)node
->Data();
1560 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1561 return (wxChar
*)node
->Data();
1564 // ----------------------------------------------------------------------------
1566 // ----------------------------------------------------------------------------
1568 // List item structure
1569 wxListItem::wxListItem()
1579 m_format
= wxLIST_FORMAT_CENTRE
;
1585 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1587 info
.m_data
= lvItem
.lParam
;
1590 info
.m_stateMask
= 0;
1591 info
.m_itemId
= lvItem
.iItem
;
1593 long oldMask
= lvItem
.mask
;
1595 bool needText
= FALSE
;
1596 if (getFullInfo
!= 0)
1598 if ( lvItem
.mask
& LVIF_TEXT
)
1605 lvItem
.pszText
= new wxChar
[513];
1606 lvItem
.cchTextMax
= 512;
1608 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1609 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1610 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1613 if ( lvItem
.mask
& LVIF_STATE
)
1615 info
.m_mask
|= wxLIST_MASK_STATE
;
1617 if ( lvItem
.stateMask
& LVIS_CUT
)
1619 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1620 if ( lvItem
.state
& LVIS_CUT
)
1621 info
.m_state
|= wxLIST_STATE_CUT
;
1623 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1625 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1626 if ( lvItem
.state
& LVIS_DROPHILITED
)
1627 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1629 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1631 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1632 if ( lvItem
.state
& LVIS_FOCUSED
)
1633 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1635 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1637 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1638 if ( lvItem
.state
& LVIS_SELECTED
)
1639 info
.m_state
|= wxLIST_STATE_SELECTED
;
1643 if ( lvItem
.mask
& LVIF_TEXT
)
1645 info
.m_mask
|= wxLIST_MASK_TEXT
;
1646 info
.m_text
= lvItem
.pszText
;
1648 if ( lvItem
.mask
& LVIF_IMAGE
)
1650 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1651 info
.m_image
= lvItem
.iImage
;
1653 if ( lvItem
.mask
& LVIF_PARAM
)
1654 info
.m_mask
|= wxLIST_MASK_DATA
;
1655 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1656 info
.m_mask
|= wxLIST_SET_ITEM
;
1657 info
.m_col
= lvItem
.iSubItem
;
1662 delete[] lvItem
.pszText
;
1664 lvItem
.mask
= oldMask
;
1667 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1669 lvItem
.iItem
= (int) info
.m_itemId
;
1671 lvItem
.iImage
= info
.m_image
;
1672 lvItem
.lParam
= info
.m_data
;
1673 lvItem
.stateMask
= 0;
1676 lvItem
.iSubItem
= info
.m_col
;
1678 if (info
.m_mask
& wxLIST_MASK_STATE
)
1680 lvItem
.mask
|= LVIF_STATE
;
1681 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1683 lvItem
.stateMask
|= LVIS_CUT
;
1684 if (info
.m_state
& wxLIST_STATE_CUT
)
1685 lvItem
.state
|= LVIS_CUT
;
1687 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1689 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1690 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1691 lvItem
.state
|= LVIS_DROPHILITED
;
1693 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1695 lvItem
.stateMask
|= LVIS_FOCUSED
;
1696 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1697 lvItem
.state
|= LVIS_FOCUSED
;
1699 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1701 lvItem
.stateMask
|= LVIS_SELECTED
;
1702 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1703 lvItem
.state
|= LVIS_SELECTED
;
1707 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1709 lvItem
.mask
|= LVIF_TEXT
;
1710 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1712 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1716 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1717 if ( lvItem
.pszText
)
1718 lvItem
.cchTextMax
= info
.m_text
.Length();
1720 lvItem
.cchTextMax
= 0;
1723 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1724 lvItem
.mask
|= LVIF_IMAGE
;
1725 if (info
.m_mask
& wxLIST_MASK_DATA
)
1726 lvItem
.mask
|= LVIF_PARAM
;
1729 // ----------------------------------------------------------------------------
1731 // ----------------------------------------------------------------------------
1733 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1735 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1736 : wxNotifyEvent(commandType
, id
)
1742 m_cancelled
= FALSE
;