1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "listctrl.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/listctrl.h"
40 #include "wx/msw/private.h"
42 #if defined(__GNUWIN32__) && !defined(wxUSE_NORLANDER_HEADERS)
43 #include "wx/msw/gnuwin32/extra.h"
50 (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& tvItem
);
58 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& tvItem
, HWND getFullInfo
= 0);
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
65 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
67 // ============================================================================
69 // ============================================================================
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 void wxListEvent::CopyObject(wxObject
& object_dest
) const
77 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
79 wxNotifyEvent::CopyObject(object_dest
);
82 obj
->m_itemIndex
= m_itemIndex
;
83 obj
->m_oldItemIndex
= m_oldItemIndex
;
85 obj
->m_cancelled
= m_cancelled
;
86 obj
->m_pointDrag
= m_pointDrag
;
87 obj
->m_item
.m_mask
= m_item
.m_mask
;
88 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
89 obj
->m_item
.m_col
= m_item
.m_col
;
90 obj
->m_item
.m_state
= m_item
.m_state
;
91 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
92 obj
->m_item
.m_text
= m_item
.m_text
;
93 obj
->m_item
.m_image
= m_item
.m_image
;
94 obj
->m_item
.m_data
= m_item
.m_data
;
95 obj
->m_item
.m_format
= m_item
.m_format
;
96 obj
->m_item
.m_width
= m_item
.m_width
;
98 if ( m_item
.HasAttributes() )
100 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
101 obj
->m_item
.SetBackgroundColour(m_item
.GetBackgroundColour());
102 obj
->m_item
.SetFont(m_item
.GetFont());
106 // ----------------------------------------------------------------------------
107 // wxListCtrl construction
108 // ----------------------------------------------------------------------------
110 void wxListCtrl::Init()
112 m_imageListNormal
= NULL
;
113 m_imageListSmall
= NULL
;
114 m_imageListState
= NULL
;
118 m_hasAnyAttr
= FALSE
;
121 bool wxListCtrl::Create(wxWindow
*parent
,
126 const wxValidator
& validator
,
127 const wxString
& name
)
129 SetValidator(validator
);
137 m_windowStyle
= style
;
150 m_windowId
= (id
== -1) ? NewControlId() : id
;
152 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
153 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
154 if ( wxStyleHasBorder(m_windowStyle
) )
156 m_baseStyle
= wstyle
;
158 if ( !DoCreateControl(x
, y
, width
, height
) )
162 parent
->AddChild(this);
167 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
169 DWORD wstyle
= m_baseStyle
;
172 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
174 // Even with extended styles, need to combine with WS_BORDER
175 // for them to look right.
179 long oldStyle
= 0; // Dummy
180 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
182 // Create the ListView control.
183 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
188 GetWinHwnd(GetParent()),
195 wxLogError(wxT("Can't create list control window."));
200 // for comctl32.dll v 4.70+ we want to have this attribute because it's
201 // prettier (and also because wxGTK does it like this)
202 #ifdef ListView_SetExtendedListViewStyle
203 if ( wstyle
& LVS_REPORT
)
205 ListView_SetExtendedListViewStyle(GetHwnd(),
206 LVS_EX_FULLROWSELECT
);
208 #endif // ListView_SetExtendedListViewStyle
210 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
211 SetForegroundColour(GetParent()->GetForegroundColour());
218 void wxListCtrl::UpdateStyle()
222 // The new window view style
224 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
225 dwStyleNew
|= m_baseStyle
;
227 // Get the current window style.
228 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
230 // Only set the window style if the view bits have changed.
231 if ( dwStyleOld
!= dwStyleNew
)
233 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
238 wxListCtrl::~wxListCtrl()
242 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
244 delete (wxListItemAttr
*)node
->Data();
250 m_textCtrl
->UnsubclassWin();
251 m_textCtrl
->SetHWND(0);
257 // ----------------------------------------------------------------------------
258 // set/get/change style
259 // ----------------------------------------------------------------------------
261 // Add or remove a single window style
262 void wxListCtrl::SetSingleStyle(long style
, bool add
)
264 long flag
= GetWindowStyleFlag();
266 // Get rid of conflicting styles
269 if ( style
& wxLC_MASK_TYPE
)
270 flag
= flag
& ~wxLC_MASK_TYPE
;
271 if ( style
& wxLC_MASK_ALIGN
)
272 flag
= flag
& ~wxLC_MASK_ALIGN
;
273 if ( style
& wxLC_MASK_SORT
)
274 flag
= flag
& ~wxLC_MASK_SORT
;
290 m_windowStyle
= flag
;
295 // Set the whole window style
296 void wxListCtrl::SetWindowStyleFlag(long flag
)
298 m_windowStyle
= flag
;
303 // Can be just a single style, or a bitlist
304 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
307 if ( style
& wxLC_ICON
)
309 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
310 oldStyle
-= LVS_SMALLICON
;
311 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
312 oldStyle
-= LVS_REPORT
;
313 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
314 oldStyle
-= LVS_LIST
;
318 if ( style
& wxLC_SMALL_ICON
)
320 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
321 oldStyle
-= LVS_ICON
;
322 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
323 oldStyle
-= LVS_REPORT
;
324 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
325 oldStyle
-= LVS_LIST
;
326 wstyle
|= LVS_SMALLICON
;
329 if ( style
& wxLC_LIST
)
331 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
332 oldStyle
-= LVS_ICON
;
333 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
334 oldStyle
-= LVS_REPORT
;
335 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
336 oldStyle
-= LVS_SMALLICON
;
340 if ( style
& wxLC_REPORT
)
342 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
343 oldStyle
-= LVS_ICON
;
344 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
345 oldStyle
-= LVS_LIST
;
346 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
347 oldStyle
-= LVS_SMALLICON
;
349 wstyle
|= LVS_REPORT
;
352 if ( style
& wxLC_ALIGN_LEFT
)
354 if ( oldStyle
& LVS_ALIGNTOP
)
355 oldStyle
-= LVS_ALIGNTOP
;
356 wstyle
|= LVS_ALIGNLEFT
;
359 if ( style
& wxLC_ALIGN_TOP
)
361 if ( oldStyle
& LVS_ALIGNLEFT
)
362 oldStyle
-= LVS_ALIGNLEFT
;
363 wstyle
|= LVS_ALIGNTOP
;
366 if ( style
& wxLC_AUTOARRANGE
)
367 wstyle
|= LVS_AUTOARRANGE
;
369 // Apparently, no such style (documentation wrong?)
371 if ( style & wxLC_BUTTON )
372 wstyle |= LVS_BUTTON;
375 if ( style
& wxLC_NO_SORT_HEADER
)
376 wstyle
|= LVS_NOSORTHEADER
;
378 if ( style
& wxLC_NO_HEADER
)
379 wstyle
|= LVS_NOCOLUMNHEADER
;
381 if ( style
& wxLC_EDIT_LABELS
)
382 wstyle
|= LVS_EDITLABELS
;
384 if ( style
& wxLC_SINGLE_SEL
)
385 wstyle
|= LVS_SINGLESEL
;
387 if ( style
& wxLC_SORT_ASCENDING
)
389 if ( oldStyle
& LVS_SORTDESCENDING
)
390 oldStyle
-= LVS_SORTDESCENDING
;
391 wstyle
|= LVS_SORTASCENDING
;
394 if ( style
& wxLC_SORT_DESCENDING
)
396 if ( oldStyle
& LVS_SORTASCENDING
)
397 oldStyle
-= LVS_SORTASCENDING
;
398 wstyle
|= LVS_SORTDESCENDING
;
404 // ----------------------------------------------------------------------------
406 // ----------------------------------------------------------------------------
408 // Sets the background colour (GetBackgroundColour already implicit in
410 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
412 if ( !wxWindow::SetBackgroundColour(col
) )
415 ListView_SetBkColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
420 // Gets information about this column
421 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
426 lvCol
.pszText
= NULL
;
428 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
430 lvCol
.mask
|= LVCF_TEXT
;
431 lvCol
.pszText
= new wxChar
[513];
432 lvCol
.cchTextMax
= 512;
435 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
437 // item.m_subItem = lvCol.iSubItem;
438 item
.m_width
= lvCol
.cx
;
440 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
442 item
.m_text
= lvCol
.pszText
;
443 delete[] lvCol
.pszText
;
446 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
448 if (lvCol
.fmt
== LVCFMT_LEFT
)
449 item
.m_format
= wxLIST_FORMAT_LEFT
;
450 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
451 item
.m_format
= wxLIST_FORMAT_RIGHT
;
452 else if (lvCol
.fmt
== LVCFMT_CENTER
)
453 item
.m_format
= wxLIST_FORMAT_CENTRE
;
459 // Sets information about this column
460 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
465 lvCol
.pszText
= NULL
;
467 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
469 lvCol
.mask
|= LVCF_TEXT
;
470 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
471 lvCol
.cchTextMax
= 0; // Ignored
473 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
475 lvCol
.mask
|= LVCF_FMT
;
477 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
478 lvCol
.fmt
= LVCFMT_LEFT
;
479 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
480 lvCol
.fmt
= LVCFMT_RIGHT
;
481 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
482 lvCol
.fmt
= LVCFMT_CENTER
;
485 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
487 lvCol
.mask
|= LVCF_WIDTH
;
488 lvCol
.cx
= item
.m_width
;
490 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
491 lvCol
.cx
= LVSCW_AUTOSIZE
;
492 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
493 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
495 lvCol
.mask
|= LVCF_SUBITEM
;
496 lvCol
.iSubItem
= col
;
497 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
500 // Gets the column width
501 int wxListCtrl::GetColumnWidth(int col
) const
503 return ListView_GetColumnWidth(GetHwnd(), col
);
506 // Sets the column width
507 bool wxListCtrl::SetColumnWidth(int col
, int width
)
510 if ( m_windowStyle
& wxLC_LIST
)
514 if ( width2
== wxLIST_AUTOSIZE
)
515 width2
= LVSCW_AUTOSIZE
;
516 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
517 width2
= LVSCW_AUTOSIZE_USEHEADER
;
519 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
522 // Gets the number of items that can fit vertically in the
523 // visible area of the list control (list or report view)
524 // or the total number of items in the list control (icon
525 // or small icon view)
526 int wxListCtrl::GetCountPerPage(void) const
528 return ListView_GetCountPerPage(GetHwnd());
531 // Gets the edit control for editing labels.
532 wxTextCtrl
* wxListCtrl::GetEditControl(void) const
537 // Gets information about the item
538 bool wxListCtrl::GetItem(wxListItem
& info
) const
541 wxZeroMemory(lvItem
);
543 lvItem
.iItem
= info
.m_itemId
;
544 lvItem
.iSubItem
= info
.m_col
;
546 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
548 lvItem
.mask
|= LVIF_TEXT
;
549 lvItem
.pszText
= new wxChar
[513];
550 lvItem
.cchTextMax
= 512;
554 lvItem
.pszText
= NULL
;
557 if (info
.m_mask
& wxLIST_MASK_DATA
)
558 lvItem
.mask
|= LVIF_PARAM
;
560 if ( info
.m_mask
& wxLIST_MASK_STATE
)
562 lvItem
.mask
|= LVIF_STATE
;
563 // the other bits are hardly interesting anyhow
564 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
567 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
570 wxLogError(_("Couldn't retrieve information about list control item %d."),
575 wxConvertFromMSWListItem(this, info
, lvItem
);
579 delete[] lvItem
.pszText
;
584 // Sets information about the item
585 bool wxListCtrl::SetItem(wxListItem
& info
)
588 wxConvertToMSWListItem(this, info
, item
);
590 // check whether it has any custom attributes
591 if ( info
.HasAttributes() )
593 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
599 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
600 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
602 // make the change visible
603 ListView_Update(GetHwnd(), item
.iItem
);
609 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
613 info
.m_mask
= wxLIST_MASK_TEXT
;
614 info
.m_itemId
= index
;
618 info
.m_image
= imageId
;
619 info
.m_mask
|= wxLIST_MASK_IMAGE
;
621 return SetItem(info
);
625 // Gets the item state
626 int wxListCtrl::GetItemState(long item
, long stateMask
) const
630 info
.m_mask
= wxLIST_MASK_STATE
;
631 info
.m_stateMask
= stateMask
;
632 info
.m_itemId
= item
;
640 // Sets the item state
641 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
645 info
.m_mask
= wxLIST_MASK_STATE
;
646 info
.m_state
= state
;
647 info
.m_stateMask
= stateMask
;
648 info
.m_itemId
= item
;
650 return SetItem(info
);
653 // Sets the item image
654 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
658 info
.m_mask
= wxLIST_MASK_IMAGE
;
659 info
.m_image
= image
;
660 info
.m_itemId
= item
;
662 return SetItem(info
);
665 // Gets the item text
666 wxString
wxListCtrl::GetItemText(long item
) const
670 info
.m_mask
= wxLIST_MASK_TEXT
;
671 info
.m_itemId
= item
;
678 // Sets the item text
679 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
683 info
.m_mask
= wxLIST_MASK_TEXT
;
684 info
.m_itemId
= item
;
690 // Gets the item data
691 long wxListCtrl::GetItemData(long item
) const
695 info
.m_mask
= wxLIST_MASK_DATA
;
696 info
.m_itemId
= item
;
703 // Sets the item data
704 bool wxListCtrl::SetItemData(long item
, long data
)
708 info
.m_mask
= wxLIST_MASK_DATA
;
709 info
.m_itemId
= item
;
712 return SetItem(info
);
715 // Gets the item rectangle
716 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
720 int code2
= LVIR_BOUNDS
;
721 if ( code
== wxLIST_RECT_BOUNDS
)
723 else if ( code
== wxLIST_RECT_ICON
)
725 else if ( code
== wxLIST_RECT_LABEL
)
729 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
731 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
736 rect
.width
= rect2
.right
- rect2
.left
;
737 rect
.height
= rect2
.bottom
- rect2
.left
;
741 // Gets the item position
742 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
746 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
748 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
752 // Sets the item position.
753 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
755 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
758 // Gets the number of items in the list control
759 int wxListCtrl::GetItemCount(void) const
761 return ListView_GetItemCount(GetHwnd());
764 // Retrieves the spacing between icons in pixels.
765 // If small is TRUE, gets the spacing for the small icon
766 // view, otherwise the large icon view.
767 int wxListCtrl::GetItemSpacing(bool isSmall
) const
769 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
772 // Gets the number of selected items in the list control
773 int wxListCtrl::GetSelectedItemCount(void) const
775 return ListView_GetSelectedCount(GetHwnd());
778 // Gets the text colour of the listview
779 wxColour
wxListCtrl::GetTextColour(void) const
781 COLORREF ref
= ListView_GetTextColor(GetHwnd());
782 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
786 // Sets the text colour of the listview
787 void wxListCtrl::SetTextColour(const wxColour
& col
)
789 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
792 // Gets the index of the topmost visible item when in
793 // list or report view
794 long wxListCtrl::GetTopItem(void) const
796 return (long) ListView_GetTopIndex(GetHwnd());
799 // Searches for an item, starting from 'item'.
800 // 'geometry' is one of
801 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
802 // 'state' is a state bit flag, one or more of
803 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
804 // item can be -1 to find the first item that matches the
806 // Returns the item or -1 if unsuccessful.
807 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
811 if ( geom
== wxLIST_NEXT_ABOVE
)
813 if ( geom
== wxLIST_NEXT_ALL
)
815 if ( geom
== wxLIST_NEXT_BELOW
)
817 if ( geom
== wxLIST_NEXT_LEFT
)
818 flags
|= LVNI_TOLEFT
;
819 if ( geom
== wxLIST_NEXT_RIGHT
)
820 flags
|= LVNI_TORIGHT
;
822 if ( state
& wxLIST_STATE_CUT
)
824 if ( state
& wxLIST_STATE_DROPHILITED
)
825 flags
|= LVNI_DROPHILITED
;
826 if ( state
& wxLIST_STATE_FOCUSED
)
827 flags
|= LVNI_FOCUSED
;
828 if ( state
& wxLIST_STATE_SELECTED
)
829 flags
|= LVNI_SELECTED
;
831 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
835 wxImageList
*wxListCtrl::GetImageList(int which
) const
837 if ( which
== wxIMAGE_LIST_NORMAL
)
839 return m_imageListNormal
;
841 else if ( which
== wxIMAGE_LIST_SMALL
)
843 return m_imageListSmall
;
845 else if ( which
== wxIMAGE_LIST_STATE
)
847 return m_imageListState
;
852 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
855 if ( which
== wxIMAGE_LIST_NORMAL
)
857 flags
= LVSIL_NORMAL
;
858 m_imageListNormal
= imageList
;
860 else if ( which
== wxIMAGE_LIST_SMALL
)
863 m_imageListSmall
= imageList
;
865 else if ( which
== wxIMAGE_LIST_STATE
)
868 m_imageListState
= imageList
;
870 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
873 // ----------------------------------------------------------------------------
875 // ----------------------------------------------------------------------------
877 // Arranges the items
878 bool wxListCtrl::Arrange(int flag
)
881 if ( flag
== wxLIST_ALIGN_LEFT
)
882 code
= LVA_ALIGNLEFT
;
883 else if ( flag
== wxLIST_ALIGN_TOP
)
885 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
887 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
888 code
= LVA_SNAPTOGRID
;
890 return (ListView_Arrange(GetHwnd(), code
) != 0);
894 bool wxListCtrl::DeleteItem(long item
)
896 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
900 bool wxListCtrl::DeleteAllItems()
902 return (ListView_DeleteAllItems(GetHwnd()) != 0);
906 bool wxListCtrl::DeleteAllColumns()
908 while ( m_colCount
> 0 )
910 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
912 wxLogLastError("ListView_DeleteColumn");
920 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
926 bool wxListCtrl::DeleteColumn(int col
)
928 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
930 if ( success
&& (m_colCount
> 0) )
935 // Clears items, and columns if there are any.
936 void wxListCtrl::ClearAll()
939 if ( m_colCount
> 0 )
943 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
945 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
947 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
951 m_textCtrl
->UnsubclassWin();
952 m_textCtrl
->SetHWND(0);
957 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
958 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
959 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
964 // End label editing, optionally cancelling the edit
965 bool wxListCtrl::EndEditLabel(bool cancel
)
969 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
971 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
975 m_textCtrl->UnsubclassWin();
976 m_textCtrl->SetHWND(0);
986 // Ensures this item is visible
987 bool wxListCtrl::EnsureVisible(long item
)
989 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
992 // Find an item whose label matches this string, starting from the item after 'start'
993 // or the beginning if 'start' is -1.
994 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
996 LV_FINDINFO findInfo
;
998 findInfo
.flags
= LVFI_STRING
;
1000 findInfo
.flags
|= LVFI_STRING
;
1001 findInfo
.psz
= WXSTRINGCAST str
;
1003 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1006 // Find an item whose data matches this data, starting from the item after 'start'
1007 // or the beginning if 'start' is -1.
1008 long wxListCtrl::FindItem(long start
, long data
)
1010 LV_FINDINFO findInfo
;
1012 findInfo
.flags
= LVFI_PARAM
;
1013 findInfo
.lParam
= data
;
1015 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1018 // Find an item nearest this position in the specified direction, starting from
1019 // the item after 'start' or the beginning if 'start' is -1.
1020 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1022 LV_FINDINFO findInfo
;
1024 findInfo
.flags
= LVFI_NEARESTXY
;
1025 findInfo
.pt
.x
= pt
.x
;
1026 findInfo
.pt
.y
= pt
.y
;
1027 findInfo
.vkDirection
= VK_RIGHT
;
1029 if ( direction
== wxLIST_FIND_UP
)
1030 findInfo
.vkDirection
= VK_UP
;
1031 else if ( direction
== wxLIST_FIND_DOWN
)
1032 findInfo
.vkDirection
= VK_DOWN
;
1033 else if ( direction
== wxLIST_FIND_LEFT
)
1034 findInfo
.vkDirection
= VK_LEFT
;
1035 else if ( direction
== wxLIST_FIND_RIGHT
)
1036 findInfo
.vkDirection
= VK_RIGHT
;
1038 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1041 // Determines which item (if any) is at the specified point,
1042 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1043 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1045 LV_HITTESTINFO hitTestInfo
;
1046 hitTestInfo
.pt
.x
= (int) point
.x
;
1047 hitTestInfo
.pt
.y
= (int) point
.y
;
1049 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1052 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1053 flags
|= wxLIST_HITTEST_ABOVE
;
1054 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1055 flags
|= wxLIST_HITTEST_BELOW
;
1056 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1057 flags
|= wxLIST_HITTEST_NOWHERE
;
1058 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1059 flags
|= wxLIST_HITTEST_ONITEMICON
;
1060 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1061 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1062 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1063 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1064 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1065 flags
|= wxLIST_HITTEST_TOLEFT
;
1066 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1067 flags
|= wxLIST_HITTEST_TORIGHT
;
1069 return (long) hitTestInfo
.iItem
;
1072 // Inserts an item, returning the index of the new item if successful,
1074 long wxListCtrl::InsertItem(wxListItem
& info
)
1077 wxConvertToMSWListItem(this, info
, item
);
1079 // check whether it has any custom attributes
1080 if ( info
.HasAttributes() )
1082 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1084 m_hasAnyAttr
= TRUE
;
1087 return (long) ListView_InsertItem(GetHwnd(), & item
);
1090 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1093 info
.m_text
= label
;
1094 info
.m_mask
= wxLIST_MASK_TEXT
;
1095 info
.m_itemId
= index
;
1096 return InsertItem(info
);
1099 // Inserts an image item
1100 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1103 info
.m_image
= imageIndex
;
1104 info
.m_mask
= wxLIST_MASK_IMAGE
;
1105 info
.m_itemId
= index
;
1106 return InsertItem(info
);
1109 // Inserts an image/string item
1110 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1113 info
.m_image
= imageIndex
;
1114 info
.m_text
= label
;
1115 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1116 info
.m_itemId
= index
;
1117 return InsertItem(info
);
1120 // For list view mode (only), inserts a column.
1121 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1126 lvCol
.pszText
= NULL
;
1128 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1130 lvCol
.mask
|= LVCF_TEXT
;
1131 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1132 lvCol
.cchTextMax
= 0; // Ignored
1134 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1136 lvCol
.mask
|= LVCF_FMT
;
1138 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1139 lvCol
.fmt
= LVCFMT_LEFT
;
1140 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1141 lvCol
.fmt
= LVCFMT_RIGHT
;
1142 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1143 lvCol
.fmt
= LVCFMT_CENTER
;
1146 lvCol
.mask
|= LVCF_WIDTH
;
1147 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1149 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1150 lvCol
.cx
= LVSCW_AUTOSIZE
;
1151 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1152 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1154 lvCol
.cx
= item
.m_width
;
1158 // always give some width to the new column: this one is compatible
1163 lvCol
.mask
|= LVCF_SUBITEM
;
1164 lvCol
.iSubItem
= col
;
1166 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1173 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1180 long wxListCtrl::InsertColumn(long col
,
1181 const wxString
& heading
,
1186 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1187 item
.m_text
= heading
;
1190 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1191 item
.m_width
= width
;
1193 item
.m_format
= format
;
1195 return InsertColumn(col
, item
);
1198 // Scrolls the list control. If in icon, small icon or report view mode,
1199 // x specifies the number of pixels to scroll. If in list view mode, x
1200 // specifies the number of columns to scroll.
1201 // If in icon, small icon or list view mode, y specifies the number of pixels
1202 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1203 bool wxListCtrl::ScrollList(int dx
, int dy
)
1205 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1210 // fn is a function which takes 3 long arguments: item1, item2, data.
1211 // item1 is the long data associated with a first item (NOT the index).
1212 // item2 is the long data associated with a second item (NOT the index).
1213 // data is the same value as passed to SortItems.
1214 // The return value is a negative number if the first item should precede the second
1215 // item, a positive number of the second item should precede the first,
1216 // or zero if the two items are equivalent.
1218 // data is arbitrary data to be passed to the sort function.
1219 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1221 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1224 // ----------------------------------------------------------------------------
1225 // message processing
1226 // ----------------------------------------------------------------------------
1228 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1230 if (cmd
== EN_UPDATE
)
1232 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1233 event
.SetEventObject( this );
1234 ProcessCommand(event
);
1237 else if (cmd
== EN_KILLFOCUS
)
1239 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1240 event
.SetEventObject( this );
1241 ProcessCommand(event
);
1248 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1250 // prepare the event
1251 // -----------------
1253 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1254 wxEventType eventType
= wxEVT_NULL
;
1255 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1256 switch ( nmhdr
->code
)
1258 case LVN_BEGINRDRAG
:
1259 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1263 if ( eventType
== wxEVT_NULL
)
1265 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1269 NM_LISTVIEW
*hdr
= (NM_LISTVIEW
*)lParam
;
1270 event
.m_itemIndex
= hdr
->iItem
;
1271 event
.m_pointDrag
.x
= hdr
->ptAction
.x
;
1272 event
.m_pointDrag
.y
= hdr
->ptAction
.y
;
1276 case LVN_BEGINLABELEDIT
:
1278 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1279 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1280 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1284 case LVN_COLUMNCLICK
:
1286 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1287 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1288 event
.m_itemIndex
= -1;
1289 event
.m_col
= hdr
->iSubItem
;
1293 case LVN_DELETEALLITEMS
:
1294 // what's the sense of generating a wxWin event for this when
1295 // it's absolutely not portable?
1297 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1298 event
.m_itemIndex
= -1;
1301 // return TRUE to suppress all additional LVN_DELETEITEM
1302 // notifications - this makes deleting all items from a list ctrl
1308 case LVN_DELETEITEM
:
1310 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1311 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1312 event
.m_itemIndex
= hdr
->iItem
;
1316 delete (wxListItemAttr
*)m_attrs
.Delete(hdr
->iItem
);
1321 case LVN_ENDLABELEDIT
:
1323 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1324 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1325 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1326 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1331 case LVN_SETDISPINFO
:
1333 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1334 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1335 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1339 case LVN_GETDISPINFO
:
1340 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1341 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1345 // TODO: some text buffering here, I think
1346 // TODO: API for getting Windows to retrieve values
1348 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1349 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1350 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1357 case LVN_INSERTITEM
:
1359 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1360 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1361 event
.m_itemIndex
= hdr
->iItem
;
1365 case LVN_ITEMCHANGED
:
1367 // This needs to be sent to wxListCtrl as a rather more
1368 // concrete event. For now, just detect a selection
1370 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1371 if ( (hdr
->uNewState
& LVIS_SELECTED
) && !(hdr
->uOldState
& LVIS_SELECTED
) )
1373 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1374 event
.m_itemIndex
= hdr
->iItem
;
1376 else if ( !(hdr
->uNewState
& LVIS_SELECTED
) && (hdr
->uOldState
& LVIS_SELECTED
) )
1378 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1379 event
.m_itemIndex
= hdr
->iItem
;
1388 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1389 WORD wVKey
= info
->wVKey
;
1391 // get the current selection
1392 long lItem
= GetNextItem(-1,
1394 wxLIST_STATE_SELECTED
);
1396 // <Enter> or <Space> activate the selected item if any
1397 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1399 // TODO this behaviour probably should be optional
1400 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1401 event
.m_itemIndex
= lItem
;
1405 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1406 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1412 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1414 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1419 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1421 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1422 NM_LISTVIEW
* hdr
= (NM_LISTVIEW
*)lParam
;
1423 event
.m_itemIndex
= hdr
->iItem
;
1428 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1429 subclass and check for the actual WM_RBUTTONDOWN message, because
1430 NM_RCLICK waits for the WM_RBUTTONUP message as well before firing off.
1431 We want to have notify events for both down -and- up. */
1433 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), don't do
1435 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) ) {
1439 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1440 LV_HITTESTINFO lvhti
;
1441 wxZeroMemory(lvhti
);
1443 ::GetCursorPos(&(lvhti
.pt
));
1444 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1445 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1447 if ( lvhti
.flags
& LVHT_ONITEM
)
1449 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1450 event
.m_itemIndex
= lvhti
.iItem
;
1457 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1459 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1461 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1466 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1467 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1468 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1469 event
.m_itemIndex
= hdr
->iItem
;
1474 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1477 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1478 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1479 switch( nmcd
.dwDrawStage
)
1482 // if we've got any items with non standard attributes,
1483 // notify us before painting each item
1484 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1488 case CDDS_ITEMPREPAINT
:
1490 wxListItemAttr
*attr
=
1491 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1495 // nothing to do for this item
1496 return CDRF_DODEFAULT
;
1500 wxColour colText
, colBack
;
1501 if ( attr
->HasFont() )
1503 wxFont font
= attr
->GetFont();
1504 hFont
= (HFONT
)font
.GetResourceHandle();
1511 if ( attr
->HasTextColour() )
1513 colText
= attr
->GetTextColour();
1517 colText
= GetTextColour();
1520 if ( attr
->HasBackgroundColour() )
1522 colBack
= attr
->GetBackgroundColour();
1526 colBack
= GetBackgroundColour();
1529 // note that if we wanted to set colours for
1530 // individual columns (subitems), we would have
1531 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1534 ::SelectObject(nmcd
.hdc
, hFont
);
1536 *result
= CDRF_NEWFONT
;
1540 *result
= CDRF_DODEFAULT
;
1543 lplvcd
->clrText
= wxColourToRGB(colText
);
1544 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1550 *result
= CDRF_DODEFAULT
;
1555 #endif // _WIN32_IE >= 0x300
1558 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1561 // process the event
1562 // -----------------
1564 event
.SetEventObject( this );
1565 event
.SetEventType(eventType
);
1567 if ( !GetEventHandler()->ProcessEvent(event
) )
1573 switch ( (int)nmhdr
->code
)
1575 case LVN_GETDISPINFO
:
1577 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1578 if ( info
->item
.mask
& LVIF_TEXT
)
1580 if ( !event
.m_item
.m_text
.IsNull() )
1582 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1583 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1586 // wxConvertToMSWListItem(this, event.m_item, info->item);
1589 case LVN_ENDLABELEDIT
:
1591 *result
= event
.IsAllowed();
1598 *result
= !event
.IsAllowed();
1603 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1605 // Remove the first element if 3 strings exist
1606 if ( m_stringPool
.Number() == 3 )
1608 wxNode
*node
= m_stringPool
.First();
1609 delete[] (char *)node
->Data();
1612 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1613 return (wxChar
*)node
->Data();
1616 // ----------------------------------------------------------------------------
1618 // ----------------------------------------------------------------------------
1620 // List item structure
1621 wxListItem::wxListItem()
1631 m_format
= wxLIST_FORMAT_CENTRE
;
1637 void wxListItem::Clear()
1646 m_format
= wxLIST_FORMAT_CENTRE
;
1648 m_text
= wxEmptyString
;
1650 if (m_attr
) delete m_attr
;
1654 void wxListItem::ClearAttributes()
1656 if (m_attr
) delete m_attr
;
1660 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1662 info
.m_data
= lvItem
.lParam
;
1665 info
.m_stateMask
= 0;
1666 info
.m_itemId
= lvItem
.iItem
;
1668 long oldMask
= lvItem
.mask
;
1670 bool needText
= FALSE
;
1671 if (getFullInfo
!= 0)
1673 if ( lvItem
.mask
& LVIF_TEXT
)
1680 lvItem
.pszText
= new wxChar
[513];
1681 lvItem
.cchTextMax
= 512;
1683 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1684 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1685 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1688 if ( lvItem
.mask
& LVIF_STATE
)
1690 info
.m_mask
|= wxLIST_MASK_STATE
;
1692 if ( lvItem
.stateMask
& LVIS_CUT
)
1694 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1695 if ( lvItem
.state
& LVIS_CUT
)
1696 info
.m_state
|= wxLIST_STATE_CUT
;
1698 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1700 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1701 if ( lvItem
.state
& LVIS_DROPHILITED
)
1702 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1704 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1706 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1707 if ( lvItem
.state
& LVIS_FOCUSED
)
1708 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1710 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1712 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1713 if ( lvItem
.state
& LVIS_SELECTED
)
1714 info
.m_state
|= wxLIST_STATE_SELECTED
;
1718 if ( lvItem
.mask
& LVIF_TEXT
)
1720 info
.m_mask
|= wxLIST_MASK_TEXT
;
1721 info
.m_text
= lvItem
.pszText
;
1723 if ( lvItem
.mask
& LVIF_IMAGE
)
1725 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1726 info
.m_image
= lvItem
.iImage
;
1728 if ( lvItem
.mask
& LVIF_PARAM
)
1729 info
.m_mask
|= wxLIST_MASK_DATA
;
1730 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1731 info
.m_mask
|= wxLIST_SET_ITEM
;
1732 info
.m_col
= lvItem
.iSubItem
;
1737 delete[] lvItem
.pszText
;
1739 lvItem
.mask
= oldMask
;
1742 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1744 lvItem
.iItem
= (int) info
.m_itemId
;
1746 lvItem
.iImage
= info
.m_image
;
1747 lvItem
.lParam
= info
.m_data
;
1748 lvItem
.stateMask
= 0;
1751 lvItem
.iSubItem
= info
.m_col
;
1753 if (info
.m_mask
& wxLIST_MASK_STATE
)
1755 lvItem
.mask
|= LVIF_STATE
;
1756 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1758 lvItem
.stateMask
|= LVIS_CUT
;
1759 if (info
.m_state
& wxLIST_STATE_CUT
)
1760 lvItem
.state
|= LVIS_CUT
;
1762 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1764 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1765 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1766 lvItem
.state
|= LVIS_DROPHILITED
;
1768 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1770 lvItem
.stateMask
|= LVIS_FOCUSED
;
1771 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1772 lvItem
.state
|= LVIS_FOCUSED
;
1774 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1776 lvItem
.stateMask
|= LVIS_SELECTED
;
1777 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1778 lvItem
.state
|= LVIS_SELECTED
;
1782 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1784 lvItem
.mask
|= LVIF_TEXT
;
1785 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1787 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1791 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1792 if ( lvItem
.pszText
)
1793 lvItem
.cchTextMax
= info
.m_text
.Length();
1795 lvItem
.cchTextMax
= 0;
1798 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1799 lvItem
.mask
|= LVIF_IMAGE
;
1800 if (info
.m_mask
& wxLIST_MASK_DATA
)
1801 lvItem
.mask
|= LVIF_PARAM
;
1804 // ----------------------------------------------------------------------------
1806 // ----------------------------------------------------------------------------
1808 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1810 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1811 : wxNotifyEvent(commandType
, id
)
1817 m_cancelled
= FALSE
;