1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/listctrl.cpp
4 // Author: Julian Smart
5 // Modified by: Agron Selimaj
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
35 #include "wx/textctrl.h"
38 #include "wx/mac/uma.h"
40 #include "wx/imaglist.h"
41 #include "wx/listctrl.h"
42 #include "wx/sysopt.h"
44 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
46 #if wxUSE_EXTENDED_RTTI
47 WX_DEFINE_FLAGS( wxListCtrlStyle
)
49 wxBEGIN_FLAGS( wxListCtrlStyle
)
50 // new style border flags, we put them first to
51 // use them for streaming out
52 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
53 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
54 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
55 wxFLAGS_MEMBER(wxBORDER_RAISED
)
56 wxFLAGS_MEMBER(wxBORDER_STATIC
)
57 wxFLAGS_MEMBER(wxBORDER_NONE
)
59 // old style border flags
60 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
61 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
62 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
63 wxFLAGS_MEMBER(wxRAISED_BORDER
)
64 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
65 wxFLAGS_MEMBER(wxBORDER
)
67 // standard window styles
68 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
69 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
70 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
71 wxFLAGS_MEMBER(wxWANTS_CHARS
)
72 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
73 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
74 wxFLAGS_MEMBER(wxVSCROLL
)
75 wxFLAGS_MEMBER(wxHSCROLL
)
77 wxFLAGS_MEMBER(wxLC_LIST
)
78 wxFLAGS_MEMBER(wxLC_REPORT
)
79 wxFLAGS_MEMBER(wxLC_ICON
)
80 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
81 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
82 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
83 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
84 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
85 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
86 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
87 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
88 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
89 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
90 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
92 wxEND_FLAGS( wxListCtrlStyle
)
94 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
96 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
97 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
99 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
100 wxEND_PROPERTIES_TABLE()
102 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
103 wxEND_HANDLERS_TABLE()
105 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
108 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
111 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
114 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
115 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
117 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
119 WX_DECLARE_EXPORTED_LIST(wxListItem
, wxListItemList
);
120 #include "wx/listimpl.cpp"
121 WX_DEFINE_LIST(wxListItemList
)
123 class wxMacListCtrlItem
: public wxMacListBoxItem
128 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
129 DataBrowserItemNotification message
,
130 DataBrowserItemDataRef itemData
) const;
132 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
133 virtual wxListItem
* GetColumnInfo( unsigned int column
);
134 virtual bool HasColumnInfo( unsigned int column
);
136 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
137 virtual const wxString
& GetColumnTextValue( unsigned int column
);
139 virtual int GetColumnImageValue( unsigned int column
);
140 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
142 virtual OSStatus
GetSetData( wxMacDataItemBrowserControl
*owner
,
143 DataBrowserPropertyID property
,
144 DataBrowserItemDataRef itemData
,
148 virtual ~wxMacListCtrlItem();
150 wxListItemList m_rowItems
;
153 // TODO: Make a better name!!
154 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
157 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
158 virtual ~wxMacDataBrowserListCtrlControl();
160 // create a list item (can be a subclass of wxMacListBoxItem)
162 virtual wxMacListCtrlItem
* CreateItem();
164 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
165 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
166 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
167 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
170 wxClientDataType m_clientDataItemsType
;
174 // TODO: This gives errors, find out why.
175 //BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
176 // EVT_PAINT(wxListCtrl::OnPaint)
179 // ============================================================================
181 // ============================================================================
183 wxMacListControl
* wxListCtrl::GetPeer() const
185 return dynamic_cast<wxMacListControl
*>(m_peer
);
188 // ----------------------------------------------------------------------------
189 // wxListCtrl construction
190 // ----------------------------------------------------------------------------
192 void wxListCtrl::Init()
194 m_imageListNormal
= NULL
;
195 m_imageListSmall
= NULL
;
196 m_imageListState
= NULL
;
198 // keep track of if we created our own image lists, or if they were assigned
200 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
204 m_genericImpl
= NULL
;
208 bool wxListCtrl::Create(wxWindow
*parent
,
213 const wxValidator
& validator
,
214 const wxString
& name
)
217 // for now, we'll always use the generic list control for ICON and LIST views,
218 // because they dynamically change the number of columns on resize.
219 // Also, allow the user to set it to use the list ctrl as well.
220 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
221 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
222 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
))
224 m_macIsUserPane
= true;
226 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
228 m_genericImpl
= new wxGenericListCtrl(this, id
, pos
, size
, style
, validator
, name
);
234 m_macIsUserPane
= false;
236 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
238 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
241 MacPostControlCreate( pos
, size
);
247 wxListCtrl::~wxListCtrl()
249 if (m_ownsImageListNormal
)
250 delete m_imageListNormal
;
251 if (m_ownsImageListSmall
)
252 delete m_imageListSmall
;
253 if (m_ownsImageListState
)
254 delete m_imageListState
;
257 // ----------------------------------------------------------------------------
258 // set/get/change style
259 // ----------------------------------------------------------------------------
261 // Add or remove a single window style
262 void wxListCtrl::SetSingleStyle(long style
, bool add
)
264 long flag
= GetWindowStyleFlag();
266 // Get rid of conflicting styles
269 if ( style
& wxLC_MASK_TYPE
)
270 flag
= flag
& ~wxLC_MASK_TYPE
;
271 if ( style
& wxLC_MASK_ALIGN
)
272 flag
= flag
& ~wxLC_MASK_ALIGN
;
273 if ( style
& wxLC_MASK_SORT
)
274 flag
= flag
& ~wxLC_MASK_SORT
;
282 SetWindowStyleFlag(flag
);
285 // Set the whole window style
286 void wxListCtrl::SetWindowStyleFlag(long flag
)
288 if ( flag
!= m_windowStyle
)
290 m_windowStyle
= flag
;
293 m_genericImpl
->SetWindowStyleFlag(flag
);
300 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
){
301 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
304 m_genericImpl
->SetSize(x
, y
, width
, height
, sizeFlags
);
307 // ----------------------------------------------------------------------------
309 // ----------------------------------------------------------------------------
311 // Gets information about this column
312 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
315 return m_genericImpl
->GetColumn(col
, item
);
319 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
323 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
327 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
331 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) )
339 // Sets information about this column
340 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
343 return m_genericImpl
->SetColumn(col
, item
);
348 int wxListCtrl::GetColumnCount() const
351 return m_genericImpl
->GetColumnCount();
355 m_dbImpl
->GetColumnCount(&count
);
362 // Gets the column width
363 int wxListCtrl::GetColumnWidth(int col
) const
366 return m_genericImpl
->GetColumnWidth(col
);
369 return m_dbImpl
->GetColumnWidth(col
);
375 // Sets the column width
376 bool wxListCtrl::SetColumnWidth(int col
, int width
)
379 return m_genericImpl
->SetColumnWidth(col
, width
);
381 // TODO: This is setting the width of the first column
382 // to the entire window width; investigate why
386 // m_dbImpl->SetColumnWidth(col+1, width);
393 // Gets the number of items that can fit vertically in the
394 // visible area of the list control (list or report view)
395 // or the total number of items in the list control (icon
396 // or small icon view)
397 int wxListCtrl::GetCountPerPage() const
400 return m_genericImpl
->GetCountPerPage();
408 // Gets the edit control for editing labels.
409 wxTextCtrl
* wxListCtrl::GetEditControl() const
412 return m_genericImpl
->GetEditControl();
417 // Gets information about the item
418 bool wxListCtrl::GetItem(wxListItem
& info
) const
421 return m_genericImpl
->GetItem(info
);
424 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
429 // Sets information about the item
430 bool wxListCtrl::SetItem(wxListItem
& info
)
433 return m_genericImpl
->SetItem(info
);
436 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
441 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
444 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
448 info
.m_mask
= wxLIST_MASK_TEXT
;
449 info
.m_itemId
= index
;
453 info
.m_image
= imageId
;
454 info
.m_mask
|= wxLIST_MASK_IMAGE
;
456 return SetItem(info
);
460 // Gets the item state
461 int wxListCtrl::GetItemState(long item
, long stateMask
) const
464 return m_genericImpl
->GetItemState(item
, stateMask
);
468 info
.m_mask
= wxLIST_MASK_STATE
;
469 info
.m_stateMask
= stateMask
;
470 info
.m_itemId
= item
;
478 // Sets the item state
479 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
482 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
485 info
.m_mask
= wxLIST_MASK_STATE
;
486 info
.m_stateMask
= stateMask
;
487 info
.m_state
= state
;
488 info
.m_itemId
= item
;
489 return SetItem(info
);
492 // Sets the item image
493 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
495 return SetItemColumnImage(item
, 0, image
);
498 // Sets the item image
499 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
502 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
506 info
.m_mask
= wxLIST_MASK_IMAGE
;
507 info
.m_image
= image
;
508 info
.m_itemId
= item
;
511 return SetItem(info
);
514 // Gets the item text
515 wxString
wxListCtrl::GetItemText(long item
) const
518 return m_genericImpl
->GetItemText(item
);
522 info
.m_mask
= wxLIST_MASK_TEXT
;
523 info
.m_itemId
= item
;
526 return wxEmptyString
;
530 // Sets the item text
531 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
534 return m_genericImpl
->SetItemText(item
, str
);
538 info
.m_mask
= wxLIST_MASK_TEXT
;
539 info
.m_itemId
= item
;
545 // Gets the item data
546 long wxListCtrl::GetItemData(long item
) const
549 return m_genericImpl
->GetItemData(item
);
553 info
.m_mask
= wxLIST_MASK_DATA
;
554 info
.m_itemId
= item
;
561 // Sets the item data
562 bool wxListCtrl::SetItemData(long item
, long data
)
565 return m_genericImpl
->SetItemData(item
, data
);
569 info
.m_mask
= wxLIST_MASK_DATA
;
570 info
.m_itemId
= item
;
573 return SetItem(info
);
576 wxRect
wxListCtrl::GetViewRect() const
578 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
579 _T("wxListCtrl::GetViewRect() only works in icon mode") );
582 return m_genericImpl
->GetViewRect();
588 // Gets the item rectangle
589 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
592 return m_genericImpl
->GetItemRect(item
, rect
, code
);
597 // Gets the item position
598 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
601 return m_genericImpl
->GetItemPosition(item
, pos
);
603 bool success
= false;
608 // Sets the item position.
609 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
612 return m_genericImpl
->SetItemPosition(item
, pos
);
617 // Gets the number of items in the list control
618 int wxListCtrl::GetItemCount() const
621 return m_genericImpl
->GetItemCount();
624 return m_dbImpl
->MacGetCount();
629 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
632 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
635 wxSize
wxListCtrl::GetItemSpacing() const
638 return m_genericImpl
->GetItemSpacing();
643 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
646 m_genericImpl
->SetItemTextColour(item
, col
);
650 info
.m_itemId
= item
;
651 info
.SetTextColour( col
);
655 wxColour
wxListCtrl::GetItemTextColour( long item
) const
658 return m_genericImpl
->GetItemTextColour(item
);
663 return info
.GetTextColour();
668 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
671 m_genericImpl
->SetItemBackgroundColour(item
, col
);
676 info
.m_itemId
= item
;
677 info
.SetBackgroundColour( col
);
681 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
684 return m_genericImpl
->GetItemBackgroundColour(item
);
689 return info
.GetBackgroundColour();
694 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
697 m_genericImpl
->SetItemFont(item
, f
);
702 info
.m_itemId
= item
;
707 wxFont
wxListCtrl::GetItemFont( long item
) const
710 return m_genericImpl
->GetItemFont(item
);
715 return info
.GetFont();
721 // Gets the number of selected items in the list control
722 int wxListCtrl::GetSelectedItemCount() const
725 return m_genericImpl
->GetSelectedItemCount();
728 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
733 // Gets the text colour of the listview
734 wxColour
wxListCtrl::GetTextColour() const
737 return m_genericImpl
->GetTextColour();
739 // TODO: we need owner drawn list items to customize text color.
744 // Sets the text colour of the listview
745 void wxListCtrl::SetTextColour(const wxColour
& col
)
748 m_genericImpl
->SetTextColour(col
);
752 // TODO: if we add owner-drawn item support for DataBrowser,
753 // consider supporting this property
756 // Gets the index of the topmost visible item when in
757 // list or report view
758 long wxListCtrl::GetTopItem() const
761 return m_genericImpl
->GetTopItem();
766 // Searches for an item, starting from 'item'.
767 // 'geometry' is one of
768 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
769 // 'state' is a state bit flag, one or more of
770 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
771 // item can be -1 to find the first item that matches the
773 // Returns the item or -1 if unsuccessful.
774 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
777 return m_genericImpl
->GetNextItem(item
, geom
, state
);
783 wxImageList
*wxListCtrl::GetImageList(int which
) const
786 return m_genericImpl
->GetImageList(which
);
788 if ( which
== wxIMAGE_LIST_NORMAL
)
790 return m_imageListNormal
;
792 else if ( which
== wxIMAGE_LIST_SMALL
)
794 return m_imageListSmall
;
796 else if ( which
== wxIMAGE_LIST_STATE
)
798 return m_imageListState
;
803 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
806 m_genericImpl
->SetImageList(imageList
, which
);
811 if ( which
== wxIMAGE_LIST_NORMAL
)
813 if (m_ownsImageListNormal
) delete m_imageListNormal
;
814 m_imageListNormal
= imageList
;
815 m_ownsImageListNormal
= false;
817 else if ( which
== wxIMAGE_LIST_SMALL
)
819 if (m_ownsImageListSmall
) delete m_imageListSmall
;
820 m_imageListSmall
= imageList
;
821 m_ownsImageListSmall
= false;
823 else if ( which
== wxIMAGE_LIST_STATE
)
825 if (m_ownsImageListState
) delete m_imageListState
;
826 m_imageListState
= imageList
;
827 m_ownsImageListState
= false;
831 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
834 m_genericImpl
->AssignImageList(imageList
, which
);
838 SetImageList(imageList
, which
);
839 if ( which
== wxIMAGE_LIST_NORMAL
)
840 m_ownsImageListNormal
= true;
841 else if ( which
== wxIMAGE_LIST_SMALL
)
842 m_ownsImageListSmall
= true;
843 else if ( which
== wxIMAGE_LIST_STATE
)
844 m_ownsImageListState
= true;
847 // ----------------------------------------------------------------------------
849 // ----------------------------------------------------------------------------
851 // Arranges the items
852 bool wxListCtrl::Arrange(int flag
)
855 return m_genericImpl
->Arrange(flag
);
860 bool wxListCtrl::DeleteItem(long item
)
863 return m_genericImpl
->DeleteItem(item
);
866 m_dbImpl
->MacDelete(item
);
867 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
868 event
.SetEventObject( this );
869 event
.m_itemIndex
= item
;
870 GetEventHandler()->ProcessEvent( event
);
877 bool wxListCtrl::DeleteAllItems()
880 return m_genericImpl
->DeleteAllItems();
883 m_dbImpl
->MacClear();
884 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
885 event
.SetEventObject( this );
886 GetEventHandler()->ProcessEvent( event
);
892 bool wxListCtrl::DeleteAllColumns()
895 return m_genericImpl
->DeleteAllColumns();
899 m_dbImpl
->GetColumnCount(&cols
);
900 for (UInt32 col
= 0; col
< cols
; col
++){
909 bool wxListCtrl::DeleteColumn(int col
)
912 return m_genericImpl
->DeleteColumn(col
);
915 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
922 // Clears items, and columns if there are any.
923 void wxListCtrl::ClearAll()
926 m_genericImpl
->ClearAll();
931 if ( m_colCount
> 0 )
935 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
938 return m_genericImpl
->EditLabel(item
, textControlClass
);
943 // End label editing, optionally cancelling the edit
944 bool wxListCtrl::EndEditLabel(bool cancel
)
946 // TODO: generic impl. doesn't have this method - is it needed for us?
948 return false; // m_genericImpl->EndEditLabel(cancel);
954 // Ensures this item is visible
955 bool wxListCtrl::EnsureVisible(long item
)
958 return m_genericImpl
->EnsureVisible(item
);
961 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
962 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
966 // Find an item whose label matches this string, starting from the item after 'start'
967 // or the beginning if 'start' is -1.
968 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
971 return m_genericImpl
->FindItem(start
, str
, partial
);
976 // Find an item whose data matches this data, starting from the item after 'start'
977 // or the beginning if 'start' is -1.
978 long wxListCtrl::FindItem(long start
, long data
)
981 return m_genericImpl
->FindItem(start
, data
);
983 long idx
= start
+ 1;
984 long count
= GetItemCount();
988 if (GetItemData(idx
) == data
)
996 // Find an item nearest this position in the specified direction, starting from
997 // the item after 'start' or the beginning if 'start' is -1.
998 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1001 return m_genericImpl
->FindItem(start
, pt
, direction
);
1005 // Determines which item (if any) is at the specified point,
1006 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1008 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1011 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1017 // Inserts an item, returning the index of the new item if successful,
1019 long wxListCtrl::InsertItem(wxListItem
& info
)
1021 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1024 return m_genericImpl
->InsertItem(info
);
1027 int count
= GetItemCount();
1029 if (info
.m_itemId
> count
)
1030 info
.m_itemId
= count
;
1032 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1033 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1034 event
.SetEventObject( this );
1035 event
.m_itemIndex
= info
.m_itemId
;
1036 GetEventHandler()->ProcessEvent( event
);
1039 return info
.m_itemId
;
1042 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1045 return m_genericImpl
->InsertItem(index
, label
);
1048 info
.m_text
= label
;
1049 info
.m_mask
= wxLIST_MASK_TEXT
;
1050 info
.m_itemId
= index
;
1051 return InsertItem(info
);
1054 // Inserts an image item
1055 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1058 return m_genericImpl
->InsertItem(index
, imageIndex
);
1061 info
.m_image
= imageIndex
;
1062 info
.m_mask
= wxLIST_MASK_IMAGE
;
1063 info
.m_itemId
= index
;
1064 return InsertItem(info
);
1067 // Inserts an image/string item
1068 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1071 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1074 info
.m_image
= imageIndex
;
1075 info
.m_text
= label
;
1076 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1077 info
.m_itemId
= index
;
1078 return InsertItem(info
);
1081 // For list view mode (only), inserts a column.
1082 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1085 return m_genericImpl
->InsertColumn(col
, item
);
1088 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) ) //item.GetWidth() == 0)
1090 DataBrowserPropertyType type
= kDataBrowserTextType
;
1091 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1092 if (imageList
&& imageList
->GetImageCount() > 0){
1093 wxBitmap bmp
= imageList
->GetBitmap(0);
1095 type
= kDataBrowserIconAndTextType
;
1098 fprintf(stderr
, "Flush is %d\n", item
.GetAlign());
1099 SInt16 just
= teFlushDefault
;
1100 if (item
.GetMask() & wxLIST_MASK_FORMAT
){
1101 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1103 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1105 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1106 just
= teFlushRight
;
1108 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, -1, item
.GetWidth());
1114 long wxListCtrl::InsertColumn(long col
,
1115 const wxString
& heading
,
1120 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1123 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1124 item
.m_text
= heading
;
1127 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1128 item
.m_width
= width
;
1130 item
.m_format
= format
;
1132 return InsertColumn(col
, item
);
1135 // scroll the control by the given number of pixels (exception: in list view,
1136 // dx is interpreted as number of columns)
1137 bool wxListCtrl::ScrollList(int dx
, int dy
)
1140 return m_genericImpl
->ScrollList(dx
, dy
);
1143 m_dbImpl
->SetScrollPosition(dx
, dy
);
1149 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1152 return m_genericImpl
->SortItems(fn
, data
);
1157 // ----------------------------------------------------------------------------
1158 // virtual list controls
1159 // ----------------------------------------------------------------------------
1161 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1163 // this is a pure virtual function, in fact - which is not really pure
1164 // because the controls which are not virtual don't need to implement it
1165 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1167 return wxEmptyString
;
1170 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1172 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1174 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1178 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1181 return OnGetItemImage(item
);
1186 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1188 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1189 _T("invalid item index in OnGetItemAttr()") );
1191 // no attributes by default
1195 void wxListCtrl::SetItemCount(long count
)
1197 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1200 m_genericImpl
->SetItemCount(count
);
1207 void wxListCtrl::RefreshItem(long item
)
1210 m_genericImpl
->RefreshItem(item
);
1215 GetItemRect(item
, rect
);
1219 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1222 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1226 wxRect rect1
, rect2
;
1227 GetItemRect(itemFrom
, rect1
);
1228 GetItemRect(itemTo
, rect2
);
1230 wxRect rect
= rect1
;
1231 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
1237 // wxMac internal data structures
1239 wxMacListCtrlItem::~wxMacListCtrlItem()
1243 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
1244 DataBrowserItemNotification message
,
1245 DataBrowserItemDataRef itemData
) const
1248 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
1250 // we want to depend on as little as possible to make sure tear-down of controls is safe
1251 if ( message
== kDataBrowserItemRemoved
)
1253 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
1255 delete (wxClientData
*) (m_data
);
1262 // CS : couldn't reproduce this problem, what are the steps to test ?
1263 // 1) wxDynamicCast fails during shutdown. This doesn't suprise me, but
1264 // you have similar listbox code, so I'm wondering why this case is different.
1266 // CS: these two should be fixed now
1267 // 2) owner->GetLineFromItem( this ) always asserts.
1268 // 3) the !lb->IsSelectionSuppressed code also fails with EXC_BAD_ACCESS
1270 // during shutdown, this may fail.
1271 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1273 bool trigger
= false;
1275 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1276 bool isSingle
= list
->GetWindowStyle() | wxLC_SINGLE_SEL
;
1279 case kDataBrowserItemDeselected
:
1280 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1282 trigger
= !lb
->IsSelectionSuppressed();
1285 case kDataBrowserItemSelected
:
1286 trigger
= !lb
->IsSelectionSuppressed();
1289 case kDataBrowserItemDoubleClicked
:
1290 event
.SetEventType( wxEVT_LEFT_DCLICK
);
1300 event
.SetEventObject( list
);
1301 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
1302 if ( !list
->IsVirtual() )
1304 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1306 // direct notification is not always having the listbox GetSelection() having in synch with event
1307 wxPostEvent( list
->GetEventHandler(), event
);
1313 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
1314 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
1316 OSStatus err
= noErr
;
1317 m_clientDataItemsType
= wxClientData_None
;
1319 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
1320 if ( style
& wxLC_SINGLE_SEL
)
1322 options
|= kDataBrowserSelectOnlyOne
;
1326 options
|= kDataBrowserAlwaysExtendSelection
| kDataBrowserCmdTogglesSelection
;
1329 err
= SetSelectionFlags( options
);
1330 verify_noerr( err
);
1332 // create the numeric order column
1333 DataBrowserListViewColumnDesc columnDesc
;
1334 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1335 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1337 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1338 kControlUseFontMask
| kControlUseJustMask
;
1340 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
1341 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
1342 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1343 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1344 columnDesc
.headerBtnDesc
.titleString
= NULL
;
1346 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1347 columnDesc
.headerBtnDesc
.maximumWidth
= 0;
1348 columnDesc
.propertyDesc
.propertyID
= kNumericOrderColumnId
;
1349 columnDesc
.propertyDesc
.propertyType
= kDataBrowserPropertyRelevanceRankPart
;
1350 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserTableViewSelectionColumn
;
1351 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1352 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1355 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1357 if ( style
& wxLC_LIST
){
1358 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
1359 verify_noerr( AutoSizeColumns() );
1360 verify_noerr( SetHeaderButtonHeight( 0 ) );
1363 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1364 if ( style
& wxLC_SORT_ASCENDING
)
1366 m_sortOrder
= SortOrder_Text_Ascending
;
1367 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1368 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
1370 else if ( style
& wxLC_SORT_DESCENDING
)
1372 m_sortOrder
= SortOrder_Text_Descending
;
1373 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1374 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderDecreasing
);
1378 m_sortOrder
= SortOrder_None
;
1379 SetDataBrowserSortProperty( m_controlRef
, kNumericOrderColumnId
);
1380 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
1383 verify_noerr( AutoSizeColumns() );
1384 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
1385 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
1388 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
1392 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
1394 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1396 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1397 listItem
->SetColumnInfo( column
, item
);
1398 UpdateState(dataItem
, item
);
1402 // apply changes that need to happen immediately, rather than when the
1403 // databrowser control fires a callback.
1404 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
1406 bool isSelected
= IsItemSelected( dataItem
);
1407 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
1409 // toggle the selection state if wxListInfo state and actual state don't match.
1410 if ( isSelected
!= isSelectedState
){
1411 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
1412 if (!isSelectedState
)
1413 options
= kDataBrowserItemsRemove
;
1414 fprintf(stderr
, "state = %d, db options = %d\n", isSelectedState
, options
);
1415 SetSelectedItem(dataItem
, options
);
1417 // TODO: Set column width if item width > than current column width
1420 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
1422 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1423 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
1426 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1427 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
1429 long mask
= item
.GetMask();
1431 // by default, get everything for backwards compatibility
1434 if ( mask
& wxLIST_MASK_TEXT
)
1435 item
.SetText(oldItem
->GetText());
1436 if ( mask
& wxLIST_MASK_IMAGE
)
1437 item
.SetImage(oldItem
->GetImage());
1438 if ( mask
& wxLIST_MASK_DATA
)
1439 item
.SetData(oldItem
->GetData());
1440 if ( mask
& wxLIST_MASK_STATE
)
1441 item
.SetState(oldItem
->GetState());
1442 if ( mask
& wxLIST_MASK_WIDTH
)
1443 item
.SetWidth(oldItem
->GetWidth());
1444 if ( mask
& wxLIST_MASK_FORMAT
)
1445 item
.SetAlign(oldItem
->GetAlign());
1447 item
.SetTextColour(oldItem
->GetTextColour());
1448 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
1449 item
.SetFont(oldItem
->GetFont());
1453 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
1455 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
1456 MacSetColumnInfo(n
, 0, item
);
1459 wxMacListCtrlItem
* wxMacDataBrowserListCtrlControl::CreateItem()
1461 return new wxMacListCtrlItem();
1464 wxMacListCtrlItem::wxMacListCtrlItem()
1466 m_rowItems
= wxListItemList();
1469 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
1471 return GetColumnInfo(column
)->GetImage();
1474 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
1476 GetColumnInfo(column
)->SetImage(imageIndex
);
1479 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
1484 return GetColumnInfo(column
)->GetText();
1487 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
1489 GetColumnInfo(column
)->SetText(text
);
1491 // for compatibility with superclass APIs
1496 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
1498 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
1499 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
1501 return node
->GetData();
1504 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
1506 return m_rowItems
.GetCount() > column
;
1509 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
1512 if ( column
>= m_rowItems
.GetCount() ){
1513 wxListItem
* listItem
= new wxListItem(*item
);
1514 //listItem->SetAlign(item->GetAlign());
1515 //listItem->SetBackgroundColour(item->GetBackgroundColour());
1516 //listItem->SetColumn(item->GetColumn());
1517 //listItem->SetData(item->GetData());
1518 //listItem->SetFont(item->GetFont());
1519 //listItem->SetId(GetOrder());
1520 //listItem->SetImage(item->GetImage());
1521 //listItem->SetMask(item->GetMask());
1523 //listItem->SetText(item->GetText());
1524 m_rowItems
.Append( listItem
);
1527 wxListItem
* listItem
= GetColumnInfo( column
);
1528 long mask
= item
->GetMask();
1529 if (mask
& wxLIST_MASK_TEXT
)
1530 listItem
->SetText(item
->GetText());
1531 if (mask
& wxLIST_MASK_DATA
)
1532 listItem
->SetData(item
->GetData());
1533 if (mask
& wxLIST_MASK_IMAGE
)
1534 listItem
->SetImage(item
->GetImage());
1535 if (mask
& wxLIST_MASK_STATE
)
1536 listItem
->SetState(item
->GetState());
1537 if (mask
& wxLIST_MASK_FORMAT
)
1538 listItem
->SetAlign(item
->GetAlign());
1539 if (mask
& wxLIST_MASK_WIDTH
)
1540 listItem
->SetWidth(item
->GetWidth());
1544 OSStatus
wxMacListCtrlItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1545 DataBrowserPropertyID property
,
1546 DataBrowserItemDataRef itemData
,
1549 OSStatus err
= errDataBrowserPropertyNotSupported
;
1552 if ( property
>= kMinColumnId
){
1553 short listColumn
= property
- kMinColumnId
;
1555 if (HasColumnInfo(listColumn
)){
1556 wxListItem
* item
= GetColumnInfo(listColumn
);
1557 wxMacCFStringHolder cfStr
;
1559 if (item
->GetText()){
1560 cfStr
.Assign( item
->GetText(), wxLocale::GetSystemEncoding() );
1561 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
1565 int imgIndex
= item
->GetImage();
1566 if ( (item
->GetMask() & wxLIST_MASK_IMAGE
) ){
1567 wxListCtrl
* list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1568 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
1569 if (imageList
&& imageList
->GetImageCount() > 0){
1570 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
1571 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
1572 ::SetDataBrowserItemDataIcon(itemData
, icon
);
1583 // no editable props here
1589 // don't duplicate the numeric order column handling
1590 if (err
== errDataBrowserPropertyNotSupported
)
1591 err
= wxMacDataItem::GetSetData(owner
, property
, itemData
, changeValue
);
1596 #endif // wxUSE_LISTCTRL