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"
43 #include "wx/listctrl.h"
44 #include "wx/dcclient.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
;
133 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= FALSE
;
137 m_hasAnyAttr
= FALSE
;
140 bool wxListCtrl::Create(wxWindow
*parent
,
145 const wxValidator
& validator
,
146 const wxString
& name
)
149 SetValidator(validator
);
150 #endif // wxUSE_VALIDATORS
159 m_windowStyle
= style
;
172 m_windowId
= (id
== -1) ? NewControlId() : id
;
174 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
|
175 LVS_SHAREIMAGELISTS
| LVS_SHOWSELALWAYS
;
176 if ( wxStyleHasBorder(m_windowStyle
) )
178 m_baseStyle
= wstyle
;
180 if ( !DoCreateControl(x
, y
, width
, height
) )
184 parent
->AddChild(this);
189 bool wxListCtrl::DoCreateControl(int x
, int y
, int w
, int h
)
191 DWORD wstyle
= m_baseStyle
;
194 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
);
196 // Even with extended styles, need to combine with WS_BORDER
197 // for them to look right.
201 long oldStyle
= 0; // Dummy
202 wstyle
|= ConvertToMSWStyle(oldStyle
, m_windowStyle
);
204 // Create the ListView control.
205 m_hWnd
= (WXHWND
)CreateWindowEx(exStyle
,
210 GetWinHwnd(GetParent()),
217 wxLogError(_("Can't create list control window, check that comctl32.dll is installed."));
222 // for comctl32.dll v 4.70+ we want to have this attribute because it's
223 // prettier (and also because wxGTK does it like this)
224 if ( (wstyle
& LVS_REPORT
) && wxTheApp
->GetComCtl32Version() >= 470 )
226 ::SendMessage(GetHwnd(), LVM_SETEXTENDEDLISTVIEWSTYLE
,
227 0, LVS_EX_FULLROWSELECT
);
230 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
231 SetForegroundColour(GetParent()->GetForegroundColour());
238 void wxListCtrl::UpdateStyle()
242 // The new window view style
244 DWORD dwStyleNew
= ConvertToMSWStyle(dummy
, m_windowStyle
);
245 dwStyleNew
|= m_baseStyle
;
247 // Get the current window style.
248 DWORD dwStyleOld
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
250 // Only set the window style if the view bits have changed.
251 if ( dwStyleOld
!= dwStyleNew
)
253 ::SetWindowLong(GetHwnd(), GWL_STYLE
, dwStyleNew
);
258 void wxListCtrl::FreeAllAttrs(bool dontRecreate
)
262 for ( wxNode
*node
= m_attrs
.Next(); node
; node
= m_attrs
.Next() )
264 delete (wxListItemAttr
*)node
->Data();
270 m_attrs
.Create(wxKEY_INTEGER
, 1000); // just as def ctor
273 m_hasAnyAttr
= FALSE
;
277 wxListCtrl::~wxListCtrl()
279 FreeAllAttrs(TRUE
/* no need to recreate hash any more */);
283 m_textCtrl
->UnsubclassWin();
284 m_textCtrl
->SetHWND(0);
289 if (m_ownsImageListNormal
) delete m_imageListNormal
;
290 if (m_ownsImageListSmall
) delete m_imageListSmall
;
291 if (m_ownsImageListState
) delete m_imageListState
;
294 // ----------------------------------------------------------------------------
295 // set/get/change style
296 // ----------------------------------------------------------------------------
298 // Add or remove a single window style
299 void wxListCtrl::SetSingleStyle(long style
, bool add
)
301 long flag
= GetWindowStyleFlag();
303 // Get rid of conflicting styles
306 if ( style
& wxLC_MASK_TYPE
)
307 flag
= flag
& ~wxLC_MASK_TYPE
;
308 if ( style
& wxLC_MASK_ALIGN
)
309 flag
= flag
& ~wxLC_MASK_ALIGN
;
310 if ( style
& wxLC_MASK_SORT
)
311 flag
= flag
& ~wxLC_MASK_SORT
;
327 m_windowStyle
= flag
;
332 // Set the whole window style
333 void wxListCtrl::SetWindowStyleFlag(long flag
)
335 m_windowStyle
= flag
;
340 // Can be just a single style, or a bitlist
341 long wxListCtrl::ConvertToMSWStyle(long& oldStyle
, long style
) const
344 if ( style
& wxLC_ICON
)
346 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
347 oldStyle
-= LVS_SMALLICON
;
348 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
349 oldStyle
-= LVS_REPORT
;
350 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
351 oldStyle
-= LVS_LIST
;
355 if ( style
& wxLC_SMALL_ICON
)
357 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
358 oldStyle
-= LVS_ICON
;
359 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
360 oldStyle
-= LVS_REPORT
;
361 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
362 oldStyle
-= LVS_LIST
;
363 wstyle
|= LVS_SMALLICON
;
366 if ( style
& wxLC_LIST
)
368 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
369 oldStyle
-= LVS_ICON
;
370 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
371 oldStyle
-= LVS_REPORT
;
372 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
373 oldStyle
-= LVS_SMALLICON
;
377 if ( style
& wxLC_REPORT
)
379 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_ICON
)
380 oldStyle
-= LVS_ICON
;
381 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_LIST
)
382 oldStyle
-= LVS_LIST
;
383 if ( (oldStyle
& LVS_TYPEMASK
) == LVS_SMALLICON
)
384 oldStyle
-= LVS_SMALLICON
;
386 wstyle
|= LVS_REPORT
;
389 if ( style
& wxLC_ALIGN_LEFT
)
391 if ( oldStyle
& LVS_ALIGNTOP
)
392 oldStyle
-= LVS_ALIGNTOP
;
393 wstyle
|= LVS_ALIGNLEFT
;
396 if ( style
& wxLC_ALIGN_TOP
)
398 if ( oldStyle
& LVS_ALIGNLEFT
)
399 oldStyle
-= LVS_ALIGNLEFT
;
400 wstyle
|= LVS_ALIGNTOP
;
403 if ( style
& wxLC_AUTOARRANGE
)
404 wstyle
|= LVS_AUTOARRANGE
;
406 // Apparently, no such style (documentation wrong?)
408 if ( style & wxLC_BUTTON )
409 wstyle |= LVS_BUTTON;
412 if ( style
& wxLC_NO_SORT_HEADER
)
413 wstyle
|= LVS_NOSORTHEADER
;
415 if ( style
& wxLC_NO_HEADER
)
416 wstyle
|= LVS_NOCOLUMNHEADER
;
418 if ( style
& wxLC_EDIT_LABELS
)
419 wstyle
|= LVS_EDITLABELS
;
421 if ( style
& wxLC_SINGLE_SEL
)
422 wstyle
|= LVS_SINGLESEL
;
424 if ( style
& wxLC_SORT_ASCENDING
)
426 if ( oldStyle
& LVS_SORTDESCENDING
)
427 oldStyle
-= LVS_SORTDESCENDING
;
428 wstyle
|= LVS_SORTASCENDING
;
431 if ( style
& wxLC_SORT_DESCENDING
)
433 if ( oldStyle
& LVS_SORTASCENDING
)
434 oldStyle
-= LVS_SORTASCENDING
;
435 wstyle
|= LVS_SORTDESCENDING
;
441 // ----------------------------------------------------------------------------
443 // ----------------------------------------------------------------------------
445 // Sets the foreground, i.e. text, colour
446 bool wxListCtrl::SetForegroundColour(const wxColour
& col
)
448 if ( !wxWindow::SetForegroundColour(col
) )
451 ListView_SetTextColor(GetHwnd(), wxColourToRGB(col
));
456 // Sets the background colour
457 bool wxListCtrl::SetBackgroundColour(const wxColour
& col
)
459 if ( !wxWindow::SetBackgroundColour(col
) )
462 // we set the same colour for both the "empty" background and the items
464 COLORREF color
= wxColourToRGB(col
);
465 ListView_SetBkColor(GetHwnd(), color
);
466 ListView_SetTextBkColor(GetHwnd(), color
);
471 // Gets information about this column
472 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
477 lvCol
.pszText
= NULL
;
479 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
481 lvCol
.mask
|= LVCF_TEXT
;
482 lvCol
.pszText
= new wxChar
[513];
483 lvCol
.cchTextMax
= 512;
486 bool success
= (ListView_GetColumn(GetHwnd(), col
, & lvCol
) != 0);
488 // item.m_subItem = lvCol.iSubItem;
489 item
.m_width
= lvCol
.cx
;
491 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) && lvCol
.pszText
)
493 item
.m_text
= lvCol
.pszText
;
494 delete[] lvCol
.pszText
;
497 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
499 if (lvCol
.fmt
== LVCFMT_LEFT
)
500 item
.m_format
= wxLIST_FORMAT_LEFT
;
501 else if (lvCol
.fmt
== LVCFMT_RIGHT
)
502 item
.m_format
= wxLIST_FORMAT_RIGHT
;
503 else if (lvCol
.fmt
== LVCFMT_CENTER
)
504 item
.m_format
= wxLIST_FORMAT_CENTRE
;
510 // Sets information about this column
511 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
516 lvCol
.pszText
= NULL
;
518 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
520 lvCol
.mask
|= LVCF_TEXT
;
521 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
522 lvCol
.cchTextMax
= 0; // Ignored
524 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
526 lvCol
.mask
|= LVCF_FMT
;
528 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
529 lvCol
.fmt
= LVCFMT_LEFT
;
530 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
531 lvCol
.fmt
= LVCFMT_RIGHT
;
532 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
533 lvCol
.fmt
= LVCFMT_CENTER
;
536 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
538 lvCol
.mask
|= LVCF_WIDTH
;
539 lvCol
.cx
= item
.m_width
;
541 if ( lvCol
.cx
== wxLIST_AUTOSIZE
)
542 lvCol
.cx
= LVSCW_AUTOSIZE
;
543 else if ( lvCol
.cx
== wxLIST_AUTOSIZE_USEHEADER
)
544 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
546 lvCol
.mask
|= LVCF_SUBITEM
;
547 lvCol
.iSubItem
= col
;
548 return (ListView_SetColumn(GetHwnd(), col
, & lvCol
) != 0);
551 // Gets the column width
552 int wxListCtrl::GetColumnWidth(int col
) const
554 return ListView_GetColumnWidth(GetHwnd(), col
);
557 // Sets the column width
558 bool wxListCtrl::SetColumnWidth(int col
, int width
)
561 if ( m_windowStyle
& wxLC_LIST
)
565 if ( width2
== wxLIST_AUTOSIZE
)
566 width2
= LVSCW_AUTOSIZE
;
567 else if ( width2
== wxLIST_AUTOSIZE_USEHEADER
)
568 width2
= LVSCW_AUTOSIZE_USEHEADER
;
570 return (ListView_SetColumnWidth(GetHwnd(), col2
, width2
) != 0);
573 // Gets the number of items that can fit vertically in the
574 // visible area of the list control (list or report view)
575 // or the total number of items in the list control (icon
576 // or small icon view)
577 int wxListCtrl::GetCountPerPage() const
579 return ListView_GetCountPerPage(GetHwnd());
582 // Gets the edit control for editing labels.
583 wxTextCtrl
* wxListCtrl::GetEditControl() const
588 // Gets information about the item
589 bool wxListCtrl::GetItem(wxListItem
& info
) const
592 wxZeroMemory(lvItem
);
594 lvItem
.iItem
= info
.m_itemId
;
595 lvItem
.iSubItem
= info
.m_col
;
597 if ( info
.m_mask
& wxLIST_MASK_TEXT
)
599 lvItem
.mask
|= LVIF_TEXT
;
600 lvItem
.pszText
= new wxChar
[513];
601 lvItem
.cchTextMax
= 512;
605 lvItem
.pszText
= NULL
;
608 if (info
.m_mask
& wxLIST_MASK_DATA
)
609 lvItem
.mask
|= LVIF_PARAM
;
611 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
612 lvItem
.mask
|= LVIF_IMAGE
;
614 if ( info
.m_mask
& wxLIST_MASK_STATE
)
616 lvItem
.mask
|= LVIF_STATE
;
617 // the other bits are hardly interesting anyhow
618 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
621 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
624 wxLogError(_("Couldn't retrieve information about list control item %d."),
629 wxConvertFromMSWListItem(this, info
, lvItem
);
633 delete[] lvItem
.pszText
;
638 // Sets information about the item
639 bool wxListCtrl::SetItem(wxListItem
& info
)
642 wxConvertToMSWListItem(this, info
, item
);
644 // check whether it has any custom attributes
645 if ( info
.HasAttributes() )
648 wxListItemAttr
*attr
;
649 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
653 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
655 else *attr
= *info
.GetAttributes();
661 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
662 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
664 // make the change visible
665 ListView_Update(GetHwnd(), item
.iItem
);
671 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
675 info
.m_mask
= wxLIST_MASK_TEXT
;
676 info
.m_itemId
= index
;
680 info
.m_image
= imageId
;
681 info
.m_mask
|= wxLIST_MASK_IMAGE
;
683 return SetItem(info
);
687 // Gets the item state
688 int wxListCtrl::GetItemState(long item
, long stateMask
) const
692 info
.m_mask
= wxLIST_MASK_STATE
;
693 info
.m_stateMask
= stateMask
;
694 info
.m_itemId
= item
;
702 // Sets the item state
703 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
707 info
.m_mask
= wxLIST_MASK_STATE
;
708 info
.m_state
= state
;
709 info
.m_stateMask
= stateMask
;
710 info
.m_itemId
= item
;
712 return SetItem(info
);
715 // Sets the item image
716 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
720 info
.m_mask
= wxLIST_MASK_IMAGE
;
721 info
.m_image
= image
;
722 info
.m_itemId
= item
;
724 return SetItem(info
);
727 // Gets the item text
728 wxString
wxListCtrl::GetItemText(long item
) const
732 info
.m_mask
= wxLIST_MASK_TEXT
;
733 info
.m_itemId
= item
;
740 // Sets the item text
741 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
745 info
.m_mask
= wxLIST_MASK_TEXT
;
746 info
.m_itemId
= item
;
752 // Gets the item data
753 long wxListCtrl::GetItemData(long item
) const
757 info
.m_mask
= wxLIST_MASK_DATA
;
758 info
.m_itemId
= item
;
765 // Sets the item data
766 bool wxListCtrl::SetItemData(long item
, long data
)
770 info
.m_mask
= wxLIST_MASK_DATA
;
771 info
.m_itemId
= item
;
774 return SetItem(info
);
777 // Gets the item rectangle
778 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
782 int code2
= LVIR_BOUNDS
;
783 if ( code
== wxLIST_RECT_BOUNDS
)
785 else if ( code
== wxLIST_RECT_ICON
)
787 else if ( code
== wxLIST_RECT_LABEL
)
791 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
793 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
798 rect
.width
= rect2
.right
- rect2
.left
;
799 rect
.height
= rect2
.bottom
- rect2
.top
;
803 // Gets the item position
804 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
808 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
810 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
814 // Sets the item position.
815 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
817 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
820 // Gets the number of items in the list control
821 int wxListCtrl::GetItemCount() const
823 return ListView_GetItemCount(GetHwnd());
826 // Retrieves the spacing between icons in pixels.
827 // If small is TRUE, gets the spacing for the small icon
828 // view, otherwise the large icon view.
829 int wxListCtrl::GetItemSpacing(bool isSmall
) const
831 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
834 // Gets the number of selected items in the list control
835 int wxListCtrl::GetSelectedItemCount() const
837 return ListView_GetSelectedCount(GetHwnd());
840 // Gets the text colour of the listview
841 wxColour
wxListCtrl::GetTextColour() const
843 COLORREF ref
= ListView_GetTextColor(GetHwnd());
844 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
848 // Sets the text colour of the listview
849 void wxListCtrl::SetTextColour(const wxColour
& col
)
851 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
854 // Gets the index of the topmost visible item when in
855 // list or report view
856 long wxListCtrl::GetTopItem() const
858 return (long) ListView_GetTopIndex(GetHwnd());
861 // Searches for an item, starting from 'item'.
862 // 'geometry' is one of
863 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
864 // 'state' is a state bit flag, one or more of
865 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
866 // item can be -1 to find the first item that matches the
868 // Returns the item or -1 if unsuccessful.
869 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
873 if ( geom
== wxLIST_NEXT_ABOVE
)
875 if ( geom
== wxLIST_NEXT_ALL
)
877 if ( geom
== wxLIST_NEXT_BELOW
)
879 if ( geom
== wxLIST_NEXT_LEFT
)
880 flags
|= LVNI_TOLEFT
;
881 if ( geom
== wxLIST_NEXT_RIGHT
)
882 flags
|= LVNI_TORIGHT
;
884 if ( state
& wxLIST_STATE_CUT
)
886 if ( state
& wxLIST_STATE_DROPHILITED
)
887 flags
|= LVNI_DROPHILITED
;
888 if ( state
& wxLIST_STATE_FOCUSED
)
889 flags
|= LVNI_FOCUSED
;
890 if ( state
& wxLIST_STATE_SELECTED
)
891 flags
|= LVNI_SELECTED
;
893 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
897 wxImageList
*wxListCtrl::GetImageList(int which
) const
899 if ( which
== wxIMAGE_LIST_NORMAL
)
901 return m_imageListNormal
;
903 else if ( which
== wxIMAGE_LIST_SMALL
)
905 return m_imageListSmall
;
907 else if ( which
== wxIMAGE_LIST_STATE
)
909 return m_imageListState
;
914 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
917 if ( which
== wxIMAGE_LIST_NORMAL
)
919 flags
= LVSIL_NORMAL
;
920 if (m_ownsImageListNormal
) delete m_imageListNormal
;
921 m_imageListNormal
= imageList
;
922 m_ownsImageListNormal
= FALSE
;
924 else if ( which
== wxIMAGE_LIST_SMALL
)
927 if (m_ownsImageListSmall
) delete m_imageListSmall
;
928 m_imageListSmall
= imageList
;
929 m_ownsImageListSmall
= FALSE
;
931 else if ( which
== wxIMAGE_LIST_STATE
)
934 if (m_ownsImageListState
) delete m_imageListState
;
935 m_imageListState
= imageList
;
936 m_ownsImageListState
= FALSE
;
938 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
941 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
943 SetImageList(imageList
, which
);
944 if ( which
== wxIMAGE_LIST_NORMAL
)
945 m_ownsImageListNormal
= TRUE
;
946 else if ( which
== wxIMAGE_LIST_SMALL
)
947 m_ownsImageListSmall
= TRUE
;
948 else if ( which
== wxIMAGE_LIST_STATE
)
949 m_ownsImageListState
= TRUE
;
952 // ----------------------------------------------------------------------------
954 // ----------------------------------------------------------------------------
956 // Arranges the items
957 bool wxListCtrl::Arrange(int flag
)
960 if ( flag
== wxLIST_ALIGN_LEFT
)
961 code
= LVA_ALIGNLEFT
;
962 else if ( flag
== wxLIST_ALIGN_TOP
)
964 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
966 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
967 code
= LVA_SNAPTOGRID
;
969 return (ListView_Arrange(GetHwnd(), code
) != 0);
973 bool wxListCtrl::DeleteItem(long item
)
975 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
979 bool wxListCtrl::DeleteAllItems()
981 return (ListView_DeleteAllItems(GetHwnd()) != 0);
985 bool wxListCtrl::DeleteAllColumns()
987 while ( m_colCount
> 0 )
989 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
991 wxLogLastError(wxT("ListView_DeleteColumn"));
999 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
1005 bool wxListCtrl::DeleteColumn(int col
)
1007 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
1009 if ( success
&& (m_colCount
> 0) )
1014 // Clears items, and columns if there are any.
1015 void wxListCtrl::ClearAll()
1018 if ( m_colCount
> 0 )
1022 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1024 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1026 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
1030 m_textCtrl
->UnsubclassWin();
1031 m_textCtrl
->SetHWND(0);
1036 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1037 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1038 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1043 // End label editing, optionally cancelling the edit
1044 bool wxListCtrl::EndEditLabel(bool cancel
)
1048 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
1050 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
1054 m_textCtrl->UnsubclassWin();
1055 m_textCtrl->SetHWND(0);
1065 // Ensures this item is visible
1066 bool wxListCtrl::EnsureVisible(long item
)
1068 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
1071 // Find an item whose label matches this string, starting from the item after 'start'
1072 // or the beginning if 'start' is -1.
1073 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1075 LV_FINDINFO findInfo
;
1077 findInfo
.flags
= LVFI_STRING
;
1079 findInfo
.flags
|= LVFI_PARTIAL
;
1082 // ListView_FindItem() excludes the first item from search and to look
1083 // through all the items you need to start from -1 which is unnatural and
1084 // inconsitent with the generic version - so we adjust the index
1085 return ListView_FindItem(GetHwnd(), (int) start
- 1, &findInfo
);
1088 // Find an item whose data matches this data, starting from the item after 'start'
1089 // or the beginning if 'start' is -1.
1090 long wxListCtrl::FindItem(long start
, long data
)
1092 LV_FINDINFO findInfo
;
1094 findInfo
.flags
= LVFI_PARAM
;
1095 findInfo
.lParam
= data
;
1097 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1100 // Find an item nearest this position in the specified direction, starting from
1101 // the item after 'start' or the beginning if 'start' is -1.
1102 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1104 LV_FINDINFO findInfo
;
1106 findInfo
.flags
= LVFI_NEARESTXY
;
1107 findInfo
.pt
.x
= pt
.x
;
1108 findInfo
.pt
.y
= pt
.y
;
1109 findInfo
.vkDirection
= VK_RIGHT
;
1111 if ( direction
== wxLIST_FIND_UP
)
1112 findInfo
.vkDirection
= VK_UP
;
1113 else if ( direction
== wxLIST_FIND_DOWN
)
1114 findInfo
.vkDirection
= VK_DOWN
;
1115 else if ( direction
== wxLIST_FIND_LEFT
)
1116 findInfo
.vkDirection
= VK_LEFT
;
1117 else if ( direction
== wxLIST_FIND_RIGHT
)
1118 findInfo
.vkDirection
= VK_RIGHT
;
1120 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1123 // Determines which item (if any) is at the specified point,
1124 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1125 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1127 LV_HITTESTINFO hitTestInfo
;
1128 hitTestInfo
.pt
.x
= (int) point
.x
;
1129 hitTestInfo
.pt
.y
= (int) point
.y
;
1131 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1134 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1135 flags
|= wxLIST_HITTEST_ABOVE
;
1136 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1137 flags
|= wxLIST_HITTEST_BELOW
;
1138 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1139 flags
|= wxLIST_HITTEST_NOWHERE
;
1140 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1141 flags
|= wxLIST_HITTEST_ONITEMICON
;
1142 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1143 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1144 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1145 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1146 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1147 flags
|= wxLIST_HITTEST_TOLEFT
;
1148 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1149 flags
|= wxLIST_HITTEST_TORIGHT
;
1151 return (long) hitTestInfo
.iItem
;
1154 // Inserts an item, returning the index of the new item if successful,
1156 long wxListCtrl::InsertItem(wxListItem
& info
)
1159 wxConvertToMSWListItem(this, info
, item
);
1161 // check whether it has any custom attributes
1162 if ( info
.HasAttributes() )
1165 wxListItemAttr
*attr
;
1166 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
1170 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1172 else *attr
= *info
.GetAttributes();
1174 m_hasAnyAttr
= TRUE
;
1177 return (long) ListView_InsertItem(GetHwnd(), & item
);
1180 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1183 info
.m_text
= label
;
1184 info
.m_mask
= wxLIST_MASK_TEXT
;
1185 info
.m_itemId
= index
;
1186 return InsertItem(info
);
1189 // Inserts an image item
1190 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1193 info
.m_image
= imageIndex
;
1194 info
.m_mask
= wxLIST_MASK_IMAGE
;
1195 info
.m_itemId
= index
;
1196 return InsertItem(info
);
1199 // Inserts an image/string item
1200 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1203 info
.m_image
= imageIndex
;
1204 info
.m_text
= label
;
1205 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1206 info
.m_itemId
= index
;
1207 return InsertItem(info
);
1210 // For list view mode (only), inserts a column.
1211 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1216 lvCol
.pszText
= NULL
;
1218 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1220 lvCol
.mask
|= LVCF_TEXT
;
1221 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1222 lvCol
.cchTextMax
= 0; // Ignored
1224 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1226 lvCol
.mask
|= LVCF_FMT
;
1228 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1229 lvCol
.fmt
= LVCFMT_LEFT
;
1230 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1231 lvCol
.fmt
= LVCFMT_RIGHT
;
1232 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1233 lvCol
.fmt
= LVCFMT_CENTER
;
1236 lvCol
.mask
|= LVCF_WIDTH
;
1237 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1239 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1240 lvCol
.cx
= LVSCW_AUTOSIZE
;
1241 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1242 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1244 lvCol
.cx
= item
.m_width
;
1248 // always give some width to the new column: this one is compatible
1253 lvCol
.mask
|= LVCF_SUBITEM
;
1254 lvCol
.iSubItem
= col
;
1256 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1263 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1270 long wxListCtrl::InsertColumn(long col
,
1271 const wxString
& heading
,
1276 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1277 item
.m_text
= heading
;
1280 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1281 item
.m_width
= width
;
1283 item
.m_format
= format
;
1285 return InsertColumn(col
, item
);
1288 // Scrolls the list control. If in icon, small icon or report view mode,
1289 // x specifies the number of pixels to scroll. If in list view mode, x
1290 // specifies the number of columns to scroll.
1291 // If in icon, small icon or list view mode, y specifies the number of pixels
1292 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1293 bool wxListCtrl::ScrollList(int dx
, int dy
)
1295 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1300 // fn is a function which takes 3 long arguments: item1, item2, data.
1301 // item1 is the long data associated with a first item (NOT the index).
1302 // item2 is the long data associated with a second item (NOT the index).
1303 // data is the same value as passed to SortItems.
1304 // The return value is a negative number if the first item should precede the second
1305 // item, a positive number of the second item should precede the first,
1306 // or zero if the two items are equivalent.
1308 // data is arbitrary data to be passed to the sort function.
1309 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1311 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1314 // ----------------------------------------------------------------------------
1315 // message processing
1316 // ----------------------------------------------------------------------------
1318 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1320 if (cmd
== EN_UPDATE
)
1322 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1323 event
.SetEventObject( this );
1324 ProcessCommand(event
);
1327 else if (cmd
== EN_KILLFOCUS
)
1329 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1330 event
.SetEventObject( this );
1331 ProcessCommand(event
);
1338 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1340 // prepare the event
1341 // -----------------
1343 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1344 wxEventType eventType
= wxEVT_NULL
;
1346 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1348 // almost all messages use NM_LISTVIEW
1349 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1351 // this is true for almost all events
1352 event
.m_item
.m_data
= nmLV
->lParam
;
1354 switch ( nmhdr
->code
)
1356 case LVN_BEGINRDRAG
:
1357 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1361 if ( eventType
== wxEVT_NULL
)
1363 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1366 event
.m_itemIndex
= nmLV
->iItem
;
1367 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1368 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1371 case LVN_BEGINLABELEDIT
:
1373 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1374 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1375 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1379 case LVN_COLUMNCLICK
:
1380 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1381 event
.m_itemIndex
= -1;
1382 event
.m_col
= nmLV
->iSubItem
;
1385 case LVN_DELETEALLITEMS
:
1386 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1387 event
.m_itemIndex
= -1;
1393 case LVN_DELETEITEM
:
1394 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1395 event
.m_itemIndex
= nmLV
->iItem
;
1399 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1403 case LVN_ENDLABELEDIT
:
1405 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1406 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1407 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1408 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1413 case LVN_SETDISPINFO
:
1415 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1416 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1417 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1421 case LVN_GETDISPINFO
:
1422 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1423 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1427 // TODO: some text buffering here, I think
1428 // TODO: API for getting Windows to retrieve values
1430 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1431 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1432 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1439 case LVN_INSERTITEM
:
1440 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1441 event
.m_itemIndex
= nmLV
->iItem
;
1444 case LVN_ITEMCHANGED
:
1445 // This needs to be sent to wxListCtrl as a rather more concrete
1446 // event. For now, just detect a selection or deselection.
1447 if ( (nmLV
->uNewState
& LVIS_SELECTED
) && !(nmLV
->uOldState
& LVIS_SELECTED
) )
1449 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1450 event
.m_itemIndex
= nmLV
->iItem
;
1452 else if ( !(nmLV
->uNewState
& LVIS_SELECTED
) && (nmLV
->uOldState
& LVIS_SELECTED
) )
1454 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1455 event
.m_itemIndex
= nmLV
->iItem
;
1465 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1466 WORD wVKey
= info
->wVKey
;
1468 // get the current selection
1469 long lItem
= GetNextItem(-1,
1471 wxLIST_STATE_SELECTED
);
1473 // <Enter> or <Space> activate the selected item if any
1474 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1476 // TODO this behaviour probably should be optional
1477 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1478 event
.m_itemIndex
= lItem
;
1482 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1483 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1488 // fill the other fields too
1489 event
.m_item
.m_text
= GetItemText(lItem
);
1490 event
.m_item
.m_data
= GetItemData(lItem
);
1496 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1498 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1503 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1504 // if it happened on an item (and not on empty place)
1505 if ( nmLV
->iItem
== -1 )
1511 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1512 event
.m_itemIndex
= nmLV
->iItem
;
1513 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1514 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1518 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1519 subclass and check for the actual WM_RBUTTONDOWN message,
1520 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1521 before firing off. We want to have notify events for both down
1524 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1525 // don't do anything else
1526 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1531 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1532 LV_HITTESTINFO lvhti
;
1533 wxZeroMemory(lvhti
);
1535 ::GetCursorPos(&(lvhti
.pt
));
1536 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1537 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1539 if ( lvhti
.flags
& LVHT_ONITEM
)
1541 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1542 event
.m_itemIndex
= lvhti
.iItem
;
1549 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1551 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1553 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1558 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1559 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1560 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1561 event
.m_itemIndex
= hdr
->iItem
;
1566 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1569 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1570 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1571 switch( nmcd
.dwDrawStage
)
1574 // if we've got any items with non standard attributes,
1575 // notify us before painting each item
1576 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1580 case CDDS_ITEMPREPAINT
:
1582 wxListItemAttr
*attr
=
1583 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1587 // nothing to do for this item
1588 return CDRF_DODEFAULT
;
1592 wxColour colText
, colBack
;
1593 if ( attr
->HasFont() )
1595 wxFont font
= attr
->GetFont();
1596 hFont
= (HFONT
)font
.GetResourceHandle();
1603 if ( attr
->HasTextColour() )
1605 colText
= attr
->GetTextColour();
1609 colText
= GetTextColour();
1612 if ( attr
->HasBackgroundColour() )
1614 colBack
= attr
->GetBackgroundColour();
1618 colBack
= GetBackgroundColour();
1621 // note that if we wanted to set colours for
1622 // individual columns (subitems), we would have
1623 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1626 ::SelectObject(nmcd
.hdc
, hFont
);
1628 *result
= CDRF_NEWFONT
;
1632 *result
= CDRF_DODEFAULT
;
1635 lplvcd
->clrText
= wxColourToRGB(colText
);
1636 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1642 *result
= CDRF_DODEFAULT
;
1647 #endif // _WIN32_IE >= 0x300
1650 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1653 // process the event
1654 // -----------------
1656 event
.SetEventObject( this );
1657 event
.SetEventType(eventType
);
1659 if ( !GetEventHandler()->ProcessEvent(event
) )
1665 switch ( nmhdr
->code
)
1667 case LVN_DELETEALLITEMS
:
1668 // always return TRUE to suppress all additional LVN_DELETEITEM
1669 // notifications - this makes deleting all items from a list ctrl
1675 case LVN_GETDISPINFO
:
1677 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1678 if ( info
->item
.mask
& LVIF_TEXT
)
1680 if ( !event
.m_item
.m_text
.IsNull() )
1682 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1683 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1686 // wxConvertToMSWListItem(this, event.m_item, info->item);
1689 case LVN_ENDLABELEDIT
:
1691 *result
= event
.IsAllowed();
1696 *result
= !event
.IsAllowed();
1701 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1703 // Remove the first element if 3 strings exist
1704 if ( m_stringPool
.Number() == 3 )
1706 wxNode
*node
= m_stringPool
.First();
1707 delete[] (char *)node
->Data();
1710 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1711 return (wxChar
*)node
->Data();
1714 // Necessary for drawing hrules and vrules, if specified
1715 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
1719 wxControl::OnPaint(event
);
1721 // Reset the device origin since it may have been set
1722 dc
.SetDeviceOrigin(0, 0);
1724 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
1725 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
1727 if (!drawHRules
&& !drawVRules
)
1729 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
1732 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1734 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1736 wxSize clientSize
= GetClientSize();
1741 int itemCount
= GetItemCount();
1743 for (i
= 0; i
< itemCount
; i
++)
1745 if (GetItemRect(i
, itemRect
))
1747 cy
= itemRect
.GetTop();
1748 if (i
!= 0) // Don't draw the first one
1750 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
1753 if (i
== (GetItemCount() - 1))
1755 cy
= itemRect
.GetBottom();
1756 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
1761 i
= (GetItemCount() - 1);
1762 if (drawVRules
&& (i
> -1))
1764 wxRect firstItemRect
;
1765 GetItemRect(0, firstItemRect
);
1767 if (GetItemRect(i
, itemRect
))
1770 int x
= itemRect
.GetX();
1771 for (col
= 0; col
< GetColumnCount(); col
++)
1773 int colWidth
= GetColumnWidth(col
);
1775 dc
.DrawLine(x
, firstItemRect
.GetY() - 2, x
, itemRect
.GetBottom());
1781 // ----------------------------------------------------------------------------
1783 // ----------------------------------------------------------------------------
1785 // List item structure
1786 wxListItem::wxListItem()
1796 m_format
= wxLIST_FORMAT_CENTRE
;
1802 void wxListItem::Clear()
1811 m_format
= wxLIST_FORMAT_CENTRE
;
1813 m_text
= wxEmptyString
;
1815 if (m_attr
) delete m_attr
;
1819 void wxListItem::ClearAttributes()
1821 if (m_attr
) delete m_attr
;
1825 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1827 info
.m_data
= lvItem
.lParam
;
1830 info
.m_stateMask
= 0;
1831 info
.m_itemId
= lvItem
.iItem
;
1833 long oldMask
= lvItem
.mask
;
1835 bool needText
= FALSE
;
1836 if (getFullInfo
!= 0)
1838 if ( lvItem
.mask
& LVIF_TEXT
)
1845 lvItem
.pszText
= new wxChar
[513];
1846 lvItem
.cchTextMax
= 512;
1848 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1849 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1850 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1853 if ( lvItem
.mask
& LVIF_STATE
)
1855 info
.m_mask
|= wxLIST_MASK_STATE
;
1857 if ( lvItem
.stateMask
& LVIS_CUT
)
1859 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1860 if ( lvItem
.state
& LVIS_CUT
)
1861 info
.m_state
|= wxLIST_STATE_CUT
;
1863 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1865 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1866 if ( lvItem
.state
& LVIS_DROPHILITED
)
1867 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1869 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1871 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1872 if ( lvItem
.state
& LVIS_FOCUSED
)
1873 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1875 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1877 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1878 if ( lvItem
.state
& LVIS_SELECTED
)
1879 info
.m_state
|= wxLIST_STATE_SELECTED
;
1883 if ( lvItem
.mask
& LVIF_TEXT
)
1885 info
.m_mask
|= wxLIST_MASK_TEXT
;
1886 info
.m_text
= lvItem
.pszText
;
1888 if ( lvItem
.mask
& LVIF_IMAGE
)
1890 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1891 info
.m_image
= lvItem
.iImage
;
1893 if ( lvItem
.mask
& LVIF_PARAM
)
1894 info
.m_mask
|= wxLIST_MASK_DATA
;
1895 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1896 info
.m_mask
|= wxLIST_SET_ITEM
;
1897 info
.m_col
= lvItem
.iSubItem
;
1902 delete[] lvItem
.pszText
;
1904 lvItem
.mask
= oldMask
;
1907 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1909 lvItem
.iItem
= (int) info
.m_itemId
;
1911 lvItem
.iImage
= info
.m_image
;
1912 lvItem
.lParam
= info
.m_data
;
1913 lvItem
.stateMask
= 0;
1916 lvItem
.iSubItem
= info
.m_col
;
1918 if (info
.m_mask
& wxLIST_MASK_STATE
)
1920 lvItem
.mask
|= LVIF_STATE
;
1921 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1923 lvItem
.stateMask
|= LVIS_CUT
;
1924 if (info
.m_state
& wxLIST_STATE_CUT
)
1925 lvItem
.state
|= LVIS_CUT
;
1927 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1929 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1930 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1931 lvItem
.state
|= LVIS_DROPHILITED
;
1933 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1935 lvItem
.stateMask
|= LVIS_FOCUSED
;
1936 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1937 lvItem
.state
|= LVIS_FOCUSED
;
1939 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1941 lvItem
.stateMask
|= LVIS_SELECTED
;
1942 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1943 lvItem
.state
|= LVIS_SELECTED
;
1947 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1949 lvItem
.mask
|= LVIF_TEXT
;
1950 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1952 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1956 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1957 if ( lvItem
.pszText
)
1958 lvItem
.cchTextMax
= info
.m_text
.Length();
1960 lvItem
.cchTextMax
= 0;
1963 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1964 lvItem
.mask
|= LVIF_IMAGE
;
1965 if (info
.m_mask
& wxLIST_MASK_DATA
)
1966 lvItem
.mask
|= LVIF_PARAM
;
1969 // ----------------------------------------------------------------------------
1971 // ----------------------------------------------------------------------------
1973 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1975 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1976 : wxNotifyEvent(commandType
, id
)
1982 m_cancelled
= FALSE
;