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 BEGIN_EVENT_TABLE(wxListCtrl
, wxControl
)
82 EVT_PAINT(wxListCtrl::OnPaint
)
85 // ============================================================================
87 // ============================================================================
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 void wxListEvent::CopyObject(wxObject
& object_dest
) const
95 wxListEvent
*obj
= (wxListEvent
*)&object_dest
;
97 wxNotifyEvent::CopyObject(object_dest
);
100 obj
->m_itemIndex
= m_itemIndex
;
101 obj
->m_oldItemIndex
= m_oldItemIndex
;
103 obj
->m_cancelled
= m_cancelled
;
104 obj
->m_pointDrag
= m_pointDrag
;
105 obj
->m_item
.m_mask
= m_item
.m_mask
;
106 obj
->m_item
.m_itemId
= m_item
.m_itemId
;
107 obj
->m_item
.m_col
= m_item
.m_col
;
108 obj
->m_item
.m_state
= m_item
.m_state
;
109 obj
->m_item
.m_stateMask
= m_item
.m_stateMask
;
110 obj
->m_item
.m_text
= m_item
.m_text
;
111 obj
->m_item
.m_image
= m_item
.m_image
;
112 obj
->m_item
.m_data
= m_item
.m_data
;
113 obj
->m_item
.m_format
= m_item
.m_format
;
114 obj
->m_item
.m_width
= m_item
.m_width
;
116 if ( m_item
.HasAttributes() )
118 obj
->m_item
.SetTextColour(m_item
.GetTextColour());
119 obj
->m_item
.SetBackgroundColour(m_item
.GetBackgroundColour());
120 obj
->m_item
.SetFont(m_item
.GetFont());
124 // ----------------------------------------------------------------------------
125 // wxListCtrl construction
126 // ----------------------------------------------------------------------------
128 void wxListCtrl::Init()
130 m_imageListNormal
= NULL
;
131 m_imageListSmall
= NULL
;
132 m_imageListState
= NULL
;
136 m_hasAnyAttr
= FALSE
;
139 bool wxListCtrl::Create(wxWindow
*parent
,
144 const wxValidator
& validator
,
145 const wxString
& name
)
148 SetValidator(validator
);
149 #endif // wxUSE_VALIDATORS
158 m_windowStyle
= style
;
171 m_windowId
= (id
== -1) ? NewControlId() : id
;
173 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
174 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
175 if ( wxStyleHasBorder(m_windowStyle
) )
177 m_baseStyle
= wstyle
;
179 if ( !DoCreateControl(x
, y
, width
, height
) )
183 parent
->AddChild(this);
188 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
190 DWORD wstyle
= m_baseStyle
;
193 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
195 // Even with extended styles, need to combine with WS_BORDER
196 // for them to look right.
200 long oldStyle
= 0; // Dummy
201 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
203 // Create the ListView control.
204 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
209 GetWinHwnd(GetParent()),
216 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
221 // for comctl32.dll v 4.70+ we want to have this attribute because it's
222 // prettier (and also because wxGTK does it like this)
223 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
225 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
226 0, LVS_EX_FULLROWSELECT
);
229 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
230 SetForegroundColour(GetParent()->GetForegroundColour());
237 void wxListCtrl::UpdateStyle()
241 // The new window view style
243 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
244 dwStyleNew
|= m_baseStyle
;
246 // Get the current window style.
247 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
249 // Only set the window style if the view bits have changed.
250 if ( dwStyleOld
!= dwStyleNew
)
252 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
257 void wxListCtrl::FreeAllAttrs(bool dontRecreate
)
261 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
263 delete (wxListItemAttr
*)node
->Data();
269 m_attrs
.Create(wxKEY_INTEGER
, 1000); // just as def ctor
272 m_hasAnyAttr
= FALSE
;
276 wxListCtrl::~wxListCtrl()
278 FreeAllAttrs(TRUE
/* no need to recreate hash any more */);
282 m_textCtrl
->UnsubclassWin();
283 m_textCtrl
->SetHWND(0);
289 // ----------------------------------------------------------------------------
290 // set/get/change style
291 // ----------------------------------------------------------------------------
293 // Add or remove a single window style
294 void wxListCtrl::SetSingleStyle(long style
, bool add
)
296 long flag
= GetWindowStyleFlag();
298 // Get rid of conflicting styles
301 if ( style
& wxLC_MASK_TYPE
)
302 flag
= flag
& ~wxLC_MASK_TYPE
;
303 if ( style
& wxLC_MASK_ALIGN
)
304 flag
= flag
& ~wxLC_MASK_ALIGN
;
305 if ( style
& wxLC_MASK_SORT
)
306 flag
= flag
& ~wxLC_MASK_SORT
;
322 m_windowStyle
= flag
;
327 // Set the whole window style
328 void wxListCtrl::SetWindowStyleFlag(long flag
)
330 m_windowStyle
= flag
;
335 // Can be just a single style, or a bitlist
336 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
339 if ( style
& wxLC_ICON
)
341 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
342 oldStyle
-= LVS_SMALLICON
;
343 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
344 oldStyle
-= LVS_REPORT
;
345 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
346 oldStyle
-= LVS_LIST
;
350 if ( style
& wxLC_SMALL_ICON
)
352 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
353 oldStyle
-= LVS_ICON
;
354 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
355 oldStyle
-= LVS_REPORT
;
356 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
357 oldStyle
-= LVS_LIST
;
358 wstyle
|= LVS_SMALLICON
;
361 if ( style
& wxLC_LIST
)
363 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
364 oldStyle
-= LVS_ICON
;
365 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
366 oldStyle
-= LVS_REPORT
;
367 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
368 oldStyle
-= LVS_SMALLICON
;
372 if ( style
& wxLC_REPORT
)
374 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
375 oldStyle
-= LVS_ICON
;
376 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
377 oldStyle
-= LVS_LIST
;
378 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
379 oldStyle
-= LVS_SMALLICON
;
381 wstyle
|= LVS_REPORT
;
384 if ( style
& wxLC_ALIGN_LEFT
)
386 if ( oldStyle
& LVS_ALIGNTOP
)
387 oldStyle
-= LVS_ALIGNTOP
;
388 wstyle
|= LVS_ALIGNLEFT
;
391 if ( style
& wxLC_ALIGN_TOP
)
393 if ( oldStyle
& LVS_ALIGNLEFT
)
394 oldStyle
-= LVS_ALIGNLEFT
;
395 wstyle
|= LVS_ALIGNTOP
;
398 if ( style
& wxLC_AUTOARRANGE
)
399 wstyle
|= LVS_AUTOARRANGE
;
401 // Apparently, no such style (documentation wrong?)
403 if ( style & wxLC_BUTTON )
404 wstyle |= LVS_BUTTON;
407 if ( style
& wxLC_NO_SORT_HEADER
)
408 wstyle
|= LVS_NOSORTHEADER
;
410 if ( style
& wxLC_NO_HEADER
)
411 wstyle
|= LVS_NOCOLUMNHEADER
;
413 if ( style
& wxLC_EDIT_LABELS
)
414 wstyle
|= LVS_EDITLABELS
;
416 if ( style
& wxLC_SINGLE_SEL
)
417 wstyle
|= LVS_SINGLESEL
;
419 if ( style
& wxLC_SORT_ASCENDING
)
421 if ( oldStyle
& LVS_SORTDESCENDING
)
422 oldStyle
-= LVS_SORTDESCENDING
;
423 wstyle
|= LVS_SORTASCENDING
;
426 if ( style
& wxLC_SORT_DESCENDING
)
428 if ( oldStyle
& LVS_SORTASCENDING
)
429 oldStyle
-= LVS_SORTASCENDING
;
430 wstyle
|= LVS_SORTDESCENDING
;
436 // ----------------------------------------------------------------------------
438 // ----------------------------------------------------------------------------
440 // Sets the foreground, i.e. text, colour
441 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
443 if ( !wxWindow::SetForegroundColour(col
) )
446 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
451 // Sets the background colour
452 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
454 if ( !wxWindow::SetBackgroundColour(col
) )
457 // we set the same colour for both the "empty" background and the items
459 COLORREF color
= wxColourToRGB(col
);
460 ListView_SetBkColor(GetHwnd(), color
);
461 ListView_SetTextBkColor(GetHwnd(), color
);
466 // Gets information about this column
467 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
472 lvCol
.pszText
= NULL
;
474 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
476 lvCol
.mask
|= LVCF_TEXT
;
477 lvCol
.pszText
= new wxChar
[513];
478 lvCol
.cchTextMax
= 512;
481 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
483 // item.m_subItem = lvCol.iSubItem;
484 item
.m_width
= lvCol
.cx
;
486 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
488 item
.m_text
= lvCol
.pszText
;
489 delete[] lvCol
.pszText
;
492 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
494 if (lvCol
.fmt
== LVCFMT_LEFT
)
495 item
.m_format
= wxLIST_FORMAT_LEFT
;
496 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
497 item
.m_format
= wxLIST_FORMAT_RIGHT
;
498 else if (lvCol
.fmt
== LVCFMT_CENTER
)
499 item
.m_format
= wxLIST_FORMAT_CENTRE
;
505 // Sets information about this column
506 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
511 lvCol
.pszText
= NULL
;
513 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
515 lvCol
.mask
|= LVCF_TEXT
;
516 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
517 lvCol
.cchTextMax
= 0; // Ignored
519 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
521 lvCol
.mask
|= LVCF_FMT
;
523 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
524 lvCol
.fmt
= LVCFMT_LEFT
;
525 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
526 lvCol
.fmt
= LVCFMT_RIGHT
;
527 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
528 lvCol
.fmt
= LVCFMT_CENTER
;
531 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
533 lvCol
.mask
|= LVCF_WIDTH
;
534 lvCol
.cx
= item
.m_width
;
536 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
537 lvCol
.cx
= LVSCW_AUTOSIZE
;
538 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
539 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
541 lvCol
.mask
|= LVCF_SUBITEM
;
542 lvCol
.iSubItem
= col
;
543 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
546 // Gets the column width
547 int wxListCtrl::GetColumnWidth(int col
) const
549 return ListView_GetColumnWidth(GetHwnd(), col
);
552 // Sets the column width
553 bool wxListCtrl::SetColumnWidth(int col
, int width
)
556 if ( m_windowStyle
& wxLC_LIST
)
560 if ( width2
== wxLIST_AUTOSIZE
)
561 width2
= LVSCW_AUTOSIZE
;
562 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
563 width2
= LVSCW_AUTOSIZE_USEHEADER
;
565 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
568 // Gets the number of items that can fit vertically in the
569 // visible area of the list control (list or report view)
570 // or the total number of items in the list control (icon
571 // or small icon view)
572 int wxListCtrl::GetCountPerPage() const
574 return ListView_GetCountPerPage(GetHwnd());
577 // Gets the edit control for editing labels.
578 wxTextCtrl
* wxListCtrl::GetEditControl() const
583 // Gets information about the item
584 bool wxListCtrl::GetItem(wxListItem
& info
) const
587 wxZeroMemory(lvItem
);
589 lvItem
.iItem
= info
.m_itemId
;
590 lvItem
.iSubItem
= info
.m_col
;
592 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
594 lvItem
.mask
|= LVIF_TEXT
;
595 lvItem
.pszText
= new wxChar
[513];
596 lvItem
.cchTextMax
= 512;
600 lvItem
.pszText
= NULL
;
603 if (info
.m_mask
& wxLIST_MASK_DATA
)
604 lvItem
.mask
|= LVIF_PARAM
;
606 if ( info
.m_mask
& wxLIST_MASK_STATE
)
608 lvItem
.mask
|= LVIF_STATE
;
609 // the other bits are hardly interesting anyhow
610 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
613 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
616 wxLogError(_("Couldn't retrieve information about list control item %d."),
621 wxConvertFromMSWListItem(this, info
, lvItem
);
625 delete[] lvItem
.pszText
;
630 // Sets information about the item
631 bool wxListCtrl::SetItem(wxListItem
& info
)
634 wxConvertToMSWListItem(this, info
, item
);
636 // check whether it has any custom attributes
637 if ( info
.HasAttributes() )
640 wxListItemAttr
*attr
;
641 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
645 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
647 else *attr
= *info
.GetAttributes();
653 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
654 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
656 // make the change visible
657 ListView_Update(GetHwnd(), item
.iItem
);
663 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
667 info
.m_mask
= wxLIST_MASK_TEXT
;
668 info
.m_itemId
= index
;
672 info
.m_image
= imageId
;
673 info
.m_mask
|= wxLIST_MASK_IMAGE
;
675 return SetItem(info
);
679 // Gets the item state
680 int wxListCtrl::GetItemState(long item
, long stateMask
) const
684 info
.m_mask
= wxLIST_MASK_STATE
;
685 info
.m_stateMask
= stateMask
;
686 info
.m_itemId
= item
;
694 // Sets the item state
695 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
699 info
.m_mask
= wxLIST_MASK_STATE
;
700 info
.m_state
= state
;
701 info
.m_stateMask
= stateMask
;
702 info
.m_itemId
= item
;
704 return SetItem(info
);
707 // Sets the item image
708 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
712 info
.m_mask
= wxLIST_MASK_IMAGE
;
713 info
.m_image
= image
;
714 info
.m_itemId
= item
;
716 return SetItem(info
);
719 // Gets the item text
720 wxString
wxListCtrl::GetItemText(long item
) const
724 info
.m_mask
= wxLIST_MASK_TEXT
;
725 info
.m_itemId
= item
;
732 // Sets the item text
733 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
737 info
.m_mask
= wxLIST_MASK_TEXT
;
738 info
.m_itemId
= item
;
744 // Gets the item data
745 long wxListCtrl::GetItemData(long item
) const
749 info
.m_mask
= wxLIST_MASK_DATA
;
750 info
.m_itemId
= item
;
757 // Sets the item data
758 bool wxListCtrl::SetItemData(long item
, long data
)
762 info
.m_mask
= wxLIST_MASK_DATA
;
763 info
.m_itemId
= item
;
766 return SetItem(info
);
769 // Gets the item rectangle
770 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
774 int code2
= LVIR_BOUNDS
;
775 if ( code
== wxLIST_RECT_BOUNDS
)
777 else if ( code
== wxLIST_RECT_ICON
)
779 else if ( code
== wxLIST_RECT_LABEL
)
783 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
785 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
790 rect
.width
= rect2
.right
- rect2
.left
;
791 rect
.height
= rect2
.bottom
- rect2
.top
;
795 // Gets the item position
796 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
800 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
802 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
806 // Sets the item position.
807 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
809 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
812 // Gets the number of items in the list control
813 int wxListCtrl::GetItemCount() const
815 return ListView_GetItemCount(GetHwnd());
818 // Retrieves the spacing between icons in pixels.
819 // If small is TRUE, gets the spacing for the small icon
820 // view, otherwise the large icon view.
821 int wxListCtrl::GetItemSpacing(bool isSmall
) const
823 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
826 // Gets the number of selected items in the list control
827 int wxListCtrl::GetSelectedItemCount() const
829 return ListView_GetSelectedCount(GetHwnd());
832 // Gets the text colour of the listview
833 wxColour
wxListCtrl::GetTextColour() const
835 COLORREF ref
= ListView_GetTextColor(GetHwnd());
836 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
840 // Sets the text colour of the listview
841 void wxListCtrl::SetTextColour(const wxColour
& col
)
843 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
846 // Gets the index of the topmost visible item when in
847 // list or report view
848 long wxListCtrl::GetTopItem() const
850 return (long) ListView_GetTopIndex(GetHwnd());
853 // Searches for an item, starting from 'item'.
854 // 'geometry' is one of
855 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
856 // 'state' is a state bit flag, one or more of
857 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
858 // item can be -1 to find the first item that matches the
860 // Returns the item or -1 if unsuccessful.
861 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
865 if ( geom
== wxLIST_NEXT_ABOVE
)
867 if ( geom
== wxLIST_NEXT_ALL
)
869 if ( geom
== wxLIST_NEXT_BELOW
)
871 if ( geom
== wxLIST_NEXT_LEFT
)
872 flags
|= LVNI_TOLEFT
;
873 if ( geom
== wxLIST_NEXT_RIGHT
)
874 flags
|= LVNI_TORIGHT
;
876 if ( state
& wxLIST_STATE_CUT
)
878 if ( state
& wxLIST_STATE_DROPHILITED
)
879 flags
|= LVNI_DROPHILITED
;
880 if ( state
& wxLIST_STATE_FOCUSED
)
881 flags
|= LVNI_FOCUSED
;
882 if ( state
& wxLIST_STATE_SELECTED
)
883 flags
|= LVNI_SELECTED
;
885 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
889 wxImageList
*wxListCtrl::GetImageList(int which
) const
891 if ( which
== wxIMAGE_LIST_NORMAL
)
893 return m_imageListNormal
;
895 else if ( which
== wxIMAGE_LIST_SMALL
)
897 return m_imageListSmall
;
899 else if ( which
== wxIMAGE_LIST_STATE
)
901 return m_imageListState
;
906 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
909 if ( which
== wxIMAGE_LIST_NORMAL
)
911 flags
= LVSIL_NORMAL
;
912 m_imageListNormal
= imageList
;
914 else if ( which
== wxIMAGE_LIST_SMALL
)
917 m_imageListSmall
= imageList
;
919 else if ( which
== wxIMAGE_LIST_STATE
)
922 m_imageListState
= imageList
;
924 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
927 // ----------------------------------------------------------------------------
929 // ----------------------------------------------------------------------------
931 // Arranges the items
932 bool wxListCtrl::Arrange(int flag
)
935 if ( flag
== wxLIST_ALIGN_LEFT
)
936 code
= LVA_ALIGNLEFT
;
937 else if ( flag
== wxLIST_ALIGN_TOP
)
939 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
941 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
942 code
= LVA_SNAPTOGRID
;
944 return (ListView_Arrange(GetHwnd(), code
) != 0);
948 bool wxListCtrl::DeleteItem(long item
)
950 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
954 bool wxListCtrl::DeleteAllItems()
956 return (ListView_DeleteAllItems(GetHwnd()) != 0);
960 bool wxListCtrl::DeleteAllColumns()
962 while ( m_colCount
> 0 )
964 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
966 wxLogLastError(wxT("ListView_DeleteColumn"));
974 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
980 bool wxListCtrl::DeleteColumn(int col
)
982 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
984 if ( success
&& (m_colCount
> 0) )
989 // Clears items, and columns if there are any.
990 void wxListCtrl::ClearAll()
993 if ( m_colCount
> 0 )
997 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
999 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1001 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
1005 m_textCtrl
->UnsubclassWin();
1006 m_textCtrl
->SetHWND(0);
1011 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1012 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1013 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1018 // End label editing, optionally cancelling the edit
1019 bool wxListCtrl::EndEditLabel(bool cancel
)
1023 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
1025 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
1029 m_textCtrl->UnsubclassWin();
1030 m_textCtrl->SetHWND(0);
1040 // Ensures this item is visible
1041 bool wxListCtrl::EnsureVisible(long item
)
1043 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
1046 // Find an item whose label matches this string, starting from the item after 'start'
1047 // or the beginning if 'start' is -1.
1048 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1050 LV_FINDINFO findInfo
;
1052 findInfo
.flags
= LVFI_STRING
;
1054 findInfo
.flags
|= LVFI_PARTIAL
;
1057 // ListView_FindItem() excludes the first item from search and to look
1058 // through all the items you need to start from -1 which is unnatural and
1059 // inconsitent with the generic version - so we adjust the index
1060 return ListView_FindItem(GetHwnd(), (int) start
- 1, &findInfo
);
1063 // Find an item whose data matches this data, starting from the item after 'start'
1064 // or the beginning if 'start' is -1.
1065 long wxListCtrl::FindItem(long start
, long data
)
1067 LV_FINDINFO findInfo
;
1069 findInfo
.flags
= LVFI_PARAM
;
1070 findInfo
.lParam
= data
;
1072 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1075 // Find an item nearest this position in the specified direction, starting from
1076 // the item after 'start' or the beginning if 'start' is -1.
1077 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1079 LV_FINDINFO findInfo
;
1081 findInfo
.flags
= LVFI_NEARESTXY
;
1082 findInfo
.pt
.x
= pt
.x
;
1083 findInfo
.pt
.y
= pt
.y
;
1084 findInfo
.vkDirection
= VK_RIGHT
;
1086 if ( direction
== wxLIST_FIND_UP
)
1087 findInfo
.vkDirection
= VK_UP
;
1088 else if ( direction
== wxLIST_FIND_DOWN
)
1089 findInfo
.vkDirection
= VK_DOWN
;
1090 else if ( direction
== wxLIST_FIND_LEFT
)
1091 findInfo
.vkDirection
= VK_LEFT
;
1092 else if ( direction
== wxLIST_FIND_RIGHT
)
1093 findInfo
.vkDirection
= VK_RIGHT
;
1095 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1098 // Determines which item (if any) is at the specified point,
1099 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1100 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1102 LV_HITTESTINFO hitTestInfo
;
1103 hitTestInfo
.pt
.x
= (int) point
.x
;
1104 hitTestInfo
.pt
.y
= (int) point
.y
;
1106 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1109 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1110 flags
|= wxLIST_HITTEST_ABOVE
;
1111 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1112 flags
|= wxLIST_HITTEST_BELOW
;
1113 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1114 flags
|= wxLIST_HITTEST_NOWHERE
;
1115 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1116 flags
|= wxLIST_HITTEST_ONITEMICON
;
1117 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1118 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1119 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1120 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1121 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1122 flags
|= wxLIST_HITTEST_TOLEFT
;
1123 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1124 flags
|= wxLIST_HITTEST_TORIGHT
;
1126 return (long) hitTestInfo
.iItem
;
1129 // Inserts an item, returning the index of the new item if successful,
1131 long wxListCtrl::InsertItem(wxListItem
& info
)
1134 wxConvertToMSWListItem(this, info
, item
);
1136 // check whether it has any custom attributes
1137 if ( info
.HasAttributes() )
1140 wxListItemAttr
*attr
;
1141 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
1145 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1147 else *attr
= *info
.GetAttributes();
1149 m_hasAnyAttr
= TRUE
;
1152 return (long) ListView_InsertItem(GetHwnd(), & item
);
1155 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1158 info
.m_text
= label
;
1159 info
.m_mask
= wxLIST_MASK_TEXT
;
1160 info
.m_itemId
= index
;
1161 return InsertItem(info
);
1164 // Inserts an image item
1165 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1168 info
.m_image
= imageIndex
;
1169 info
.m_mask
= wxLIST_MASK_IMAGE
;
1170 info
.m_itemId
= index
;
1171 return InsertItem(info
);
1174 // Inserts an image/string item
1175 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1178 info
.m_image
= imageIndex
;
1179 info
.m_text
= label
;
1180 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1181 info
.m_itemId
= index
;
1182 return InsertItem(info
);
1185 // For list view mode (only), inserts a column.
1186 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1191 lvCol
.pszText
= NULL
;
1193 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1195 lvCol
.mask
|= LVCF_TEXT
;
1196 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1197 lvCol
.cchTextMax
= 0; // Ignored
1199 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1201 lvCol
.mask
|= LVCF_FMT
;
1203 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1204 lvCol
.fmt
= LVCFMT_LEFT
;
1205 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1206 lvCol
.fmt
= LVCFMT_RIGHT
;
1207 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1208 lvCol
.fmt
= LVCFMT_CENTER
;
1211 lvCol
.mask
|= LVCF_WIDTH
;
1212 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1214 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1215 lvCol
.cx
= LVSCW_AUTOSIZE
;
1216 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1217 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1219 lvCol
.cx
= item
.m_width
;
1223 // always give some width to the new column: this one is compatible
1228 lvCol
.mask
|= LVCF_SUBITEM
;
1229 lvCol
.iSubItem
= col
;
1231 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1238 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1245 long wxListCtrl::InsertColumn(long col
,
1246 const wxString
& heading
,
1251 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1252 item
.m_text
= heading
;
1255 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1256 item
.m_width
= width
;
1258 item
.m_format
= format
;
1260 return InsertColumn(col
, item
);
1263 // Scrolls the list control. If in icon, small icon or report view mode,
1264 // x specifies the number of pixels to scroll. If in list view mode, x
1265 // specifies the number of columns to scroll.
1266 // If in icon, small icon or list view mode, y specifies the number of pixels
1267 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1268 bool wxListCtrl::ScrollList(int dx
, int dy
)
1270 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1275 // fn is a function which takes 3 long arguments: item1, item2, data.
1276 // item1 is the long data associated with a first item (NOT the index).
1277 // item2 is the long data associated with a second item (NOT the index).
1278 // data is the same value as passed to SortItems.
1279 // The return value is a negative number if the first item should precede the second
1280 // item, a positive number of the second item should precede the first,
1281 // or zero if the two items are equivalent.
1283 // data is arbitrary data to be passed to the sort function.
1284 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1286 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1289 // ----------------------------------------------------------------------------
1290 // message processing
1291 // ----------------------------------------------------------------------------
1293 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1295 if (cmd
== EN_UPDATE
)
1297 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1298 event
.SetEventObject( this );
1299 ProcessCommand(event
);
1302 else if (cmd
== EN_KILLFOCUS
)
1304 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1305 event
.SetEventObject( this );
1306 ProcessCommand(event
);
1313 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1315 // prepare the event
1316 // -----------------
1318 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1319 wxEventType eventType
= wxEVT_NULL
;
1321 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1323 // almost all messages use NM_LISTVIEW
1324 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1326 // this is true for almost all events
1327 event
.m_item
.m_data
= nmLV
->lParam
;
1329 switch ( nmhdr
->code
)
1331 case LVN_BEGINRDRAG
:
1332 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1336 if ( eventType
== wxEVT_NULL
)
1338 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1341 event
.m_itemIndex
= nmLV
->iItem
;
1342 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1343 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1346 case LVN_BEGINLABELEDIT
:
1348 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1349 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1350 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1354 case LVN_COLUMNCLICK
:
1355 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1356 event
.m_itemIndex
= -1;
1357 event
.m_col
= nmLV
->iSubItem
;
1360 case LVN_DELETEALLITEMS
:
1361 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1362 event
.m_itemIndex
= -1;
1368 case LVN_DELETEITEM
:
1369 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1370 event
.m_itemIndex
= nmLV
->iItem
;
1374 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1378 case LVN_ENDLABELEDIT
:
1380 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1381 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1382 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1383 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1388 case LVN_SETDISPINFO
:
1390 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1391 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1392 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1396 case LVN_GETDISPINFO
:
1397 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1398 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1402 // TODO: some text buffering here, I think
1403 // TODO: API for getting Windows to retrieve values
1405 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1406 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1407 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1414 case LVN_INSERTITEM
:
1415 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1416 event
.m_itemIndex
= nmLV
->iItem
;
1419 case LVN_ITEMCHANGED
:
1420 // This needs to be sent to wxListCtrl as a rather more concrete
1421 // event. For now, just detect a selection or deselection.
1422 if ( (nmLV
->uNewState
& LVIS_SELECTED
) && !(nmLV
->uOldState
& LVIS_SELECTED
) )
1424 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1425 event
.m_itemIndex
= nmLV
->iItem
;
1427 else if ( !(nmLV
->uNewState
& LVIS_SELECTED
) && (nmLV
->uOldState
& LVIS_SELECTED
) )
1429 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1430 event
.m_itemIndex
= nmLV
->iItem
;
1440 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1441 WORD wVKey
= info
->wVKey
;
1443 // get the current selection
1444 long lItem
= GetNextItem(-1,
1446 wxLIST_STATE_SELECTED
);
1448 // <Enter> or <Space> activate the selected item if any
1449 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1451 // TODO this behaviour probably should be optional
1452 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1453 event
.m_itemIndex
= lItem
;
1457 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1458 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1463 // fill the other fields too
1464 event
.m_item
.m_text
= GetItemText(lItem
);
1465 event
.m_item
.m_data
= GetItemData(lItem
);
1471 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1473 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1478 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1479 // if it happened on an item (and not on empty place)
1480 if ( nmLV
->iItem
== -1 )
1486 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1487 event
.m_itemIndex
= nmLV
->iItem
;
1488 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1489 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1493 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1494 subclass and check for the actual WM_RBUTTONDOWN message,
1495 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1496 before firing off. We want to have notify events for both down
1499 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1500 // don't do anything else
1501 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1506 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1507 LV_HITTESTINFO lvhti
;
1508 wxZeroMemory(lvhti
);
1510 ::GetCursorPos(&(lvhti
.pt
));
1511 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1512 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1514 if ( lvhti
.flags
& LVHT_ONITEM
)
1516 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1517 event
.m_itemIndex
= lvhti
.iItem
;
1524 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1526 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1528 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1533 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1534 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1535 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1536 event
.m_itemIndex
= hdr
->iItem
;
1541 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1544 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1545 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1546 switch( nmcd
.dwDrawStage
)
1549 // if we've got any items with non standard attributes,
1550 // notify us before painting each item
1551 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1555 case CDDS_ITEMPREPAINT
:
1557 wxListItemAttr
*attr
=
1558 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1562 // nothing to do for this item
1563 return CDRF_DODEFAULT
;
1567 wxColour colText
, colBack
;
1568 if ( attr
->HasFont() )
1570 wxFont font
= attr
->GetFont();
1571 hFont
= (HFONT
)font
.GetResourceHandle();
1578 if ( attr
->HasTextColour() )
1580 colText
= attr
->GetTextColour();
1584 colText
= GetTextColour();
1587 if ( attr
->HasBackgroundColour() )
1589 colBack
= attr
->GetBackgroundColour();
1593 colBack
= GetBackgroundColour();
1596 // note that if we wanted to set colours for
1597 // individual columns (subitems), we would have
1598 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1601 ::SelectObject(nmcd
.hdc
, hFont
);
1603 *result
= CDRF_NEWFONT
;
1607 *result
= CDRF_DODEFAULT
;
1610 lplvcd
->clrText
= wxColourToRGB(colText
);
1611 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1617 *result
= CDRF_DODEFAULT
;
1622 #endif // _WIN32_IE >= 0x300
1625 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1628 // process the event
1629 // -----------------
1631 event
.SetEventObject( this );
1632 event
.SetEventType(eventType
);
1634 if ( !GetEventHandler()->ProcessEvent(event
) )
1640 switch ( nmhdr
->code
)
1642 case LVN_DELETEALLITEMS
:
1643 // always return TRUE to suppress all additional LVN_DELETEITEM
1644 // notifications - this makes deleting all items from a list ctrl
1650 case LVN_GETDISPINFO
:
1652 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1653 if ( info
->item
.mask
& LVIF_TEXT
)
1655 if ( !event
.m_item
.m_text
.IsNull() )
1657 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1658 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1661 // wxConvertToMSWListItem(this, event.m_item, info->item);
1664 case LVN_ENDLABELEDIT
:
1666 *result
= event
.IsAllowed();
1671 *result
= !event
.IsAllowed();
1676 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1678 // Remove the first element if 3 strings exist
1679 if ( m_stringPool
.Number() == 3 )
1681 wxNode
*node
= m_stringPool
.First();
1682 delete[] (char *)node
->Data();
1685 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1686 return (wxChar
*)node
->Data();
1689 // Necessary for drawing hrules and vrules, if specified
1690 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
1694 wxControl::OnPaint(event
);
1696 // Reset the device origin since it may have been set
1697 dc
.SetDeviceOrigin(0, 0);
1699 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
1700 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
1702 if (!drawHRules
&& !drawVRules
)
1704 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
1707 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1709 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1711 wxSize clientSize
= GetClientSize();
1716 int itemCount
= GetItemCount();
1718 for (i
= 0; i
< itemCount
; i
++)
1720 if (GetItemRect(i
, itemRect
))
1722 cy
= itemRect
.GetTop();
1723 if (i
!= 0) // Don't draw the first one
1725 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
1728 if (i
== (GetItemCount() - 1))
1730 cy
= itemRect
.GetBottom();
1731 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
1736 i
= (GetItemCount() - 1);
1737 if (drawVRules
&& (i
> -1))
1739 wxRect firstItemRect
;
1740 GetItemRect(0, firstItemRect
);
1742 if (GetItemRect(i
, itemRect
))
1745 int x
= itemRect
.GetX();
1746 for (col
= 0; col
< GetColumnCount(); col
++)
1748 int colWidth
= GetColumnWidth(col
);
1750 dc
.DrawLine(x
, firstItemRect
.GetY() - 2, x
, itemRect
.GetBottom());
1756 // ----------------------------------------------------------------------------
1758 // ----------------------------------------------------------------------------
1760 // List item structure
1761 wxListItem::wxListItem()
1771 m_format
= wxLIST_FORMAT_CENTRE
;
1777 void wxListItem::Clear()
1786 m_format
= wxLIST_FORMAT_CENTRE
;
1788 m_text
= wxEmptyString
;
1790 if (m_attr
) delete m_attr
;
1794 void wxListItem::ClearAttributes()
1796 if (m_attr
) delete m_attr
;
1800 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1802 info
.m_data
= lvItem
.lParam
;
1805 info
.m_stateMask
= 0;
1806 info
.m_itemId
= lvItem
.iItem
;
1808 long oldMask
= lvItem
.mask
;
1810 bool needText
= FALSE
;
1811 if (getFullInfo
!= 0)
1813 if ( lvItem
.mask
& LVIF_TEXT
)
1820 lvItem
.pszText
= new wxChar
[513];
1821 lvItem
.cchTextMax
= 512;
1823 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1824 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1825 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1828 if ( lvItem
.mask
& LVIF_STATE
)
1830 info
.m_mask
|= wxLIST_MASK_STATE
;
1832 if ( lvItem
.stateMask
& LVIS_CUT
)
1834 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1835 if ( lvItem
.state
& LVIS_CUT
)
1836 info
.m_state
|= wxLIST_STATE_CUT
;
1838 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1840 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1841 if ( lvItem
.state
& LVIS_DROPHILITED
)
1842 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1844 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1846 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1847 if ( lvItem
.state
& LVIS_FOCUSED
)
1848 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1850 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1852 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1853 if ( lvItem
.state
& LVIS_SELECTED
)
1854 info
.m_state
|= wxLIST_STATE_SELECTED
;
1858 if ( lvItem
.mask
& LVIF_TEXT
)
1860 info
.m_mask
|= wxLIST_MASK_TEXT
;
1861 info
.m_text
= lvItem
.pszText
;
1863 if ( lvItem
.mask
& LVIF_IMAGE
)
1865 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1866 info
.m_image
= lvItem
.iImage
;
1868 if ( lvItem
.mask
& LVIF_PARAM
)
1869 info
.m_mask
|= wxLIST_MASK_DATA
;
1870 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1871 info
.m_mask
|= wxLIST_SET_ITEM
;
1872 info
.m_col
= lvItem
.iSubItem
;
1877 delete[] lvItem
.pszText
;
1879 lvItem
.mask
= oldMask
;
1882 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1884 lvItem
.iItem
= (int) info
.m_itemId
;
1886 lvItem
.iImage
= info
.m_image
;
1887 lvItem
.lParam
= info
.m_data
;
1888 lvItem
.stateMask
= 0;
1891 lvItem
.iSubItem
= info
.m_col
;
1893 if (info
.m_mask
& wxLIST_MASK_STATE
)
1895 lvItem
.mask
|= LVIF_STATE
;
1896 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1898 lvItem
.stateMask
|= LVIS_CUT
;
1899 if (info
.m_state
& wxLIST_STATE_CUT
)
1900 lvItem
.state
|= LVIS_CUT
;
1902 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1904 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1905 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1906 lvItem
.state
|= LVIS_DROPHILITED
;
1908 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1910 lvItem
.stateMask
|= LVIS_FOCUSED
;
1911 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1912 lvItem
.state
|= LVIS_FOCUSED
;
1914 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1916 lvItem
.stateMask
|= LVIS_SELECTED
;
1917 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1918 lvItem
.state
|= LVIS_SELECTED
;
1922 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1924 lvItem
.mask
|= LVIF_TEXT
;
1925 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1927 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1931 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1932 if ( lvItem
.pszText
)
1933 lvItem
.cchTextMax
= info
.m_text
.Length();
1935 lvItem
.cchTextMax
= 0;
1938 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1939 lvItem
.mask
|= LVIF_IMAGE
;
1940 if (info
.m_mask
& wxLIST_MASK_DATA
)
1941 lvItem
.mask
|= LVIF_PARAM
;
1944 // ----------------------------------------------------------------------------
1946 // ----------------------------------------------------------------------------
1948 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1950 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1951 : wxNotifyEvent(commandType
, id
)
1957 m_cancelled
= FALSE
;