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
;
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_IMAGE
)
607 lvItem
.mask
|= LVIF_IMAGE
;
609 if ( info
.m_mask
& wxLIST_MASK_STATE
)
611 lvItem
.mask
|= LVIF_STATE
;
612 // the other bits are hardly interesting anyhow
613 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
616 bool success
= ListView_GetItem((HWND
)GetHWND(), &lvItem
) != 0;
619 wxLogError(_("Couldn't retrieve information about list control item %d."),
624 wxConvertFromMSWListItem(this, info
, lvItem
);
628 delete[] lvItem
.pszText
;
633 // Sets information about the item
634 bool wxListCtrl::SetItem(wxListItem
& info
)
637 wxConvertToMSWListItem(this, info
, item
);
639 // check whether it has any custom attributes
640 if ( info
.HasAttributes() )
643 wxListItemAttr
*attr
;
644 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
648 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
650 else *attr
= *info
.GetAttributes();
656 bool ok
= ListView_SetItem(GetHwnd(), &item
) != 0;
657 if ( ok
&& (info
.m_mask
& wxLIST_MASK_IMAGE
) )
659 // make the change visible
660 ListView_Update(GetHwnd(), item
.iItem
);
666 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
670 info
.m_mask
= wxLIST_MASK_TEXT
;
671 info
.m_itemId
= index
;
675 info
.m_image
= imageId
;
676 info
.m_mask
|= wxLIST_MASK_IMAGE
;
678 return SetItem(info
);
682 // Gets the item state
683 int wxListCtrl::GetItemState(long item
, long stateMask
) const
687 info
.m_mask
= wxLIST_MASK_STATE
;
688 info
.m_stateMask
= stateMask
;
689 info
.m_itemId
= item
;
697 // Sets the item state
698 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
702 info
.m_mask
= wxLIST_MASK_STATE
;
703 info
.m_state
= state
;
704 info
.m_stateMask
= stateMask
;
705 info
.m_itemId
= item
;
707 return SetItem(info
);
710 // Sets the item image
711 bool wxListCtrl::SetItemImage(long item
, int image
, int selImage
)
715 info
.m_mask
= wxLIST_MASK_IMAGE
;
716 info
.m_image
= image
;
717 info
.m_itemId
= item
;
719 return SetItem(info
);
722 // Gets the item text
723 wxString
wxListCtrl::GetItemText(long item
) const
727 info
.m_mask
= wxLIST_MASK_TEXT
;
728 info
.m_itemId
= item
;
735 // Sets the item text
736 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
740 info
.m_mask
= wxLIST_MASK_TEXT
;
741 info
.m_itemId
= item
;
747 // Gets the item data
748 long wxListCtrl::GetItemData(long item
) const
752 info
.m_mask
= wxLIST_MASK_DATA
;
753 info
.m_itemId
= item
;
760 // Sets the item data
761 bool wxListCtrl::SetItemData(long item
, long data
)
765 info
.m_mask
= wxLIST_MASK_DATA
;
766 info
.m_itemId
= item
;
769 return SetItem(info
);
772 // Gets the item rectangle
773 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
777 int code2
= LVIR_BOUNDS
;
778 if ( code
== wxLIST_RECT_BOUNDS
)
780 else if ( code
== wxLIST_RECT_ICON
)
782 else if ( code
== wxLIST_RECT_LABEL
)
786 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
) != 0);
788 bool success
= (ListView_GetItemRect(GetHwnd(), (int) item
, &rect2
, code2
) != 0);
793 rect
.width
= rect2
.right
- rect2
.left
;
794 rect
.height
= rect2
.bottom
- rect2
.top
;
798 // Gets the item position
799 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
803 bool success
= (ListView_GetItemPosition(GetHwnd(), (int) item
, &pt
) != 0);
805 pos
.x
= pt
.x
; pos
.y
= pt
.y
;
809 // Sets the item position.
810 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
812 return (ListView_SetItemPosition(GetHwnd(), (int) item
, pos
.x
, pos
.y
) != 0);
815 // Gets the number of items in the list control
816 int wxListCtrl::GetItemCount() const
818 return ListView_GetItemCount(GetHwnd());
821 // Retrieves the spacing between icons in pixels.
822 // If small is TRUE, gets the spacing for the small icon
823 // view, otherwise the large icon view.
824 int wxListCtrl::GetItemSpacing(bool isSmall
) const
826 return ListView_GetItemSpacing(GetHwnd(), (BOOL
) isSmall
);
829 // Gets the number of selected items in the list control
830 int wxListCtrl::GetSelectedItemCount() const
832 return ListView_GetSelectedCount(GetHwnd());
835 // Gets the text colour of the listview
836 wxColour
wxListCtrl::GetTextColour() const
838 COLORREF ref
= ListView_GetTextColor(GetHwnd());
839 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
843 // Sets the text colour of the listview
844 void wxListCtrl::SetTextColour(const wxColour
& col
)
846 ListView_SetTextColor(GetHwnd(), PALETTERGB(col
.Red(), col
.Green(), col
.Blue()));
849 // Gets the index of the topmost visible item when in
850 // list or report view
851 long wxListCtrl::GetTopItem() const
853 return (long) ListView_GetTopIndex(GetHwnd());
856 // Searches for an item, starting from 'item'.
857 // 'geometry' is one of
858 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
859 // 'state' is a state bit flag, one or more of
860 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
861 // item can be -1 to find the first item that matches the
863 // Returns the item or -1 if unsuccessful.
864 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
868 if ( geom
== wxLIST_NEXT_ABOVE
)
870 if ( geom
== wxLIST_NEXT_ALL
)
872 if ( geom
== wxLIST_NEXT_BELOW
)
874 if ( geom
== wxLIST_NEXT_LEFT
)
875 flags
|= LVNI_TOLEFT
;
876 if ( geom
== wxLIST_NEXT_RIGHT
)
877 flags
|= LVNI_TORIGHT
;
879 if ( state
& wxLIST_STATE_CUT
)
881 if ( state
& wxLIST_STATE_DROPHILITED
)
882 flags
|= LVNI_DROPHILITED
;
883 if ( state
& wxLIST_STATE_FOCUSED
)
884 flags
|= LVNI_FOCUSED
;
885 if ( state
& wxLIST_STATE_SELECTED
)
886 flags
|= LVNI_SELECTED
;
888 return (long) ListView_GetNextItem(GetHwnd(), item
, flags
);
892 wxImageList
*wxListCtrl::GetImageList(int which
) const
894 if ( which
== wxIMAGE_LIST_NORMAL
)
896 return m_imageListNormal
;
898 else if ( which
== wxIMAGE_LIST_SMALL
)
900 return m_imageListSmall
;
902 else if ( which
== wxIMAGE_LIST_STATE
)
904 return m_imageListState
;
909 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
912 if ( which
== wxIMAGE_LIST_NORMAL
)
914 flags
= LVSIL_NORMAL
;
915 m_imageListNormal
= imageList
;
917 else if ( which
== wxIMAGE_LIST_SMALL
)
920 m_imageListSmall
= imageList
;
922 else if ( which
== wxIMAGE_LIST_STATE
)
925 m_imageListState
= imageList
;
927 ListView_SetImageList(GetHwnd(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
930 // ----------------------------------------------------------------------------
932 // ----------------------------------------------------------------------------
934 // Arranges the items
935 bool wxListCtrl::Arrange(int flag
)
938 if ( flag
== wxLIST_ALIGN_LEFT
)
939 code
= LVA_ALIGNLEFT
;
940 else if ( flag
== wxLIST_ALIGN_TOP
)
942 else if ( flag
== wxLIST_ALIGN_DEFAULT
)
944 else if ( flag
== wxLIST_ALIGN_SNAP_TO_GRID
)
945 code
= LVA_SNAPTOGRID
;
947 return (ListView_Arrange(GetHwnd(), code
) != 0);
951 bool wxListCtrl::DeleteItem(long item
)
953 return (ListView_DeleteItem(GetHwnd(), (int) item
) != 0);
957 bool wxListCtrl::DeleteAllItems()
959 return (ListView_DeleteAllItems(GetHwnd()) != 0);
963 bool wxListCtrl::DeleteAllColumns()
965 while ( m_colCount
> 0 )
967 if ( ListView_DeleteColumn(GetHwnd(), 0) == 0 )
969 wxLogLastError(wxT("ListView_DeleteColumn"));
977 wxASSERT_MSG( m_colCount
== 0, wxT("no columns should be left") );
983 bool wxListCtrl::DeleteColumn(int col
)
985 bool success
= (ListView_DeleteColumn(GetHwnd(), col
) != 0);
987 if ( success
&& (m_colCount
> 0) )
992 // Clears items, and columns if there are any.
993 void wxListCtrl::ClearAll()
996 if ( m_colCount
> 0 )
1000 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1002 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
1004 HWND hWnd
= (HWND
) ListView_EditLabel(GetHwnd(), item
);
1008 m_textCtrl
->UnsubclassWin();
1009 m_textCtrl
->SetHWND(0);
1014 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
1015 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
1016 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
1021 // End label editing, optionally cancelling the edit
1022 bool wxListCtrl::EndEditLabel(bool cancel
)
1026 /* I don't know how to implement this: there's no such macro as ListView_EndEditLabelNow.
1028 bool success = (ListView_EndEditLabelNow(GetHwnd(), cancel) != 0);
1032 m_textCtrl->UnsubclassWin();
1033 m_textCtrl->SetHWND(0);
1043 // Ensures this item is visible
1044 bool wxListCtrl::EnsureVisible(long item
)
1046 return (ListView_EnsureVisible(GetHwnd(), (int) item
, FALSE
) != 0);
1049 // Find an item whose label matches this string, starting from the item after 'start'
1050 // or the beginning if 'start' is -1.
1051 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1053 LV_FINDINFO findInfo
;
1055 findInfo
.flags
= LVFI_STRING
;
1057 findInfo
.flags
|= LVFI_PARTIAL
;
1060 // ListView_FindItem() excludes the first item from search and to look
1061 // through all the items you need to start from -1 which is unnatural and
1062 // inconsitent with the generic version - so we adjust the index
1063 return ListView_FindItem(GetHwnd(), (int) start
- 1, &findInfo
);
1066 // Find an item whose data matches this data, starting from the item after 'start'
1067 // or the beginning if 'start' is -1.
1068 long wxListCtrl::FindItem(long start
, long data
)
1070 LV_FINDINFO findInfo
;
1072 findInfo
.flags
= LVFI_PARAM
;
1073 findInfo
.lParam
= data
;
1075 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1078 // Find an item nearest this position in the specified direction, starting from
1079 // the item after 'start' or the beginning if 'start' is -1.
1080 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1082 LV_FINDINFO findInfo
;
1084 findInfo
.flags
= LVFI_NEARESTXY
;
1085 findInfo
.pt
.x
= pt
.x
;
1086 findInfo
.pt
.y
= pt
.y
;
1087 findInfo
.vkDirection
= VK_RIGHT
;
1089 if ( direction
== wxLIST_FIND_UP
)
1090 findInfo
.vkDirection
= VK_UP
;
1091 else if ( direction
== wxLIST_FIND_DOWN
)
1092 findInfo
.vkDirection
= VK_DOWN
;
1093 else if ( direction
== wxLIST_FIND_LEFT
)
1094 findInfo
.vkDirection
= VK_LEFT
;
1095 else if ( direction
== wxLIST_FIND_RIGHT
)
1096 findInfo
.vkDirection
= VK_RIGHT
;
1098 return ListView_FindItem(GetHwnd(), (int) start
, & findInfo
);
1101 // Determines which item (if any) is at the specified point,
1102 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1103 long wxListCtrl::HitTest(const wxPoint
& point
, int& flags
)
1105 LV_HITTESTINFO hitTestInfo
;
1106 hitTestInfo
.pt
.x
= (int) point
.x
;
1107 hitTestInfo
.pt
.y
= (int) point
.y
;
1109 ListView_HitTest(GetHwnd(), & hitTestInfo
);
1112 if ( hitTestInfo
.flags
& LVHT_ABOVE
)
1113 flags
|= wxLIST_HITTEST_ABOVE
;
1114 if ( hitTestInfo
.flags
& LVHT_BELOW
)
1115 flags
|= wxLIST_HITTEST_BELOW
;
1116 if ( hitTestInfo
.flags
& LVHT_NOWHERE
)
1117 flags
|= wxLIST_HITTEST_NOWHERE
;
1118 if ( hitTestInfo
.flags
& LVHT_ONITEMICON
)
1119 flags
|= wxLIST_HITTEST_ONITEMICON
;
1120 if ( hitTestInfo
.flags
& LVHT_ONITEMLABEL
)
1121 flags
|= wxLIST_HITTEST_ONITEMLABEL
;
1122 if ( hitTestInfo
.flags
& LVHT_ONITEMSTATEICON
)
1123 flags
|= wxLIST_HITTEST_ONITEMSTATEICON
;
1124 if ( hitTestInfo
.flags
& LVHT_TOLEFT
)
1125 flags
|= wxLIST_HITTEST_TOLEFT
;
1126 if ( hitTestInfo
.flags
& LVHT_TORIGHT
)
1127 flags
|= wxLIST_HITTEST_TORIGHT
;
1129 return (long) hitTestInfo
.iItem
;
1132 // Inserts an item, returning the index of the new item if successful,
1134 long wxListCtrl::InsertItem(wxListItem
& info
)
1137 wxConvertToMSWListItem(this, info
, item
);
1139 // check whether it has any custom attributes
1140 if ( info
.HasAttributes() )
1143 wxListItemAttr
*attr
;
1144 attr
= (wxListItemAttr
*) m_attrs
.Get(item
.iItem
);
1148 m_attrs
.Put(item
.iItem
, (wxObject
*)new wxListItemAttr(*info
.GetAttributes()));
1150 else *attr
= *info
.GetAttributes();
1152 m_hasAnyAttr
= TRUE
;
1155 return (long) ListView_InsertItem(GetHwnd(), & item
);
1158 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1161 info
.m_text
= label
;
1162 info
.m_mask
= wxLIST_MASK_TEXT
;
1163 info
.m_itemId
= index
;
1164 return InsertItem(info
);
1167 // Inserts an image item
1168 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1171 info
.m_image
= imageIndex
;
1172 info
.m_mask
= wxLIST_MASK_IMAGE
;
1173 info
.m_itemId
= index
;
1174 return InsertItem(info
);
1177 // Inserts an image/string item
1178 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1181 info
.m_image
= imageIndex
;
1182 info
.m_text
= label
;
1183 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1184 info
.m_itemId
= index
;
1185 return InsertItem(info
);
1188 // For list view mode (only), inserts a column.
1189 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1194 lvCol
.pszText
= NULL
;
1196 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
1198 lvCol
.mask
|= LVCF_TEXT
;
1199 lvCol
.pszText
= WXSTRINGCAST item
.m_text
;
1200 lvCol
.cchTextMax
= 0; // Ignored
1202 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
1204 lvCol
.mask
|= LVCF_FMT
;
1206 if ( item
.m_format
== wxLIST_FORMAT_LEFT
)
1207 lvCol
.fmt
= LVCFMT_LEFT
;
1208 if ( item
.m_format
== wxLIST_FORMAT_RIGHT
)
1209 lvCol
.fmt
= LVCFMT_RIGHT
;
1210 if ( item
.m_format
== wxLIST_FORMAT_CENTRE
)
1211 lvCol
.fmt
= LVCFMT_CENTER
;
1214 lvCol
.mask
|= LVCF_WIDTH
;
1215 if ( item
.m_mask
& wxLIST_MASK_WIDTH
)
1217 if ( item
.m_width
== wxLIST_AUTOSIZE
)
1218 lvCol
.cx
= LVSCW_AUTOSIZE
;
1219 else if ( item
.m_width
== wxLIST_AUTOSIZE_USEHEADER
)
1220 lvCol
.cx
= LVSCW_AUTOSIZE_USEHEADER
;
1222 lvCol
.cx
= item
.m_width
;
1226 // always give some width to the new column: this one is compatible
1231 lvCol
.mask
|= LVCF_SUBITEM
;
1232 lvCol
.iSubItem
= col
;
1234 bool success
= ListView_InsertColumn(GetHwnd(), col
, & lvCol
) != -1;
1241 wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
1248 long wxListCtrl::InsertColumn(long col
,
1249 const wxString
& heading
,
1254 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1255 item
.m_text
= heading
;
1258 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1259 item
.m_width
= width
;
1261 item
.m_format
= format
;
1263 return InsertColumn(col
, item
);
1266 // Scrolls the list control. If in icon, small icon or report view mode,
1267 // x specifies the number of pixels to scroll. If in list view mode, x
1268 // specifies the number of columns to scroll.
1269 // If in icon, small icon or list view mode, y specifies the number of pixels
1270 // to scroll. If in report view mode, y specifies the number of lines to scroll.
1271 bool wxListCtrl::ScrollList(int dx
, int dy
)
1273 return (ListView_Scroll(GetHwnd(), dx
, dy
) != 0);
1278 // fn is a function which takes 3 long arguments: item1, item2, data.
1279 // item1 is the long data associated with a first item (NOT the index).
1280 // item2 is the long data associated with a second item (NOT the index).
1281 // data is the same value as passed to SortItems.
1282 // The return value is a negative number if the first item should precede the second
1283 // item, a positive number of the second item should precede the first,
1284 // or zero if the two items are equivalent.
1286 // data is arbitrary data to be passed to the sort function.
1287 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1289 return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE
) fn
, data
) != 0);
1292 // ----------------------------------------------------------------------------
1293 // message processing
1294 // ----------------------------------------------------------------------------
1296 bool wxListCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
1298 if (cmd
== EN_UPDATE
)
1300 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
1301 event
.SetEventObject( this );
1302 ProcessCommand(event
);
1305 else if (cmd
== EN_KILLFOCUS
)
1307 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
1308 event
.SetEventObject( this );
1309 ProcessCommand(event
);
1316 bool wxListCtrl::MSWOnNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
1318 // prepare the event
1319 // -----------------
1321 wxListEvent
event(wxEVT_NULL
, m_windowId
);
1322 wxEventType eventType
= wxEVT_NULL
;
1324 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1326 // almost all messages use NM_LISTVIEW
1327 NM_LISTVIEW
*nmLV
= (NM_LISTVIEW
*)nmhdr
;
1329 // this is true for almost all events
1330 event
.m_item
.m_data
= nmLV
->lParam
;
1332 switch ( nmhdr
->code
)
1334 case LVN_BEGINRDRAG
:
1335 eventType
= wxEVT_COMMAND_LIST_BEGIN_RDRAG
;
1339 if ( eventType
== wxEVT_NULL
)
1341 eventType
= wxEVT_COMMAND_LIST_BEGIN_DRAG
;
1344 event
.m_itemIndex
= nmLV
->iItem
;
1345 event
.m_pointDrag
.x
= nmLV
->ptAction
.x
;
1346 event
.m_pointDrag
.y
= nmLV
->ptAction
.y
;
1349 case LVN_BEGINLABELEDIT
:
1351 eventType
= wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
;
1352 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1353 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1357 case LVN_COLUMNCLICK
:
1358 eventType
= wxEVT_COMMAND_LIST_COL_CLICK
;
1359 event
.m_itemIndex
= -1;
1360 event
.m_col
= nmLV
->iSubItem
;
1363 case LVN_DELETEALLITEMS
:
1364 eventType
= wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
;
1365 event
.m_itemIndex
= -1;
1371 case LVN_DELETEITEM
:
1372 eventType
= wxEVT_COMMAND_LIST_DELETE_ITEM
;
1373 event
.m_itemIndex
= nmLV
->iItem
;
1377 delete (wxListItemAttr
*)m_attrs
.Delete(nmLV
->iItem
);
1381 case LVN_ENDLABELEDIT
:
1383 eventType
= wxEVT_COMMAND_LIST_END_LABEL_EDIT
;
1384 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1385 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
);
1386 if ( info
->item
.pszText
== NULL
|| info
->item
.iItem
== -1 )
1391 case LVN_SETDISPINFO
:
1393 eventType
= wxEVT_COMMAND_LIST_SET_INFO
;
1394 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1395 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1399 case LVN_GETDISPINFO
:
1400 // this provokes stack overflow: indeed, wxConvertFromMSWListItem()
1401 // sends us WM_NOTIFY! As it doesn't do anything for now, just leave
1405 // TODO: some text buffering here, I think
1406 // TODO: API for getting Windows to retrieve values
1408 eventType
= wxEVT_COMMAND_LIST_GET_INFO
;
1409 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1410 wxConvertFromMSWListItem(this, event
.m_item
, info
->item
, GetHwnd());
1417 case LVN_INSERTITEM
:
1418 eventType
= wxEVT_COMMAND_LIST_INSERT_ITEM
;
1419 event
.m_itemIndex
= nmLV
->iItem
;
1422 case LVN_ITEMCHANGED
:
1423 // This needs to be sent to wxListCtrl as a rather more concrete
1424 // event. For now, just detect a selection or deselection.
1425 if ( (nmLV
->uNewState
& LVIS_SELECTED
) && !(nmLV
->uOldState
& LVIS_SELECTED
) )
1427 eventType
= wxEVT_COMMAND_LIST_ITEM_SELECTED
;
1428 event
.m_itemIndex
= nmLV
->iItem
;
1430 else if ( !(nmLV
->uNewState
& LVIS_SELECTED
) && (nmLV
->uOldState
& LVIS_SELECTED
) )
1432 eventType
= wxEVT_COMMAND_LIST_ITEM_DESELECTED
;
1433 event
.m_itemIndex
= nmLV
->iItem
;
1443 LV_KEYDOWN
*info
= (LV_KEYDOWN
*)lParam
;
1444 WORD wVKey
= info
->wVKey
;
1446 // get the current selection
1447 long lItem
= GetNextItem(-1,
1449 wxLIST_STATE_SELECTED
);
1451 // <Enter> or <Space> activate the selected item if any
1452 if ( lItem
!= -1 && (wVKey
== VK_RETURN
|| wVKey
== VK_SPACE
) )
1454 // TODO this behaviour probably should be optional
1455 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1456 event
.m_itemIndex
= lItem
;
1460 eventType
= wxEVT_COMMAND_LIST_KEY_DOWN
;
1461 event
.m_code
= wxCharCodeMSWToWX(wVKey
);
1466 // fill the other fields too
1467 event
.m_item
.m_text
= GetItemText(lItem
);
1468 event
.m_item
.m_data
= GetItemData(lItem
);
1474 // if the user processes it in wxEVT_COMMAND_LEFT_CLICK(), don't do
1476 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1481 // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
1482 // if it happened on an item (and not on empty place)
1483 if ( nmLV
->iItem
== -1 )
1489 eventType
= wxEVT_COMMAND_LIST_ITEM_ACTIVATED
;
1490 event
.m_itemIndex
= nmLV
->iItem
;
1491 event
.m_item
.m_text
= GetItemText(nmLV
->iItem
);
1492 event
.m_item
.m_data
= GetItemData(nmLV
->iItem
);
1496 /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
1497 subclass and check for the actual WM_RBUTTONDOWN message,
1498 because NM_RCLICK waits for the WM_RBUTTONUP message as well
1499 before firing off. We want to have notify events for both down
1502 // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(),
1503 // don't do anything else
1504 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1509 // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
1510 LV_HITTESTINFO lvhti
;
1511 wxZeroMemory(lvhti
);
1513 ::GetCursorPos(&(lvhti
.pt
));
1514 ::ScreenToClient(GetHwnd(),&(lvhti
.pt
));
1515 if ( ListView_HitTest(GetHwnd(),&lvhti
) != -1 )
1517 if ( lvhti
.flags
& LVHT_ONITEM
)
1519 eventType
= wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
;
1520 event
.m_itemIndex
= lvhti
.iItem
;
1527 case NM_MCLICK
: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
1529 // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
1531 if ( wxControl::MSWOnNotify(idCtrl
, lParam
, result
) )
1536 // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
1537 eventType
= wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
;
1538 NMITEMACTIVATE
* hdr
= (NMITEMACTIVATE
*)lParam
;
1539 event
.m_itemIndex
= hdr
->iItem
;
1544 #if defined(_WIN32_IE) && _WIN32_IE >= 0x300
1547 LPNMLVCUSTOMDRAW lplvcd
= (LPNMLVCUSTOMDRAW
)lParam
;
1548 NMCUSTOMDRAW
& nmcd
= lplvcd
->nmcd
;
1549 switch( nmcd
.dwDrawStage
)
1552 // if we've got any items with non standard attributes,
1553 // notify us before painting each item
1554 *result
= m_hasAnyAttr
? CDRF_NOTIFYITEMDRAW
1558 case CDDS_ITEMPREPAINT
:
1560 wxListItemAttr
*attr
=
1561 (wxListItemAttr
*)m_attrs
.Get(nmcd
.dwItemSpec
);
1565 // nothing to do for this item
1566 return CDRF_DODEFAULT
;
1570 wxColour colText
, colBack
;
1571 if ( attr
->HasFont() )
1573 wxFont font
= attr
->GetFont();
1574 hFont
= (HFONT
)font
.GetResourceHandle();
1581 if ( attr
->HasTextColour() )
1583 colText
= attr
->GetTextColour();
1587 colText
= GetTextColour();
1590 if ( attr
->HasBackgroundColour() )
1592 colBack
= attr
->GetBackgroundColour();
1596 colBack
= GetBackgroundColour();
1599 // note that if we wanted to set colours for
1600 // individual columns (subitems), we would have
1601 // returned CDRF_NOTIFYSUBITEMREDRAW from here
1604 ::SelectObject(nmcd
.hdc
, hFont
);
1606 *result
= CDRF_NEWFONT
;
1610 *result
= CDRF_DODEFAULT
;
1613 lplvcd
->clrText
= wxColourToRGB(colText
);
1614 lplvcd
->clrTextBk
= wxColourToRGB(colBack
);
1620 *result
= CDRF_DODEFAULT
;
1625 #endif // _WIN32_IE >= 0x300
1628 return wxControl::MSWOnNotify(idCtrl
, lParam
, result
);
1631 // process the event
1632 // -----------------
1634 event
.SetEventObject( this );
1635 event
.SetEventType(eventType
);
1637 if ( !GetEventHandler()->ProcessEvent(event
) )
1643 switch ( nmhdr
->code
)
1645 case LVN_DELETEALLITEMS
:
1646 // always return TRUE to suppress all additional LVN_DELETEITEM
1647 // notifications - this makes deleting all items from a list ctrl
1653 case LVN_GETDISPINFO
:
1655 LV_DISPINFO
*info
= (LV_DISPINFO
*)lParam
;
1656 if ( info
->item
.mask
& LVIF_TEXT
)
1658 if ( !event
.m_item
.m_text
.IsNull() )
1660 info
->item
.pszText
= AddPool(event
.m_item
.m_text
);
1661 info
->item
.cchTextMax
= wxStrlen(info
->item
.pszText
) + 1;
1664 // wxConvertToMSWListItem(this, event.m_item, info->item);
1667 case LVN_ENDLABELEDIT
:
1669 *result
= event
.IsAllowed();
1674 *result
= !event
.IsAllowed();
1679 wxChar
*wxListCtrl::AddPool(const wxString
& str
)
1681 // Remove the first element if 3 strings exist
1682 if ( m_stringPool
.Number() == 3 )
1684 wxNode
*node
= m_stringPool
.First();
1685 delete[] (char *)node
->Data();
1688 wxNode
*node
= m_stringPool
.Add(WXSTRINGCAST str
);
1689 return (wxChar
*)node
->Data();
1692 // Necessary for drawing hrules and vrules, if specified
1693 void wxListCtrl::OnPaint(wxPaintEvent
& event
)
1697 wxControl::OnPaint(event
);
1699 // Reset the device origin since it may have been set
1700 dc
.SetDeviceOrigin(0, 0);
1702 bool drawHRules
= ((GetWindowStyle() & wxLC_HRULES
) != 0);
1703 bool drawVRules
= ((GetWindowStyle() & wxLC_VRULES
) != 0);
1705 if (!drawHRules
&& !drawVRules
)
1707 if ((GetWindowStyle() & wxLC_REPORT
) == 0)
1710 wxPen
pen(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DLIGHT
), 1, wxSOLID
);
1712 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1714 wxSize clientSize
= GetClientSize();
1719 int itemCount
= GetItemCount();
1721 for (i
= 0; i
< itemCount
; i
++)
1723 if (GetItemRect(i
, itemRect
))
1725 cy
= itemRect
.GetTop();
1726 if (i
!= 0) // Don't draw the first one
1728 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
1731 if (i
== (GetItemCount() - 1))
1733 cy
= itemRect
.GetBottom();
1734 dc
.DrawLine(0, cy
, clientSize
.x
, cy
);
1739 i
= (GetItemCount() - 1);
1740 if (drawVRules
&& (i
> -1))
1742 wxRect firstItemRect
;
1743 GetItemRect(0, firstItemRect
);
1745 if (GetItemRect(i
, itemRect
))
1748 int x
= itemRect
.GetX();
1749 for (col
= 0; col
< GetColumnCount(); col
++)
1751 int colWidth
= GetColumnWidth(col
);
1753 dc
.DrawLine(x
, firstItemRect
.GetY() - 2, x
, itemRect
.GetBottom());
1759 // ----------------------------------------------------------------------------
1761 // ----------------------------------------------------------------------------
1763 // List item structure
1764 wxListItem::wxListItem()
1774 m_format
= wxLIST_FORMAT_CENTRE
;
1780 void wxListItem::Clear()
1789 m_format
= wxLIST_FORMAT_CENTRE
;
1791 m_text
= wxEmptyString
;
1793 if (m_attr
) delete m_attr
;
1797 void wxListItem::ClearAttributes()
1799 if (m_attr
) delete m_attr
;
1803 static void wxConvertFromMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
, HWND getFullInfo
)
1805 info
.m_data
= lvItem
.lParam
;
1808 info
.m_stateMask
= 0;
1809 info
.m_itemId
= lvItem
.iItem
;
1811 long oldMask
= lvItem
.mask
;
1813 bool needText
= FALSE
;
1814 if (getFullInfo
!= 0)
1816 if ( lvItem
.mask
& LVIF_TEXT
)
1823 lvItem
.pszText
= new wxChar
[513];
1824 lvItem
.cchTextMax
= 512;
1826 // lvItem.mask |= TVIF_HANDLE | TVIF_STATE | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_CHILDREN | TVIF_PARAM;
1827 lvItem
.mask
|= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
1828 ::SendMessage(getFullInfo
, LVM_GETITEM
, 0, (LPARAM
)& lvItem
);
1831 if ( lvItem
.mask
& LVIF_STATE
)
1833 info
.m_mask
|= wxLIST_MASK_STATE
;
1835 if ( lvItem
.stateMask
& LVIS_CUT
)
1837 info
.m_stateMask
|= wxLIST_STATE_CUT
;
1838 if ( lvItem
.state
& LVIS_CUT
)
1839 info
.m_state
|= wxLIST_STATE_CUT
;
1841 if ( lvItem
.stateMask
& LVIS_DROPHILITED
)
1843 info
.m_stateMask
|= wxLIST_STATE_DROPHILITED
;
1844 if ( lvItem
.state
& LVIS_DROPHILITED
)
1845 info
.m_state
|= wxLIST_STATE_DROPHILITED
;
1847 if ( lvItem
.stateMask
& LVIS_FOCUSED
)
1849 info
.m_stateMask
|= wxLIST_STATE_FOCUSED
;
1850 if ( lvItem
.state
& LVIS_FOCUSED
)
1851 info
.m_state
|= wxLIST_STATE_FOCUSED
;
1853 if ( lvItem
.stateMask
& LVIS_SELECTED
)
1855 info
.m_stateMask
|= wxLIST_STATE_SELECTED
;
1856 if ( lvItem
.state
& LVIS_SELECTED
)
1857 info
.m_state
|= wxLIST_STATE_SELECTED
;
1861 if ( lvItem
.mask
& LVIF_TEXT
)
1863 info
.m_mask
|= wxLIST_MASK_TEXT
;
1864 info
.m_text
= lvItem
.pszText
;
1866 if ( lvItem
.mask
& LVIF_IMAGE
)
1868 info
.m_mask
|= wxLIST_MASK_IMAGE
;
1869 info
.m_image
= lvItem
.iImage
;
1871 if ( lvItem
.mask
& LVIF_PARAM
)
1872 info
.m_mask
|= wxLIST_MASK_DATA
;
1873 if ( lvItem
.mask
& LVIF_DI_SETITEM
)
1874 info
.m_mask
|= wxLIST_SET_ITEM
;
1875 info
.m_col
= lvItem
.iSubItem
;
1880 delete[] lvItem
.pszText
;
1882 lvItem
.mask
= oldMask
;
1885 static void wxConvertToMSWListItem(const wxListCtrl
*ctrl
, wxListItem
& info
, LV_ITEM
& lvItem
)
1887 lvItem
.iItem
= (int) info
.m_itemId
;
1889 lvItem
.iImage
= info
.m_image
;
1890 lvItem
.lParam
= info
.m_data
;
1891 lvItem
.stateMask
= 0;
1894 lvItem
.iSubItem
= info
.m_col
;
1896 if (info
.m_mask
& wxLIST_MASK_STATE
)
1898 lvItem
.mask
|= LVIF_STATE
;
1899 if (info
.m_stateMask
& wxLIST_STATE_CUT
)
1901 lvItem
.stateMask
|= LVIS_CUT
;
1902 if (info
.m_state
& wxLIST_STATE_CUT
)
1903 lvItem
.state
|= LVIS_CUT
;
1905 if (info
.m_stateMask
& wxLIST_STATE_DROPHILITED
)
1907 lvItem
.stateMask
|= LVIS_DROPHILITED
;
1908 if (info
.m_state
& wxLIST_STATE_DROPHILITED
)
1909 lvItem
.state
|= LVIS_DROPHILITED
;
1911 if (info
.m_stateMask
& wxLIST_STATE_FOCUSED
)
1913 lvItem
.stateMask
|= LVIS_FOCUSED
;
1914 if (info
.m_state
& wxLIST_STATE_FOCUSED
)
1915 lvItem
.state
|= LVIS_FOCUSED
;
1917 if (info
.m_stateMask
& wxLIST_STATE_SELECTED
)
1919 lvItem
.stateMask
|= LVIS_SELECTED
;
1920 if (info
.m_state
& wxLIST_STATE_SELECTED
)
1921 lvItem
.state
|= LVIS_SELECTED
;
1925 if (info
.m_mask
& wxLIST_MASK_TEXT
)
1927 lvItem
.mask
|= LVIF_TEXT
;
1928 if ( ctrl
->GetWindowStyleFlag() & wxLC_USER_TEXT
)
1930 lvItem
.pszText
= LPSTR_TEXTCALLBACK
;
1934 lvItem
.pszText
= WXSTRINGCAST info
.m_text
;
1935 if ( lvItem
.pszText
)
1936 lvItem
.cchTextMax
= info
.m_text
.Length();
1938 lvItem
.cchTextMax
= 0;
1941 if (info
.m_mask
& wxLIST_MASK_IMAGE
)
1942 lvItem
.mask
|= LVIF_IMAGE
;
1943 if (info
.m_mask
& wxLIST_MASK_DATA
)
1944 lvItem
.mask
|= LVIF_PARAM
;
1947 // ----------------------------------------------------------------------------
1949 // ----------------------------------------------------------------------------
1951 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
1953 wxListEvent::wxListEvent(wxEventType commandType
, int id
)
1954 : wxNotifyEvent(commandType
, id
)
1960 m_cancelled
= FALSE
;