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 that comctl32.dll is installed."));
217 // for comctl32.dll v 4.70+ we want to have this attribute because it's
218 // prettier (and also because wxGTK does it like this)
219 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
221 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
222 0, LVS_EX_FULLROWSELECT
);
225 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
226 SetForegroundColour(GetParent()->GetForegroundColour());
233 void wxListCtrl::UpdateStyle()
237 // The new window view style
239 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
240 dwStyleNew
|= m_baseStyle
;
242 // Get the current window style.
243 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
245 // Only set the window style if the view bits have changed.
246 if ( dwStyleOld
!= dwStyleNew
)
248 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
253 void wxListCtrl::FreeAllAttrs(bool dontRecreate
)
257 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
259 delete (wxListItemAttr
*)node
->Data();
265 m_attrs
.Create(wxKEY_INTEGER
, 1000); // just as def ctor
268 m_hasAnyAttr
= FALSE
;
272 wxListCtrl::~wxListCtrl()
274 FreeAllAttrs(TRUE
/* no need to recreate hash any more */);
278 m_textCtrl
->UnsubclassWin();
279 m_textCtrl
->SetHWND(0);
285 // ----------------------------------------------------------------------------
286 // set/get/change style
287 // ----------------------------------------------------------------------------
289 // Add or remove a single window style
290 void wxListCtrl::SetSingleStyle(long style
, bool add
)
292 long flag
= GetWindowStyleFlag();
294 // Get rid of conflicting styles
297 if ( style
& wxLC_MASK_TYPE
)
298 flag
= flag
& ~wxLC_MASK_TYPE
;
299 if ( style
& wxLC_MASK_ALIGN
)
300 flag
= flag
& ~wxLC_MASK_ALIGN
;
301 if ( style
& wxLC_MASK_SORT
)
302 flag
= flag
& ~wxLC_MASK_SORT
;
318 m_windowStyle
= flag
;
323 // Set the whole window style
324 void wxListCtrl::SetWindowStyleFlag(long flag
)
326 m_windowStyle
= flag
;
331 // Can be just a single style, or a bitlist
332 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
335 if ( style
& wxLC_ICON
)
337 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
338 oldStyle
-= LVS_SMALLICON
;
339 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
340 oldStyle
-= LVS_REPORT
;
341 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
342 oldStyle
-= LVS_LIST
;
346 if ( style
& wxLC_SMALL_ICON
)
348 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
349 oldStyle
-= LVS_ICON
;
350 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
351 oldStyle
-= LVS_REPORT
;
352 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
353 oldStyle
-= LVS_LIST
;
354 wstyle
|= LVS_SMALLICON
;
357 if ( style
& wxLC_LIST
)
359 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
360 oldStyle
-= LVS_ICON
;
361 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
362 oldStyle
-= LVS_REPORT
;
363 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
364 oldStyle
-= LVS_SMALLICON
;
368 if ( style
& wxLC_REPORT
)
370 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
371 oldStyle
-= LVS_ICON
;
372 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
373 oldStyle
-= LVS_LIST
;
374 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
375 oldStyle
-= LVS_SMALLICON
;
377 wstyle
|= LVS_REPORT
;
380 if ( style
& wxLC_ALIGN_LEFT
)
382 if ( oldStyle
& LVS_ALIGNTOP
)
383 oldStyle
-= LVS_ALIGNTOP
;
384 wstyle
|= LVS_ALIGNLEFT
;
387 if ( style
& wxLC_ALIGN_TOP
)
389 if ( oldStyle
& LVS_ALIGNLEFT
)
390 oldStyle
-= LVS_ALIGNLEFT
;
391 wstyle
|= LVS_ALIGNTOP
;
394 if ( style
& wxLC_AUTOARRANGE
)
395 wstyle
|= LVS_AUTOARRANGE
;
397 // Apparently, no such style (documentation wrong?)
399 if ( style & wxLC_BUTTON )
400 wstyle |= LVS_BUTTON;
403 if ( style
& wxLC_NO_SORT_HEADER
)
404 wstyle
|= LVS_NOSORTHEADER
;
406 if ( style
& wxLC_NO_HEADER
)
407 wstyle
|= LVS_NOCOLUMNHEADER
;
409 if ( style
& wxLC_EDIT_LABELS
)
410 wstyle
|= LVS_EDITLABELS
;
412 if ( style
& wxLC_SINGLE_SEL
)
413 wstyle
|= LVS_SINGLESEL
;
415 if ( style
& wxLC_SORT_ASCENDING
)
417 if ( oldStyle
& LVS_SORTDESCENDING
)
418 oldStyle
-= LVS_SORTDESCENDING
;
419 wstyle
|= LVS_SORTASCENDING
;
422 if ( style
& wxLC_SORT_DESCENDING
)
424 if ( oldStyle
& LVS_SORTASCENDING
)
425 oldStyle
-= LVS_SORTASCENDING
;
426 wstyle
|= LVS_SORTDESCENDING
;
432 // ----------------------------------------------------------------------------
434 // ----------------------------------------------------------------------------
436 // Sets the foreground, i.e. text, colour
437 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
439 if ( !wxWindow::SetForegroundColour(col
) )
442 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
447 // Sets the background colour
448 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
450 if ( !wxWindow::SetBackgroundColour(col
) )
453 // we set the same colour for both the "empty" background and the items
455 COLORREF color
= wxColourToRGB(col
);
456 ListView_SetBkColor(GetHwnd(), color
);
457 ListView_SetTextBkColor(GetHwnd(), color
);
462 // Gets information about this column
463 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
468 lvCol
.pszText
= NULL
;
470 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
472 lvCol
.mask
|= LVCF_TEXT
;
473 lvCol
.pszText
= new wxChar
[513];
474 lvCol
.cchTextMax
= 512;
477 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
479 // item.m_subItem = lvCol.iSubItem;
480 item
.m_width
= lvCol
.cx
;
482 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
484 item
.m_text
= lvCol
.pszText
;
485 delete[] lvCol
.pszText
;
488 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
490 if (lvCol
.fmt
== LVCFMT_LEFT
)
491 item
.m_format
= wxLIST_FORMAT_LEFT
;
492 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
493 item
.m_format
= wxLIST_FORMAT_RIGHT
;
494 else if (lvCol
.fmt
== LVCFMT_CENTER
)
495 item
.m_format
= wxLIST_FORMAT_CENTRE
;
501 // Sets information about this column
502 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
507 lvCol
.pszText
= NULL
;
509 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
511 lvCol
.mask
|= LVCF_TEXT
;
512 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
513 lvCol
.cchTextMax
= 0; // Ignored
515 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
517 lvCol
.mask
|= LVCF_FMT
;
519 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
520 lvCol
.fmt
= LVCFMT_LEFT
;
521 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
522 lvCol
.fmt
= LVCFMT_RIGHT
;
523 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
524 lvCol
.fmt
= LVCFMT_CENTER
;
527 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
529 lvCol
.mask
|= LVCF_WIDTH
;
530 lvCol
.cx
= item
.m_width
;
532 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
533 lvCol
.cx
= LVSCW_AUTOSIZE
;
534 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
535 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
537 lvCol
.mask
|= LVCF_SUBITEM
;
538 lvCol
.iSubItem
= col
;
539 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
542 // Gets the column width
543 int wxListCtrl::GetColumnWidth(int col
) const
545 return ListView_GetColumnWidth(GetHwnd(), col
);
548 // Sets the column width
549 bool wxListCtrl::SetColumnWidth(int col
, int width
)
552 if ( m_windowStyle
& wxLC_LIST
)
556 if ( width2
== wxLIST_AUTOSIZE
)
557 width2
= LVSCW_AUTOSIZE
;
558 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
559 width2
= LVSCW_AUTOSIZE_USEHEADER
;
561 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
564 // Gets the number of items that can fit vertically in the
565 // visible area of the list control (list or report view)
566 // or the total number of items in the list control (icon
567 // or small icon view)
568 int wxListCtrl::GetCountPerPage() const
570 return ListView_GetCountPerPage(GetHwnd());
573 // Gets the edit control for editing labels.
574 wxTextCtrl
* wxListCtrl::GetEditControl() const
579 // Gets information about the item
580 bool wxListCtrl::GetItem(wxListItem
& info
) const
583 wxZeroMemory(lvItem
);
585 lvItem
.iItem
= info
.m_itemId
;
586 lvItem
.iSubItem
= info
.m_col
;
588 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
590 lvItem
.mask
|= LVIF_TEXT
;
591 lvItem
.pszText
= new wxChar
[513];
592 lvItem
.cchTextMax
= 512;
596 lvItem
.pszText
= NULL
;
599 if (info
.m_mask
& wxLIST_MASK_DATA
)
600 lvItem
.mask
|= LVIF_PARAM
;
602 if ( info
.m_mask
& wxLIST_MASK_STATE
)
604 lvItem
.mask
|= LVIF_STATE
;
605 // the other bits are hardly interesting anyhow
606 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
609 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
612 wxLogError(_("Couldn't retrieve information about list control item %d."),
617 wxConvertFromMSWListItem(this, info
, lvItem
);
621 delete[] lvItem
.pszText
;
626 // Sets information about the item
627 bool wxListCtrl::SetItem(wxListItem
& info
)
630 wxConvertToMSWListItem(this, info
, item
);
632 // check whether it has any custom attributes
633 if ( info
.HasAttributes() )
635 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
641 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
642 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
644 // make the change visible
645 ListView_Update(GetHwnd(), item
.iItem
);
651 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
655 info
.m_mask
= wxLIST_MASK_TEXT
;
656 info
.m_itemId
= index
;
660 info
.m_image
= imageId
;
661 info
.m_mask
|= wxLIST_MASK_IMAGE
;
663 return SetItem(info
);
667 // Gets the item state
668 int wxListCtrl::GetItemState(long item
, long stateMask
) const
672 info
.m_mask
= wxLIST_MASK_STATE
;
673 info
.m_stateMask
= stateMask
;
674 info
.m_itemId
= item
;
682 // Sets the item state
683 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
687 info
.m_mask
= wxLIST_MASK_STATE
;
688 info
.m_state
= state
;
689 info
.m_stateMask
= stateMask
;
690 info
.m_itemId
= item
;
692 return SetItem(info
);
695 // Sets the item image
696 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
700 info
.m_mask
= wxLIST_MASK_IMAGE
;
701 info
.m_image
= image
;
702 info
.m_itemId
= item
;
704 return SetItem(info
);
707 // Gets the item text
708 wxString
wxListCtrl::GetItemText(long item
) const
712 info
.m_mask
= wxLIST_MASK_TEXT
;
713 info
.m_itemId
= item
;
720 // Sets the item text
721 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
725 info
.m_mask
= wxLIST_MASK_TEXT
;
726 info
.m_itemId
= item
;
732 // Gets the item data
733 long wxListCtrl::GetItemData(long item
) const
737 info
.m_mask
= wxLIST_MASK_DATA
;
738 info
.m_itemId
= item
;
745 // Sets the item data
746 bool wxListCtrl::SetItemData(long item
, long data
)
750 info
.m_mask
= wxLIST_MASK_DATA
;
751 info
.m_itemId
= item
;
754 return SetItem(info
);
757 // Gets the item rectangle
758 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
762 int code2
= LVIR_BOUNDS
;
763 if ( code
== wxLIST_RECT_BOUNDS
)
765 else if ( code
== wxLIST_RECT_ICON
)
767 else if ( code
== wxLIST_RECT_LABEL
)
771 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
773 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
778 rect
.width
= rect2
.right
- rect2
.left
;
779 rect
.height
= rect2
.bottom
- rect2
.left
;
783 // Gets the item position
784 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
788 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
790 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
794 // Sets the item position.
795 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
797 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
800 // Gets the number of items in the list control
801 int wxListCtrl::GetItemCount() const
803 return ListView_GetItemCount(GetHwnd());
806 // Retrieves the spacing between icons in pixels.
807 // If small is TRUE, gets the spacing for the small icon
808 // view, otherwise the large icon view.
809 int wxListCtrl::GetItemSpacing(bool isSmall
) const
811 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
814 // Gets the number of selected items in the list control
815 int wxListCtrl::GetSelectedItemCount() const
817 return ListView_GetSelectedCount(GetHwnd());
820 // Gets the text colour of the listview
821 wxColour
wxListCtrl::GetTextColour() const
823 COLORREF ref
= ListView_GetTextColor(GetHwnd());
824 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
828 // Sets the text colour of the listview
829 void wxListCtrl::SetTextColour(const wxColour
& col
)
831 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
834 // Gets the index of the topmost visible item when in
835 // list or report view
836 long wxListCtrl::GetTopItem() const
838 return (long) ListView_GetTopIndex(GetHwnd());
841 // Searches for an item, starting from 'item'.
842 // 'geometry' is one of
843 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
844 // 'state' is a state bit flag, one or more of
845 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
846 // item can be -1 to find the first item that matches the
848 // Returns the item or -1 if unsuccessful.
849 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
853 if ( geom
== wxLIST_NEXT_ABOVE
)
855 if ( geom
== wxLIST_NEXT_ALL
)
857 if ( geom
== wxLIST_NEXT_BELOW
)
859 if ( geom
== wxLIST_NEXT_LEFT
)
860 flags
|= LVNI_TOLEFT
;
861 if ( geom
== wxLIST_NEXT_RIGHT
)
862 flags
|= LVNI_TORIGHT
;
864 if ( state
& wxLIST_STATE_CUT
)
866 if ( state
& wxLIST_STATE_DROPHILITED
)
867 flags
|= LVNI_DROPHILITED
;
868 if ( state
& wxLIST_STATE_FOCUSED
)
869 flags
|= LVNI_FOCUSED
;
870 if ( state
& wxLIST_STATE_SELECTED
)
871 flags
|= LVNI_SELECTED
;
873 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
877 wxImageList
*wxListCtrl::GetImageList(int which
) const
879 if ( which
== wxIMAGE_LIST_NORMAL
)
881 return m_imageListNormal
;
883 else if ( which
== wxIMAGE_LIST_SMALL
)
885 return m_imageListSmall
;
887 else if ( which
== wxIMAGE_LIST_STATE
)
889 return m_imageListState
;
894 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
897 if ( which
== wxIMAGE_LIST_NORMAL
)
899 flags
= LVSIL_NORMAL
;
900 m_imageListNormal
= imageList
;
902 else if ( which
== wxIMAGE_LIST_SMALL
)
905 m_imageListSmall
= imageList
;
907 else if ( which
== wxIMAGE_LIST_STATE
)
910 m_imageListState
= imageList
;
912 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
915 // ----------------------------------------------------------------------------
917 // ----------------------------------------------------------------------------
919 // Arranges the items
920 bool wxListCtrl::Arrange(int flag
)
923 if ( flag
== wxLIST_ALIGN_LEFT
)
924 code
= LVA_ALIGNLEFT
;
925 else if ( flag
== wxLIST_ALIGN_TOP
)
927 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
929 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
930 code
= LVA_SNAPTOGRID
;
932 return (ListView_Arrange(GetHwnd(), code
) != 0);
936 bool wxListCtrl::DeleteItem(long item
)
938 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
942 bool wxListCtrl::DeleteAllItems()
944 return (ListView_DeleteAllItems(GetHwnd()) != 0);
948 bool wxListCtrl::DeleteAllColumns()
950 while ( m_colCount
> 0 )
952 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
954 wxLogLastError(wxT("ListView_DeleteColumn"));
962 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
968 bool wxListCtrl::DeleteColumn(int col
)
970 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
972 if ( success
&& (m_colCount
> 0) )
977 // Clears items, and columns if there are any.
978 void wxListCtrl::ClearAll()
981 if ( m_colCount
> 0 )
985 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
987 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
989 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
993 m_textCtrl
->UnsubclassWin();
994 m_textCtrl
->SetHWND(0);
999 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1000 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1001 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1006 // End label editing, optionally cancelling the edit
1007 bool wxListCtrl::EndEditLabel(bool cancel
)
1011 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
1013 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
1017 m_textCtrl->UnsubclassWin();
1018 m_textCtrl->SetHWND(0);
1028 // Ensures this item is visible
1029 bool wxListCtrl::EnsureVisible(long item
)
1031 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
1034 // Find an item whose label matches this string, starting from the item after 'start'
1035 // or the beginning if 'start' is -1.
1036 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1038 LV_FINDINFO findInfo
;
1040 findInfo
.flags
= LVFI_STRING
;
1042 findInfo
.flags
|= LVFI_PARTIAL
;
1045 // ListView_FindItem() excludes the first item from search and to look
1046 // through all the items you need to start from -1 which is unnatural and
1047 // inconsitent with the generic version - so we adjust the index
1048 return ListView_FindItem(GetHwnd(), (int) start
- 1, &findInfo
);
1051 // Find an item whose data matches this data, starting from the item after 'start'
1052 // or the beginning if 'start' is -1.
1053 long wxListCtrl::FindItem(long start
, long data
)
1055 LV_FINDINFO findInfo
;
1057 findInfo
.flags
= LVFI_PARAM
;
1058 findInfo
.lParam
= data
;
1060 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1063 // Find an item nearest this position in the specified direction, starting from
1064 // the item after 'start' or the beginning if 'start' is -1.
1065 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1067 LV_FINDINFO findInfo
;
1069 findInfo
.flags
= LVFI_NEARESTXY
;
1070 findInfo
.pt
.x
= pt
.x
;
1071 findInfo
.pt
.y
= pt
.y
;
1072 findInfo
.vkDirection
= VK_RIGHT
;
1074 if ( direction
== wxLIST_FIND_UP
)
1075 findInfo
.vkDirection
= VK_UP
;
1076 else if ( direction
== wxLIST_FIND_DOWN
)
1077 findInfo
.vkDirection
= VK_DOWN
;
1078 else if ( direction
== wxLIST_FIND_LEFT
)
1079 findInfo
.vkDirection
= VK_LEFT
;
1080 else if ( direction
== wxLIST_FIND_RIGHT
)
1081 findInfo
.vkDirection
= VK_RIGHT
;
1083 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1086 // Determines which item (if any) is at the specified point,
1087 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1088 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1090 LV_HITTESTINFO hitTestInfo
;
1091 hitTestInfo
.pt
.x
= (int) point
.x
;
1092 hitTestInfo
.pt
.y
= (int) point
.y
;
1094 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1097 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1098 flags
|= wxLIST_HITTEST_ABOVE
;
1099 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1100 flags
|= wxLIST_HITTEST_BELOW
;
1101 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1102 flags
|= wxLIST_HITTEST_NOWHERE
;
1103 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1104 flags
|= wxLIST_HITTEST_ONITEMICON
;
1105 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1106 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1107 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1108 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1109 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1110 flags
|= wxLIST_HITTEST_TOLEFT
;
1111 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1112 flags
|= wxLIST_HITTEST_TORIGHT
;
1114 return (long) hitTestInfo
.iItem
;
1117 // Inserts an item, returning the index of the new item if successful,
1119 long wxListCtrl::InsertItem(wxListItem
& info
)
1122 wxConvertToMSWListItem(this, info
, item
);
1124 // check whether it has any custom attributes
1125 if ( info
.HasAttributes() )
1127 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1129 m_hasAnyAttr
= TRUE
;
1132 return (long) ListView_InsertItem(GetHwnd(), & item
);
1135 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1138 info
.m_text
= label
;
1139 info
.m_mask
= wxLIST_MASK_TEXT
;
1140 info
.m_itemId
= index
;
1141 return InsertItem(info
);
1144 // Inserts an image item
1145 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1148 info
.m_image
= imageIndex
;
1149 info
.m_mask
= wxLIST_MASK_IMAGE
;
1150 info
.m_itemId
= index
;
1151 return InsertItem(info
);
1154 // Inserts an image/string item
1155 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1158 info
.m_image
= imageIndex
;
1159 info
.m_text
= label
;
1160 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1161 info
.m_itemId
= index
;
1162 return InsertItem(info
);
1165 // For list view mode (only), inserts a column.
1166 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1171 lvCol
.pszText
= NULL
;
1173 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1175 lvCol
.mask
|= LVCF_TEXT
;
1176 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1177 lvCol
.cchTextMax
= 0; // Ignored
1179 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1181 lvCol
.mask
|= LVCF_FMT
;
1183 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1184 lvCol
.fmt
= LVCFMT_LEFT
;
1185 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1186 lvCol
.fmt
= LVCFMT_RIGHT
;
1187 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1188 lvCol
.fmt
= LVCFMT_CENTER
;
1191 lvCol
.mask
|= LVCF_WIDTH
;
1192 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1194 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1195 lvCol
.cx
= LVSCW_AUTOSIZE
;
1196 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1197 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1199 lvCol
.cx
= item
.m_width
;
1203 // always give some width to the new column: this one is compatible
1208 lvCol
.mask
|= LVCF_SUBITEM
;
1209 lvCol
.iSubItem
= col
;
1211 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1218 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1225 long wxListCtrl::InsertColumn(long col
,
1226 const wxString
& heading
,
1231 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1232 item
.m_text
= heading
;
1235 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1236 item
.m_width
= width
;
1238 item
.m_format
= format
;
1240 return InsertColumn(col
, item
);
1243 // Scrolls the list control. If in icon, small icon or report view mode,
1244 // x specifies the number of pixels to scroll. If in list view mode, x
1245 // specifies the number of columns to scroll.
1246 // If in icon, small icon or list view mode, y specifies the number of pixels
1247 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1248 bool wxListCtrl::ScrollList(int dx
, int dy
)
1250 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1255 // fn is a function which takes 3 long arguments: item1, item2, data.
1256 // item1 is the long data associated with a first item (NOT the index).
1257 // item2 is the long data associated with a second item (NOT the index).
1258 // data is the same value as passed to SortItems.
1259 // The return value is a negative number if the first item should precede the second
1260 // item, a positive number of the second item should precede the first,
1261 // or zero if the two items are equivalent.
1263 // data is arbitrary data to be passed to the sort function.
1264 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1266 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1269 // ----------------------------------------------------------------------------
1270 // message processing
1271 // ----------------------------------------------------------------------------
1273 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1275 if (cmd
== EN_UPDATE
)
1277 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1278 event
.SetEventObject( this );
1279 ProcessCommand(event
);
1282 else if (cmd
== EN_KILLFOCUS
)
1284 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1285 event
.SetEventObject( this );
1286 ProcessCommand(event
);
1293 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1295 // prepare the event
1296 // -----------------
1298 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1299 wxEventType eventType
= wxEVT_NULL
;
1301 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1303 // almost all messages use NM_LISTVIEW
1304 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1306 // this is true for almost all events
1307 event
.m_item
.m_data
= nmLV
->lParam
;
1309 switch ( nmhdr
->code
)
1311 case LVN_BEGINRDRAG
:
1312 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1316 if ( eventType
== wxEVT_NULL
)
1318 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1321 event
.m_itemIndex
= nmLV
->iItem
;
1322 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1323 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1326 case LVN_BEGINLABELEDIT
:
1328 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1329 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1330 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1334 case LVN_COLUMNCLICK
:
1335 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1336 event
.m_itemIndex
= -1;
1337 event
.m_col
= nmLV
->iSubItem
;
1340 case LVN_DELETEALLITEMS
:
1341 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1342 event
.m_itemIndex
= -1;
1348 case LVN_DELETEITEM
:
1349 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1350 event
.m_itemIndex
= nmLV
->iItem
;
1354 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1358 case LVN_ENDLABELEDIT
:
1360 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1361 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1362 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1363 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1368 case LVN_SETDISPINFO
:
1370 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1371 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1372 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1376 case LVN_GETDISPINFO
:
1377 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1378 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1382 // TODO: some text buffering here, I think
1383 // TODO: API for getting Windows to retrieve values
1385 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1386 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1387 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1394 case LVN_INSERTITEM
:
1395 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1396 event
.m_itemIndex
= nmLV
->iItem
;
1399 case LVN_ITEMCHANGED
:
1400 // This needs to be sent to wxListCtrl as a rather more concrete
1401 // event. For now, just detect a selection or deselection.
1402 if ( (nmLV
->uNewState
& LVIS_SELECTED
) && !(nmLV
->uOldState
& LVIS_SELECTED
) )
1404 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1405 event
.m_itemIndex
= nmLV
->iItem
;
1407 else if ( !(nmLV
->uNewState
& LVIS_SELECTED
) && (nmLV
->uOldState
& LVIS_SELECTED
) )
1409 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1410 event
.m_itemIndex
= nmLV
->iItem
;
1420 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1421 WORD wVKey
= info
->wVKey
;
1423 // get the current selection
1424 long lItem
= GetNextItem(-1,
1426 wxLIST_STATE_SELECTED
);
1428 // <Enter> or <Space> activate the selected item if any
1429 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1431 // TODO this behaviour probably should be optional
1432 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1433 event
.m_itemIndex
= lItem
;
1437 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1438 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1443 // fill the other fields too
1444 event
.m_item
.m_text
= GetItemText(lItem
);
1445 event
.m_item
.m_data
= GetItemData(lItem
);
1451 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1453 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1458 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1459 // if it happened on an item (and not on empty place)
1460 if ( nmLV
->iItem
== -1 )
1466 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1467 event
.m_itemIndex
= nmLV
->iItem
;
1468 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1469 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1473 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1474 subclass and check for the actual WM_RBUTTONDOWN message,
1475 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1476 before firing off. We want to have notify events for both down
1479 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1480 // don't do anything else
1481 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1486 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1487 LV_HITTESTINFO lvhti
;
1488 wxZeroMemory(lvhti
);
1490 ::GetCursorPos(&(lvhti
.pt
));
1491 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1492 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1494 if ( lvhti
.flags
& LVHT_ONITEM
)
1496 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1497 event
.m_itemIndex
= lvhti
.iItem
;
1504 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1506 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1508 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1513 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1514 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1515 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1516 event
.m_itemIndex
= hdr
->iItem
;
1521 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1524 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1525 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1526 switch( nmcd
.dwDrawStage
)
1529 // if we've got any items with non standard attributes,
1530 // notify us before painting each item
1531 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1535 case CDDS_ITEMPREPAINT
:
1537 wxListItemAttr
*attr
=
1538 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1542 // nothing to do for this item
1543 return CDRF_DODEFAULT
;
1547 wxColour colText
, colBack
;
1548 if ( attr
->HasFont() )
1550 wxFont font
= attr
->GetFont();
1551 hFont
= (HFONT
)font
.GetResourceHandle();
1558 if ( attr
->HasTextColour() )
1560 colText
= attr
->GetTextColour();
1564 colText
= GetTextColour();
1567 if ( attr
->HasBackgroundColour() )
1569 colBack
= attr
->GetBackgroundColour();
1573 colBack
= GetBackgroundColour();
1576 // note that if we wanted to set colours for
1577 // individual columns (subitems), we would have
1578 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1581 ::SelectObject(nmcd
.hdc
, hFont
);
1583 *result
= CDRF_NEWFONT
;
1587 *result
= CDRF_DODEFAULT
;
1590 lplvcd
->clrText
= wxColourToRGB(colText
);
1591 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1597 *result
= CDRF_DODEFAULT
;
1602 #endif // _WIN32_IE >= 0x300
1605 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1608 // process the event
1609 // -----------------
1611 event
.SetEventObject( this );
1612 event
.SetEventType(eventType
);
1614 if ( !GetEventHandler()->ProcessEvent(event
) )
1620 switch ( nmhdr
->code
)
1622 case LVN_DELETEALLITEMS
:
1623 // always return TRUE to suppress all additional LVN_DELETEITEM
1624 // notifications - this makes deleting all items from a list ctrl
1630 case LVN_GETDISPINFO
:
1632 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1633 if ( info
->item
.mask
& LVIF_TEXT
)
1635 if ( !event
.m_item
.m_text
.IsNull() )
1637 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1638 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1641 // wxConvertToMSWListItem(this, event.m_item, info->item);
1644 case LVN_ENDLABELEDIT
:
1646 *result
= event
.IsAllowed();
1651 *result
= !event
.IsAllowed();
1656 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1658 // Remove the first element if 3 strings exist
1659 if ( m_stringPool
.Number() == 3 )
1661 wxNode
*node
= m_stringPool
.First();
1662 delete[] (char *)node
->Data();
1665 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1666 return (wxChar
*)node
->Data();
1669 // ----------------------------------------------------------------------------
1671 // ----------------------------------------------------------------------------
1673 // List item structure
1674 wxListItem::wxListItem()
1684 m_format
= wxLIST_FORMAT_CENTRE
;
1690 void wxListItem::Clear()
1699 m_format
= wxLIST_FORMAT_CENTRE
;
1701 m_text
= wxEmptyString
;
1703 if (m_attr
) delete m_attr
;
1707 void wxListItem::ClearAttributes()
1709 if (m_attr
) delete m_attr
;
1713 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1715 info
.m_data
= lvItem
.lParam
;
1718 info
.m_stateMask
= 0;
1719 info
.m_itemId
= lvItem
.iItem
;
1721 long oldMask
= lvItem
.mask
;
1723 bool needText
= FALSE
;
1724 if (getFullInfo
!= 0)
1726 if ( lvItem
.mask
& LVIF_TEXT
)
1733 lvItem
.pszText
= new wxChar
[513];
1734 lvItem
.cchTextMax
= 512;
1736 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1737 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1738 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1741 if ( lvItem
.mask
& LVIF_STATE
)
1743 info
.m_mask
|= wxLIST_MASK_STATE
;
1745 if ( lvItem
.stateMask
& LVIS_CUT
)
1747 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1748 if ( lvItem
.state
& LVIS_CUT
)
1749 info
.m_state
|= wxLIST_STATE_CUT
;
1751 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1753 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1754 if ( lvItem
.state
& LVIS_DROPHILITED
)
1755 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1757 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1759 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1760 if ( lvItem
.state
& LVIS_FOCUSED
)
1761 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1763 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1765 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1766 if ( lvItem
.state
& LVIS_SELECTED
)
1767 info
.m_state
|= wxLIST_STATE_SELECTED
;
1771 if ( lvItem
.mask
& LVIF_TEXT
)
1773 info
.m_mask
|= wxLIST_MASK_TEXT
;
1774 info
.m_text
= lvItem
.pszText
;
1776 if ( lvItem
.mask
& LVIF_IMAGE
)
1778 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1779 info
.m_image
= lvItem
.iImage
;
1781 if ( lvItem
.mask
& LVIF_PARAM
)
1782 info
.m_mask
|= wxLIST_MASK_DATA
;
1783 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1784 info
.m_mask
|= wxLIST_SET_ITEM
;
1785 info
.m_col
= lvItem
.iSubItem
;
1790 delete[] lvItem
.pszText
;
1792 lvItem
.mask
= oldMask
;
1795 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1797 lvItem
.iItem
= (int) info
.m_itemId
;
1799 lvItem
.iImage
= info
.m_image
;
1800 lvItem
.lParam
= info
.m_data
;
1801 lvItem
.stateMask
= 0;
1804 lvItem
.iSubItem
= info
.m_col
;
1806 if (info
.m_mask
& wxLIST_MASK_STATE
)
1808 lvItem
.mask
|= LVIF_STATE
;
1809 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1811 lvItem
.stateMask
|= LVIS_CUT
;
1812 if (info
.m_state
& wxLIST_STATE_CUT
)
1813 lvItem
.state
|= LVIS_CUT
;
1815 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1817 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1818 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1819 lvItem
.state
|= LVIS_DROPHILITED
;
1821 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1823 lvItem
.stateMask
|= LVIS_FOCUSED
;
1824 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1825 lvItem
.state
|= LVIS_FOCUSED
;
1827 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1829 lvItem
.stateMask
|= LVIS_SELECTED
;
1830 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1831 lvItem
.state
|= LVIS_SELECTED
;
1835 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1837 lvItem
.mask
|= LVIF_TEXT
;
1838 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1840 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1844 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1845 if ( lvItem
.pszText
)
1846 lvItem
.cchTextMax
= info
.m_text
.Length();
1848 lvItem
.cchTextMax
= 0;
1851 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1852 lvItem
.mask
|= LVIF_IMAGE
;
1853 if (info
.m_mask
& wxLIST_MASK_DATA
)
1854 lvItem
.mask
|= LVIF_PARAM
;
1857 // ----------------------------------------------------------------------------
1859 // ----------------------------------------------------------------------------
1861 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1863 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1864 : wxNotifyEvent(commandType
, id
)
1870 m_cancelled
= FALSE
;