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"
22 #pragma implementation "listctrlbase.h"
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
38 #include "wx/settings.h"
41 #include "wx/textctrl.h"
42 #include "wx/imaglist.h"
44 #include "wx/listctrl.h"
46 #include "wx/msw/private.h"
48 #ifdef __GNUWIN32_OLD__
49 #include "wx/msw/gnuwin32/extra.h"
56 (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)
59 #ifndef LVM_SETEXTENDEDLISTVIEWSTYLE
60 #define LVM_SETEXTENDEDLISTVIEWSTYLE (0x1000 + 54)
63 #ifndef LVS_EX_FULLROWSELECT
64 #define LVS_EX_FULLROWSELECT 0x00000020
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& tvItem
);
72 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& tvItem
, HWND getFullInfo
= 0);
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
79 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
81 // ============================================================================
83 // ============================================================================
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 void wxListEvent::CopyObject(wxObject
& object_dest
) const
91 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
93 wxNotifyEvent::CopyObject(object_dest
);
96 obj
->m_itemIndex
= m_itemIndex
;
97 obj
->m_oldItemIndex
= m_oldItemIndex
;
99 obj
->m_cancelled
= m_cancelled
;
100 obj
->m_pointDrag
= m_pointDrag
;
101 obj
->m_item
.m_mask
= m_item
.m_mask
;
102 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
103 obj
->m_item
.m_col
= m_item
.m_col
;
104 obj
->m_item
.m_state
= m_item
.m_state
;
105 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
106 obj
->m_item
.m_text
= m_item
.m_text
;
107 obj
->m_item
.m_image
= m_item
.m_image
;
108 obj
->m_item
.m_data
= m_item
.m_data
;
109 obj
->m_item
.m_format
= m_item
.m_format
;
110 obj
->m_item
.m_width
= m_item
.m_width
;
112 if ( m_item
.HasAttributes() )
114 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
115 obj
->m_item
.SetBackgroundColour(m_item
.GetBackgroundColour());
116 obj
->m_item
.SetFont(m_item
.GetFont());
120 // ----------------------------------------------------------------------------
121 // wxListCtrl construction
122 // ----------------------------------------------------------------------------
124 void wxListCtrl::Init()
126 m_imageListNormal
= NULL
;
127 m_imageListSmall
= NULL
;
128 m_imageListState
= NULL
;
132 m_hasAnyAttr
= FALSE
;
135 bool wxListCtrl::Create(wxWindow
*parent
,
140 const wxValidator
& validator
,
141 const wxString
& name
)
144 SetValidator(validator
);
145 #endif // wxUSE_VALIDATORS
154 m_windowStyle
= style
;
167 m_windowId
= (id
== -1) ? NewControlId() : id
;
169 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
170 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
171 if ( wxStyleHasBorder(m_windowStyle
) )
173 m_baseStyle
= wstyle
;
175 if ( !DoCreateControl(x
, y
, width
, height
) )
179 parent
->AddChild(this);
184 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
186 DWORD wstyle
= m_baseStyle
;
189 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
191 // Even with extended styles, need to combine with WS_BORDER
192 // for them to look right.
196 long oldStyle
= 0; // Dummy
197 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
199 // Create the ListView control.
200 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
205 GetWinHwnd(GetParent()),
212 wxLogError(_("Can't create list control window, check "
213 "that comctl32.dll is installed."));
218 // for comctl32.dll v 4.70+ we want to have this attribute because it's
219 // prettier (and also because wxGTK does it like this)
220 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
222 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
223 0, LVS_EX_FULLROWSELECT
);
226 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
227 SetForegroundColour(GetParent()->GetForegroundColour());
234 void wxListCtrl::UpdateStyle()
238 // The new window view style
240 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
241 dwStyleNew
|= m_baseStyle
;
243 // Get the current window style.
244 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
246 // Only set the window style if the view bits have changed.
247 if ( dwStyleOld
!= dwStyleNew
)
249 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
254 void wxListCtrl::FreeAllAttrs(bool dontRecreate
)
258 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
260 delete (wxListItemAttr
*)node
->Data();
266 m_attrs
.Create(wxKEY_INTEGER
, 1000); // just as def ctor
269 m_hasAnyAttr
= FALSE
;
273 wxListCtrl::~wxListCtrl()
275 FreeAllAttrs(TRUE
/* no need to recreate hash any more */);
279 m_textCtrl
->UnsubclassWin();
280 m_textCtrl
->SetHWND(0);
286 // ----------------------------------------------------------------------------
287 // set/get/change style
288 // ----------------------------------------------------------------------------
290 // Add or remove a single window style
291 void wxListCtrl::SetSingleStyle(long style
, bool add
)
293 long flag
= GetWindowStyleFlag();
295 // Get rid of conflicting styles
298 if ( style
& wxLC_MASK_TYPE
)
299 flag
= flag
& ~wxLC_MASK_TYPE
;
300 if ( style
& wxLC_MASK_ALIGN
)
301 flag
= flag
& ~wxLC_MASK_ALIGN
;
302 if ( style
& wxLC_MASK_SORT
)
303 flag
= flag
& ~wxLC_MASK_SORT
;
319 m_windowStyle
= flag
;
324 // Set the whole window style
325 void wxListCtrl::SetWindowStyleFlag(long flag
)
327 m_windowStyle
= flag
;
332 // Can be just a single style, or a bitlist
333 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
336 if ( style
& wxLC_ICON
)
338 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
339 oldStyle
-= LVS_SMALLICON
;
340 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
341 oldStyle
-= LVS_REPORT
;
342 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
343 oldStyle
-= LVS_LIST
;
347 if ( style
& wxLC_SMALL_ICON
)
349 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
350 oldStyle
-= LVS_ICON
;
351 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
352 oldStyle
-= LVS_REPORT
;
353 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
354 oldStyle
-= LVS_LIST
;
355 wstyle
|= LVS_SMALLICON
;
358 if ( style
& wxLC_LIST
)
360 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
361 oldStyle
-= LVS_ICON
;
362 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
363 oldStyle
-= LVS_REPORT
;
364 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
365 oldStyle
-= LVS_SMALLICON
;
369 if ( style
& wxLC_REPORT
)
371 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
372 oldStyle
-= LVS_ICON
;
373 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
374 oldStyle
-= LVS_LIST
;
375 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
376 oldStyle
-= LVS_SMALLICON
;
378 wstyle
|= LVS_REPORT
;
381 if ( style
& wxLC_ALIGN_LEFT
)
383 if ( oldStyle
& LVS_ALIGNTOP
)
384 oldStyle
-= LVS_ALIGNTOP
;
385 wstyle
|= LVS_ALIGNLEFT
;
388 if ( style
& wxLC_ALIGN_TOP
)
390 if ( oldStyle
& LVS_ALIGNLEFT
)
391 oldStyle
-= LVS_ALIGNLEFT
;
392 wstyle
|= LVS_ALIGNTOP
;
395 if ( style
& wxLC_AUTOARRANGE
)
396 wstyle
|= LVS_AUTOARRANGE
;
398 // Apparently, no such style (documentation wrong?)
400 if ( style & wxLC_BUTTON )
401 wstyle |= LVS_BUTTON;
404 if ( style
& wxLC_NO_SORT_HEADER
)
405 wstyle
|= LVS_NOSORTHEADER
;
407 if ( style
& wxLC_NO_HEADER
)
408 wstyle
|= LVS_NOCOLUMNHEADER
;
410 if ( style
& wxLC_EDIT_LABELS
)
411 wstyle
|= LVS_EDITLABELS
;
413 if ( style
& wxLC_SINGLE_SEL
)
414 wstyle
|= LVS_SINGLESEL
;
416 if ( style
& wxLC_SORT_ASCENDING
)
418 if ( oldStyle
& LVS_SORTDESCENDING
)
419 oldStyle
-= LVS_SORTDESCENDING
;
420 wstyle
|= LVS_SORTASCENDING
;
423 if ( style
& wxLC_SORT_DESCENDING
)
425 if ( oldStyle
& LVS_SORTASCENDING
)
426 oldStyle
-= LVS_SORTASCENDING
;
427 wstyle
|= LVS_SORTDESCENDING
;
433 // ----------------------------------------------------------------------------
435 // ----------------------------------------------------------------------------
437 // Sets the foreground, i.e. text, colour
438 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
440 if ( !wxWindow::SetForegroundColour(col
) )
443 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
448 // Sets the background colour
449 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
451 if ( !wxWindow::SetBackgroundColour(col
) )
454 // we set the same colour for both the "empty" background and the items
456 COLORREF color
= wxColourToRGB(col
);
457 ListView_SetBkColor(GetHwnd(), color
);
458 ListView_SetTextBkColor(GetHwnd(), color
);
463 // Gets information about this column
464 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
469 lvCol
.pszText
= NULL
;
471 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
473 lvCol
.mask
|= LVCF_TEXT
;
474 lvCol
.pszText
= new wxChar
[513];
475 lvCol
.cchTextMax
= 512;
478 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
480 // item.m_subItem = lvCol.iSubItem;
481 item
.m_width
= lvCol
.cx
;
483 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
485 item
.m_text
= lvCol
.pszText
;
486 delete[] lvCol
.pszText
;
489 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
491 if (lvCol
.fmt
== LVCFMT_LEFT
)
492 item
.m_format
= wxLIST_FORMAT_LEFT
;
493 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
494 item
.m_format
= wxLIST_FORMAT_RIGHT
;
495 else if (lvCol
.fmt
== LVCFMT_CENTER
)
496 item
.m_format
= wxLIST_FORMAT_CENTRE
;
502 // Sets information about this column
503 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
508 lvCol
.pszText
= NULL
;
510 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
512 lvCol
.mask
|= LVCF_TEXT
;
513 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
514 lvCol
.cchTextMax
= 0; // Ignored
516 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
518 lvCol
.mask
|= LVCF_FMT
;
520 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
521 lvCol
.fmt
= LVCFMT_LEFT
;
522 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
523 lvCol
.fmt
= LVCFMT_RIGHT
;
524 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
525 lvCol
.fmt
= LVCFMT_CENTER
;
528 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
530 lvCol
.mask
|= LVCF_WIDTH
;
531 lvCol
.cx
= item
.m_width
;
533 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
534 lvCol
.cx
= LVSCW_AUTOSIZE
;
535 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
536 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
538 lvCol
.mask
|= LVCF_SUBITEM
;
539 lvCol
.iSubItem
= col
;
540 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
543 // Gets the column width
544 int wxListCtrl::GetColumnWidth(int col
) const
546 return ListView_GetColumnWidth(GetHwnd(), col
);
549 // Sets the column width
550 bool wxListCtrl::SetColumnWidth(int col
, int width
)
553 if ( m_windowStyle
& wxLC_LIST
)
557 if ( width2
== wxLIST_AUTOSIZE
)
558 width2
= LVSCW_AUTOSIZE
;
559 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
560 width2
= LVSCW_AUTOSIZE_USEHEADER
;
562 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
565 // Gets the number of items that can fit vertically in the
566 // visible area of the list control (list or report view)
567 // or the total number of items in the list control (icon
568 // or small icon view)
569 int wxListCtrl::GetCountPerPage() const
571 return ListView_GetCountPerPage(GetHwnd());
574 // Gets the edit control for editing labels.
575 wxTextCtrl
* wxListCtrl::GetEditControl() const
580 // Gets information about the item
581 bool wxListCtrl::GetItem(wxListItem
& info
) const
584 wxZeroMemory(lvItem
);
586 lvItem
.iItem
= info
.m_itemId
;
587 lvItem
.iSubItem
= info
.m_col
;
589 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
591 lvItem
.mask
|= LVIF_TEXT
;
592 lvItem
.pszText
= new wxChar
[513];
593 lvItem
.cchTextMax
= 512;
597 lvItem
.pszText
= NULL
;
600 if (info
.m_mask
& wxLIST_MASK_DATA
)
601 lvItem
.mask
|= LVIF_PARAM
;
603 if ( info
.m_mask
& wxLIST_MASK_STATE
)
605 lvItem
.mask
|= LVIF_STATE
;
606 // the other bits are hardly interesting anyhow
607 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
610 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
613 wxLogError(_("Couldn't retrieve information about list control item %d."),
618 wxConvertFromMSWListItem(this, info
, lvItem
);
622 delete[] lvItem
.pszText
;
627 // Sets information about the item
628 bool wxListCtrl::SetItem(wxListItem
& info
)
631 wxConvertToMSWListItem(this, info
, item
);
633 // check whether it has any custom attributes
634 if ( info
.HasAttributes() )
636 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
642 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
643 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
645 // make the change visible
646 ListView_Update(GetHwnd(), item
.iItem
);
652 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
656 info
.m_mask
= wxLIST_MASK_TEXT
;
657 info
.m_itemId
= index
;
661 info
.m_image
= imageId
;
662 info
.m_mask
|= wxLIST_MASK_IMAGE
;
664 return SetItem(info
);
668 // Gets the item state
669 int wxListCtrl::GetItemState(long item
, long stateMask
) const
673 info
.m_mask
= wxLIST_MASK_STATE
;
674 info
.m_stateMask
= stateMask
;
675 info
.m_itemId
= item
;
683 // Sets the item state
684 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
688 info
.m_mask
= wxLIST_MASK_STATE
;
689 info
.m_state
= state
;
690 info
.m_stateMask
= stateMask
;
691 info
.m_itemId
= item
;
693 return SetItem(info
);
696 // Sets the item image
697 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
701 info
.m_mask
= wxLIST_MASK_IMAGE
;
702 info
.m_image
= image
;
703 info
.m_itemId
= item
;
705 return SetItem(info
);
708 // Gets the item text
709 wxString
wxListCtrl::GetItemText(long item
) const
713 info
.m_mask
= wxLIST_MASK_TEXT
;
714 info
.m_itemId
= item
;
721 // Sets the item text
722 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
726 info
.m_mask
= wxLIST_MASK_TEXT
;
727 info
.m_itemId
= item
;
733 // Gets the item data
734 long wxListCtrl::GetItemData(long item
) const
738 info
.m_mask
= wxLIST_MASK_DATA
;
739 info
.m_itemId
= item
;
746 // Sets the item data
747 bool wxListCtrl::SetItemData(long item
, long data
)
751 info
.m_mask
= wxLIST_MASK_DATA
;
752 info
.m_itemId
= item
;
755 return SetItem(info
);
758 // Gets the item rectangle
759 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
763 int code2
= LVIR_BOUNDS
;
764 if ( code
== wxLIST_RECT_BOUNDS
)
766 else if ( code
== wxLIST_RECT_ICON
)
768 else if ( code
== wxLIST_RECT_LABEL
)
772 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
774 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
779 rect
.width
= rect2
.right
- rect2
.left
;
780 rect
.height
= rect2
.bottom
- rect2
.left
;
784 // Gets the item position
785 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
789 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
791 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
795 // Sets the item position.
796 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
798 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
801 // Gets the number of items in the list control
802 int wxListCtrl::GetItemCount() const
804 return ListView_GetItemCount(GetHwnd());
807 // Retrieves the spacing between icons in pixels.
808 // If small is TRUE, gets the spacing for the small icon
809 // view, otherwise the large icon view.
810 int wxListCtrl::GetItemSpacing(bool isSmall
) const
812 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
815 // Gets the number of selected items in the list control
816 int wxListCtrl::GetSelectedItemCount() const
818 return ListView_GetSelectedCount(GetHwnd());
821 // Gets the text colour of the listview
822 wxColour
wxListCtrl::GetTextColour() const
824 COLORREF ref
= ListView_GetTextColor(GetHwnd());
825 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
829 // Sets the text colour of the listview
830 void wxListCtrl::SetTextColour(const wxColour
& col
)
832 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
835 // Gets the index of the topmost visible item when in
836 // list or report view
837 long wxListCtrl::GetTopItem() const
839 return (long) ListView_GetTopIndex(GetHwnd());
842 // Searches for an item, starting from 'item'.
843 // 'geometry' is one of
844 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
845 // 'state' is a state bit flag, one or more of
846 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
847 // item can be -1 to find the first item that matches the
849 // Returns the item or -1 if unsuccessful.
850 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
854 if ( geom
== wxLIST_NEXT_ABOVE
)
856 if ( geom
== wxLIST_NEXT_ALL
)
858 if ( geom
== wxLIST_NEXT_BELOW
)
860 if ( geom
== wxLIST_NEXT_LEFT
)
861 flags
|= LVNI_TOLEFT
;
862 if ( geom
== wxLIST_NEXT_RIGHT
)
863 flags
|= LVNI_TORIGHT
;
865 if ( state
& wxLIST_STATE_CUT
)
867 if ( state
& wxLIST_STATE_DROPHILITED
)
868 flags
|= LVNI_DROPHILITED
;
869 if ( state
& wxLIST_STATE_FOCUSED
)
870 flags
|= LVNI_FOCUSED
;
871 if ( state
& wxLIST_STATE_SELECTED
)
872 flags
|= LVNI_SELECTED
;
874 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
878 wxImageList
*wxListCtrl::GetImageList(int which
) const
880 if ( which
== wxIMAGE_LIST_NORMAL
)
882 return m_imageListNormal
;
884 else if ( which
== wxIMAGE_LIST_SMALL
)
886 return m_imageListSmall
;
888 else if ( which
== wxIMAGE_LIST_STATE
)
890 return m_imageListState
;
895 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
898 if ( which
== wxIMAGE_LIST_NORMAL
)
900 flags
= LVSIL_NORMAL
;
901 m_imageListNormal
= imageList
;
903 else if ( which
== wxIMAGE_LIST_SMALL
)
906 m_imageListSmall
= imageList
;
908 else if ( which
== wxIMAGE_LIST_STATE
)
911 m_imageListState
= imageList
;
913 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
916 // ----------------------------------------------------------------------------
918 // ----------------------------------------------------------------------------
920 // Arranges the items
921 bool wxListCtrl::Arrange(int flag
)
924 if ( flag
== wxLIST_ALIGN_LEFT
)
925 code
= LVA_ALIGNLEFT
;
926 else if ( flag
== wxLIST_ALIGN_TOP
)
928 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
930 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
931 code
= LVA_SNAPTOGRID
;
933 return (ListView_Arrange(GetHwnd(), code
) != 0);
937 bool wxListCtrl::DeleteItem(long item
)
939 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
943 bool wxListCtrl::DeleteAllItems()
945 return (ListView_DeleteAllItems(GetHwnd()) != 0);
949 bool wxListCtrl::DeleteAllColumns()
951 while ( m_colCount
> 0 )
953 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
955 wxLogLastError("ListView_DeleteColumn");
963 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
969 bool wxListCtrl::DeleteColumn(int col
)
971 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
973 if ( success
&& (m_colCount
> 0) )
978 // Clears items, and columns if there are any.
979 void wxListCtrl::ClearAll()
982 if ( m_colCount
> 0 )
986 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
988 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
990 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
994 m_textCtrl
->UnsubclassWin();
995 m_textCtrl
->SetHWND(0);
1000 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1001 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1002 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1007 // End label editing, optionally cancelling the edit
1008 bool wxListCtrl::EndEditLabel(bool cancel
)
1012 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
1014 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
1018 m_textCtrl->UnsubclassWin();
1019 m_textCtrl->SetHWND(0);
1029 // Ensures this item is visible
1030 bool wxListCtrl::EnsureVisible(long item
)
1032 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
1035 // Find an item whose label matches this string, starting from the item after 'start'
1036 // or the beginning if 'start' is -1.
1037 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1039 LV_FINDINFO findInfo
;
1041 findInfo
.flags
= LVFI_STRING
;
1043 findInfo
.flags
|= LVFI_STRING
;
1044 findInfo
.psz
= WXSTRINGCAST str
;
1046 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1049 // Find an item whose data matches this data, starting from the item after 'start'
1050 // or the beginning if 'start' is -1.
1051 long wxListCtrl::FindItem(long start
, long data
)
1053 LV_FINDINFO findInfo
;
1055 findInfo
.flags
= LVFI_PARAM
;
1056 findInfo
.lParam
= data
;
1058 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1061 // Find an item nearest this position in the specified direction, starting from
1062 // the item after 'start' or the beginning if 'start' is -1.
1063 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1065 LV_FINDINFO findInfo
;
1067 findInfo
.flags
= LVFI_NEARESTXY
;
1068 findInfo
.pt
.x
= pt
.x
;
1069 findInfo
.pt
.y
= pt
.y
;
1070 findInfo
.vkDirection
= VK_RIGHT
;
1072 if ( direction
== wxLIST_FIND_UP
)
1073 findInfo
.vkDirection
= VK_UP
;
1074 else if ( direction
== wxLIST_FIND_DOWN
)
1075 findInfo
.vkDirection
= VK_DOWN
;
1076 else if ( direction
== wxLIST_FIND_LEFT
)
1077 findInfo
.vkDirection
= VK_LEFT
;
1078 else if ( direction
== wxLIST_FIND_RIGHT
)
1079 findInfo
.vkDirection
= VK_RIGHT
;
1081 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1084 // Determines which item (if any) is at the specified point,
1085 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1086 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1088 LV_HITTESTINFO hitTestInfo
;
1089 hitTestInfo
.pt
.x
= (int) point
.x
;
1090 hitTestInfo
.pt
.y
= (int) point
.y
;
1092 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1095 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1096 flags
|= wxLIST_HITTEST_ABOVE
;
1097 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1098 flags
|= wxLIST_HITTEST_BELOW
;
1099 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1100 flags
|= wxLIST_HITTEST_NOWHERE
;
1101 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1102 flags
|= wxLIST_HITTEST_ONITEMICON
;
1103 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1104 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1105 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1106 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1107 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1108 flags
|= wxLIST_HITTEST_TOLEFT
;
1109 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1110 flags
|= wxLIST_HITTEST_TORIGHT
;
1112 return (long) hitTestInfo
.iItem
;
1115 // Inserts an item, returning the index of the new item if successful,
1117 long wxListCtrl::InsertItem(wxListItem
& info
)
1120 wxConvertToMSWListItem(this, info
, item
);
1122 // check whether it has any custom attributes
1123 if ( info
.HasAttributes() )
1125 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1127 m_hasAnyAttr
= TRUE
;
1130 return (long) ListView_InsertItem(GetHwnd(), & item
);
1133 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1136 info
.m_text
= label
;
1137 info
.m_mask
= wxLIST_MASK_TEXT
;
1138 info
.m_itemId
= index
;
1139 return InsertItem(info
);
1142 // Inserts an image item
1143 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1146 info
.m_image
= imageIndex
;
1147 info
.m_mask
= wxLIST_MASK_IMAGE
;
1148 info
.m_itemId
= index
;
1149 return InsertItem(info
);
1152 // Inserts an image/string item
1153 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1156 info
.m_image
= imageIndex
;
1157 info
.m_text
= label
;
1158 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1159 info
.m_itemId
= index
;
1160 return InsertItem(info
);
1163 // For list view mode (only), inserts a column.
1164 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1169 lvCol
.pszText
= NULL
;
1171 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1173 lvCol
.mask
|= LVCF_TEXT
;
1174 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1175 lvCol
.cchTextMax
= 0; // Ignored
1177 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1179 lvCol
.mask
|= LVCF_FMT
;
1181 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1182 lvCol
.fmt
= LVCFMT_LEFT
;
1183 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1184 lvCol
.fmt
= LVCFMT_RIGHT
;
1185 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1186 lvCol
.fmt
= LVCFMT_CENTER
;
1189 lvCol
.mask
|= LVCF_WIDTH
;
1190 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1192 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1193 lvCol
.cx
= LVSCW_AUTOSIZE
;
1194 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1195 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1197 lvCol
.cx
= item
.m_width
;
1201 // always give some width to the new column: this one is compatible
1206 lvCol
.mask
|= LVCF_SUBITEM
;
1207 lvCol
.iSubItem
= col
;
1209 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1216 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1223 long wxListCtrl::InsertColumn(long col
,
1224 const wxString
& heading
,
1229 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1230 item
.m_text
= heading
;
1233 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1234 item
.m_width
= width
;
1236 item
.m_format
= format
;
1238 return InsertColumn(col
, item
);
1241 // Scrolls the list control. If in icon, small icon or report view mode,
1242 // x specifies the number of pixels to scroll. If in list view mode, x
1243 // specifies the number of columns to scroll.
1244 // If in icon, small icon or list view mode, y specifies the number of pixels
1245 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1246 bool wxListCtrl::ScrollList(int dx
, int dy
)
1248 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1253 // fn is a function which takes 3 long arguments: item1, item2, data.
1254 // item1 is the long data associated with a first item (NOT the index).
1255 // item2 is the long data associated with a second item (NOT the index).
1256 // data is the same value as passed to SortItems.
1257 // The return value is a negative number if the first item should precede the second
1258 // item, a positive number of the second item should precede the first,
1259 // or zero if the two items are equivalent.
1261 // data is arbitrary data to be passed to the sort function.
1262 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1264 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1267 // ----------------------------------------------------------------------------
1268 // message processing
1269 // ----------------------------------------------------------------------------
1271 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1273 if (cmd
== EN_UPDATE
)
1275 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1276 event
.SetEventObject( this );
1277 ProcessCommand(event
);
1280 else if (cmd
== EN_KILLFOCUS
)
1282 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1283 event
.SetEventObject( this );
1284 ProcessCommand(event
);
1291 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1293 // prepare the event
1294 // -----------------
1296 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1297 wxEventType eventType
= wxEVT_NULL
;
1299 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1301 // almost all messages use NM_LISTVIEW
1302 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1304 // this is true for almost all events
1305 event
.m_item
.m_data
= nmLV
->lParam
;
1307 switch ( nmhdr
->code
)
1309 case LVN_BEGINRDRAG
:
1310 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1314 if ( eventType
== wxEVT_NULL
)
1316 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1319 event
.m_itemIndex
= nmLV
->iItem
;
1320 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1321 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1324 case LVN_BEGINLABELEDIT
:
1326 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1327 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1328 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1332 case LVN_COLUMNCLICK
:
1333 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1334 event
.m_itemIndex
= -1;
1335 event
.m_col
= nmLV
->iSubItem
;
1338 case LVN_DELETEALLITEMS
:
1339 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1340 event
.m_itemIndex
= -1;
1346 case LVN_DELETEITEM
:
1347 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1348 event
.m_itemIndex
= nmLV
->iItem
;
1352 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1356 case LVN_ENDLABELEDIT
:
1358 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1359 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1360 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1361 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1366 case LVN_SETDISPINFO
:
1368 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1369 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1370 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1374 case LVN_GETDISPINFO
:
1375 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1376 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1380 // TODO: some text buffering here, I think
1381 // TODO: API for getting Windows to retrieve values
1383 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1384 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1385 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1392 case LVN_INSERTITEM
:
1393 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1394 event
.m_itemIndex
= nmLV
->iItem
;
1397 case LVN_ITEMCHANGED
:
1398 // This needs to be sent to wxListCtrl as a rather more concrete
1399 // event. For now, just detect a selection or deselection.
1400 if ( (nmLV
->uNewState
& LVIS_SELECTED
) && !(nmLV
->uOldState
& LVIS_SELECTED
) )
1402 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1403 event
.m_itemIndex
= nmLV
->iItem
;
1405 else if ( !(nmLV
->uNewState
& LVIS_SELECTED
) && (nmLV
->uOldState
& LVIS_SELECTED
) )
1407 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1408 event
.m_itemIndex
= nmLV
->iItem
;
1418 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1419 WORD wVKey
= info
->wVKey
;
1421 // get the current selection
1422 long lItem
= GetNextItem(-1,
1424 wxLIST_STATE_SELECTED
);
1426 // <Enter> or <Space> activate the selected item if any
1427 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1429 // TODO this behaviour probably should be optional
1430 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1431 event
.m_itemIndex
= lItem
;
1435 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1436 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1439 event
.m_item
.m_data
= GetItemData(lItem
);
1444 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1446 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1451 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1452 // if it happened on an item (and not on empty place)
1453 if ( nmLV
->iItem
== -1 )
1459 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1460 event
.m_itemIndex
= nmLV
->iItem
;
1461 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1465 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1466 subclass and check for the actual WM_RBUTTONDOWN message,
1467 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1468 before firing off. We want to have notify events for both down
1471 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1472 // don't do anything else
1473 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1478 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1479 LV_HITTESTINFO lvhti
;
1480 wxZeroMemory(lvhti
);
1482 ::GetCursorPos(&(lvhti
.pt
));
1483 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1484 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1486 if ( lvhti
.flags
& LVHT_ONITEM
)
1488 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1489 event
.m_itemIndex
= lvhti
.iItem
;
1496 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1498 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1500 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1505 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1506 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1507 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1508 event
.m_itemIndex
= hdr
->iItem
;
1513 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1516 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1517 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1518 switch( nmcd
.dwDrawStage
)
1521 // if we've got any items with non standard attributes,
1522 // notify us before painting each item
1523 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1527 case CDDS_ITEMPREPAINT
:
1529 wxListItemAttr
*attr
=
1530 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1534 // nothing to do for this item
1535 return CDRF_DODEFAULT
;
1539 wxColour colText
, colBack
;
1540 if ( attr
->HasFont() )
1542 wxFont font
= attr
->GetFont();
1543 hFont
= (HFONT
)font
.GetResourceHandle();
1550 if ( attr
->HasTextColour() )
1552 colText
= attr
->GetTextColour();
1556 colText
= GetTextColour();
1559 if ( attr
->HasBackgroundColour() )
1561 colBack
= attr
->GetBackgroundColour();
1565 colBack
= GetBackgroundColour();
1568 // note that if we wanted to set colours for
1569 // individual columns (subitems), we would have
1570 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1573 ::SelectObject(nmcd
.hdc
, hFont
);
1575 *result
= CDRF_NEWFONT
;
1579 *result
= CDRF_DODEFAULT
;
1582 lplvcd
->clrText
= wxColourToRGB(colText
);
1583 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1589 *result
= CDRF_DODEFAULT
;
1594 #endif // _WIN32_IE >= 0x300
1597 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1600 // process the event
1601 // -----------------
1603 event
.SetEventObject( this );
1604 event
.SetEventType(eventType
);
1606 if ( !GetEventHandler()->ProcessEvent(event
) )
1612 switch ( nmhdr
->code
)
1614 case LVN_DELETEALLITEMS
:
1615 // always return TRUE to suppress all additional LVN_DELETEITEM
1616 // notifications - this makes deleting all items from a list ctrl
1622 case LVN_GETDISPINFO
:
1624 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1625 if ( info
->item
.mask
& LVIF_TEXT
)
1627 if ( !event
.m_item
.m_text
.IsNull() )
1629 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1630 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1633 // wxConvertToMSWListItem(this, event.m_item, info->item);
1636 case LVN_ENDLABELEDIT
:
1638 *result
= event
.IsAllowed();
1643 *result
= !event
.IsAllowed();
1648 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1650 // Remove the first element if 3 strings exist
1651 if ( m_stringPool
.Number() == 3 )
1653 wxNode
*node
= m_stringPool
.First();
1654 delete[] (char *)node
->Data();
1657 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1658 return (wxChar
*)node
->Data();
1661 // ----------------------------------------------------------------------------
1663 // ----------------------------------------------------------------------------
1665 // List item structure
1666 wxListItem::wxListItem()
1676 m_format
= wxLIST_FORMAT_CENTRE
;
1682 void wxListItem::Clear()
1691 m_format
= wxLIST_FORMAT_CENTRE
;
1693 m_text
= wxEmptyString
;
1695 if (m_attr
) delete m_attr
;
1699 void wxListItem::ClearAttributes()
1701 if (m_attr
) delete m_attr
;
1705 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1707 info
.m_data
= lvItem
.lParam
;
1710 info
.m_stateMask
= 0;
1711 info
.m_itemId
= lvItem
.iItem
;
1713 long oldMask
= lvItem
.mask
;
1715 bool needText
= FALSE
;
1716 if (getFullInfo
!= 0)
1718 if ( lvItem
.mask
& LVIF_TEXT
)
1725 lvItem
.pszText
= new wxChar
[513];
1726 lvItem
.cchTextMax
= 512;
1728 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1729 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1730 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1733 if ( lvItem
.mask
& LVIF_STATE
)
1735 info
.m_mask
|= wxLIST_MASK_STATE
;
1737 if ( lvItem
.stateMask
& LVIS_CUT
)
1739 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1740 if ( lvItem
.state
& LVIS_CUT
)
1741 info
.m_state
|= wxLIST_STATE_CUT
;
1743 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1745 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1746 if ( lvItem
.state
& LVIS_DROPHILITED
)
1747 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1749 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1751 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1752 if ( lvItem
.state
& LVIS_FOCUSED
)
1753 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1755 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1757 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1758 if ( lvItem
.state
& LVIS_SELECTED
)
1759 info
.m_state
|= wxLIST_STATE_SELECTED
;
1763 if ( lvItem
.mask
& LVIF_TEXT
)
1765 info
.m_mask
|= wxLIST_MASK_TEXT
;
1766 info
.m_text
= lvItem
.pszText
;
1768 if ( lvItem
.mask
& LVIF_IMAGE
)
1770 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1771 info
.m_image
= lvItem
.iImage
;
1773 if ( lvItem
.mask
& LVIF_PARAM
)
1774 info
.m_mask
|= wxLIST_MASK_DATA
;
1775 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1776 info
.m_mask
|= wxLIST_SET_ITEM
;
1777 info
.m_col
= lvItem
.iSubItem
;
1782 delete[] lvItem
.pszText
;
1784 lvItem
.mask
= oldMask
;
1787 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1789 lvItem
.iItem
= (int) info
.m_itemId
;
1791 lvItem
.iImage
= info
.m_image
;
1792 lvItem
.lParam
= info
.m_data
;
1793 lvItem
.stateMask
= 0;
1796 lvItem
.iSubItem
= info
.m_col
;
1798 if (info
.m_mask
& wxLIST_MASK_STATE
)
1800 lvItem
.mask
|= LVIF_STATE
;
1801 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1803 lvItem
.stateMask
|= LVIS_CUT
;
1804 if (info
.m_state
& wxLIST_STATE_CUT
)
1805 lvItem
.state
|= LVIS_CUT
;
1807 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1809 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1810 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1811 lvItem
.state
|= LVIS_DROPHILITED
;
1813 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1815 lvItem
.stateMask
|= LVIS_FOCUSED
;
1816 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1817 lvItem
.state
|= LVIS_FOCUSED
;
1819 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1821 lvItem
.stateMask
|= LVIS_SELECTED
;
1822 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1823 lvItem
.state
|= LVIS_SELECTED
;
1827 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1829 lvItem
.mask
|= LVIF_TEXT
;
1830 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1832 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1836 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1837 if ( lvItem
.pszText
)
1838 lvItem
.cchTextMax
= info
.m_text
.Length();
1840 lvItem
.cchTextMax
= 0;
1843 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1844 lvItem
.mask
|= LVIF_IMAGE
;
1845 if (info
.m_mask
& wxLIST_MASK_DATA
)
1846 lvItem
.mask
|= LVIF_PARAM
;
1849 // ----------------------------------------------------------------------------
1851 // ----------------------------------------------------------------------------
1853 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1855 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1856 : wxNotifyEvent(commandType
, id
)
1862 m_cancelled
= FALSE
;