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 class wxGenericListCtrlHook
: public wxGenericListCtrl
211 wxGenericListCtrlHook(wxListCtrl
* parent
,
216 const wxValidator
& validator
,
217 const wxString
& name
)
218 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
219 m_nativeListCtrl(parent
)
223 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
225 return m_nativeListCtrl
->OnGetItemAttr(item
);
228 virtual int OnGetItemImage(long item
) const
230 return m_nativeListCtrl
->OnGetItemImage(item
);
233 virtual int OnGetItemColumnImage(long item
, long column
) const
235 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
238 virtual wxString
OnGetItemText(long item
, long column
) const
240 return m_nativeListCtrl
->OnGetItemText(item
, column
);
244 wxListCtrl
* m_nativeListCtrl
;
248 bool wxListCtrl::Create(wxWindow
*parent
,
253 const wxValidator
& validator
,
254 const wxString
& name
)
257 // for now, we'll always use the generic list control for ICON and LIST views,
258 // because they dynamically change the number of columns on resize.
259 // Also, allow the user to set it to use the list ctrl as well.
260 // Also, use generic list control in VIRTUAL mode.
261 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
262 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
263 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) || (style
& wxLC_VIRTUAL
))
265 m_macIsUserPane
= true;
267 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
269 m_genericImpl
= new wxGenericListCtrlHook(this, id
, pos
, size
, style
, validator
, name
);
275 m_macIsUserPane
= false;
277 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
279 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
282 MacPostControlCreate( pos
, size
);
288 wxListCtrl::~wxListCtrl()
290 if (m_ownsImageListNormal
)
291 delete m_imageListNormal
;
292 if (m_ownsImageListSmall
)
293 delete m_imageListSmall
;
294 if (m_ownsImageListState
)
295 delete m_imageListState
;
298 // ----------------------------------------------------------------------------
299 // set/get/change style
300 // ----------------------------------------------------------------------------
302 // Add or remove a single window style
303 void wxListCtrl::SetSingleStyle(long style
, bool add
)
305 long flag
= GetWindowStyleFlag();
307 // Get rid of conflicting styles
310 if ( style
& wxLC_MASK_TYPE
)
311 flag
= flag
& ~wxLC_MASK_TYPE
;
312 if ( style
& wxLC_MASK_ALIGN
)
313 flag
= flag
& ~wxLC_MASK_ALIGN
;
314 if ( style
& wxLC_MASK_SORT
)
315 flag
= flag
& ~wxLC_MASK_SORT
;
323 SetWindowStyleFlag(flag
);
326 // Set the whole window style
327 void wxListCtrl::SetWindowStyleFlag(long flag
)
329 if ( flag
!= m_windowStyle
)
331 m_windowStyle
= flag
;
335 m_genericImpl
->SetWindowStyleFlag(flag
);
342 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
344 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
347 m_genericImpl
->SetSize(x
, y
, width
, height
, sizeFlags
);
350 // ----------------------------------------------------------------------------
352 // ----------------------------------------------------------------------------
354 // Gets information about this column
355 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
358 return m_genericImpl
->GetColumn(col
, item
);
362 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
366 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
370 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
374 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) )
382 // Sets information about this column
383 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
386 return m_genericImpl
->SetColumn(col
, item
);
391 int wxListCtrl::GetColumnCount() const
394 return m_genericImpl
->GetColumnCount();
399 m_dbImpl
->GetColumnCount(&count
);
406 // Gets the column width
407 int wxListCtrl::GetColumnWidth(int col
) const
410 return m_genericImpl
->GetColumnWidth(col
);
414 return m_dbImpl
->GetColumnWidth(col
);
420 // Sets the column width
421 bool wxListCtrl::SetColumnWidth(int col
, int width
)
424 return m_genericImpl
->SetColumnWidth(col
, width
);
426 // TODO: This is setting the width of the first column
427 // to the entire window width; investigate why
433 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
438 for (int column
= 0; column
< GetColumnCount(); column
++)
440 m_dbImpl
->SetColumnWidth(col
, mywidth
);
444 m_dbImpl
->SetColumnWidth(col
, mywidth
);
452 // Gets the number of items that can fit vertically in the
453 // visible area of the list control (list or report view)
454 // or the total number of items in the list control (icon
455 // or small icon view)
456 int wxListCtrl::GetCountPerPage() const
459 return m_genericImpl
->GetCountPerPage();
468 // Gets the edit control for editing labels.
469 wxTextCtrl
* wxListCtrl::GetEditControl() const
472 return m_genericImpl
->GetEditControl();
477 // Gets information about the item
478 bool wxListCtrl::GetItem(wxListItem
& info
) const
481 return m_genericImpl
->GetItem(info
);
484 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
489 // Sets information about the item
490 bool wxListCtrl::SetItem(wxListItem
& info
)
493 return m_genericImpl
->SetItem(info
);
496 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
501 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
504 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
508 info
.m_mask
= wxLIST_MASK_TEXT
;
509 info
.m_itemId
= index
;
513 info
.m_image
= imageId
;
514 info
.m_mask
|= wxLIST_MASK_IMAGE
;
516 return SetItem(info
);
520 // Gets the item state
521 int wxListCtrl::GetItemState(long item
, long stateMask
) const
524 return m_genericImpl
->GetItemState(item
, stateMask
);
528 info
.m_mask
= wxLIST_MASK_STATE
;
529 info
.m_stateMask
= stateMask
;
530 info
.m_itemId
= item
;
538 // Sets the item state
539 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
542 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
545 info
.m_mask
= wxLIST_MASK_STATE
;
546 info
.m_stateMask
= stateMask
;
547 info
.m_state
= state
;
548 info
.m_itemId
= item
;
549 return SetItem(info
);
552 // Sets the item image
553 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
555 return SetItemColumnImage(item
, 0, image
);
558 // Sets the item image
559 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
562 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
566 info
.m_mask
= wxLIST_MASK_IMAGE
;
567 info
.m_image
= image
;
568 info
.m_itemId
= item
;
571 return SetItem(info
);
574 // Gets the item text
575 wxString
wxListCtrl::GetItemText(long item
) const
578 return m_genericImpl
->GetItemText(item
);
582 info
.m_mask
= wxLIST_MASK_TEXT
;
583 info
.m_itemId
= item
;
586 return wxEmptyString
;
590 // Sets the item text
591 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
594 return m_genericImpl
->SetItemText(item
, str
);
598 info
.m_mask
= wxLIST_MASK_TEXT
;
599 info
.m_itemId
= item
;
605 // Gets the item data
606 long wxListCtrl::GetItemData(long item
) const
609 return m_genericImpl
->GetItemData(item
);
613 info
.m_mask
= wxLIST_MASK_DATA
;
614 info
.m_itemId
= item
;
621 // Sets the item data
622 bool wxListCtrl::SetItemData(long item
, long data
)
625 return m_genericImpl
->SetItemData(item
, data
);
629 info
.m_mask
= wxLIST_MASK_DATA
;
630 info
.m_itemId
= item
;
633 return SetItem(info
);
636 wxRect
wxListCtrl::GetViewRect() const
638 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
639 _T("wxListCtrl::GetViewRect() only works in icon mode") );
642 return m_genericImpl
->GetViewRect();
648 // Gets the item rectangle
649 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
652 return m_genericImpl
->GetItemRect(item
, rect
, code
);
657 // Gets the item position
658 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
661 return m_genericImpl
->GetItemPosition(item
, pos
);
663 bool success
= false;
668 // Sets the item position.
669 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
672 return m_genericImpl
->SetItemPosition(item
, pos
);
677 // Gets the number of items in the list control
678 int wxListCtrl::GetItemCount() const
681 return m_genericImpl
->GetItemCount();
684 return m_dbImpl
->MacGetCount();
689 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
692 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
695 wxSize
wxListCtrl::GetItemSpacing() const
698 return m_genericImpl
->GetItemSpacing();
703 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
707 m_genericImpl
->SetItemTextColour(item
, col
);
711 info
.m_itemId
= item
;
712 info
.SetTextColour( col
);
716 wxColour
wxListCtrl::GetItemTextColour( long item
) const
719 return m_genericImpl
->GetItemTextColour(item
);
725 return info
.GetTextColour();
730 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
734 m_genericImpl
->SetItemBackgroundColour(item
, col
);
739 info
.m_itemId
= item
;
740 info
.SetBackgroundColour( col
);
744 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
747 return m_genericImpl
->GetItemBackgroundColour(item
);
753 return info
.GetBackgroundColour();
758 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
762 m_genericImpl
->SetItemFont(item
, f
);
767 info
.m_itemId
= item
;
772 wxFont
wxListCtrl::GetItemFont( long item
) const
775 return m_genericImpl
->GetItemFont(item
);
781 return info
.GetFont();
787 // Gets the number of selected items in the list control
788 int wxListCtrl::GetSelectedItemCount() const
791 return m_genericImpl
->GetSelectedItemCount();
794 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
799 // Gets the text colour of the listview
800 wxColour
wxListCtrl::GetTextColour() const
803 return m_genericImpl
->GetTextColour();
805 // TODO: we need owner drawn list items to customize text color.
812 // Sets the text colour of the listview
813 void wxListCtrl::SetTextColour(const wxColour
& col
)
817 m_genericImpl
->SetTextColour(col
);
821 // TODO: if we add owner-drawn item support for DataBrowser,
822 // consider supporting this property
825 // Gets the index of the topmost visible item when in
826 // list or report view
827 long wxListCtrl::GetTopItem() const
830 return m_genericImpl
->GetTopItem();
835 // Searches for an item, starting from 'item'.
836 // 'geometry' is one of
837 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
838 // 'state' is a state bit flag, one or more of
839 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
840 // item can be -1 to find the first item that matches the
842 // Returns the item or -1 if unsuccessful.
843 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
846 return m_genericImpl
->GetNextItem(item
, geom
, state
);
852 wxImageList
*wxListCtrl::GetImageList(int which
) const
855 return m_genericImpl
->GetImageList(which
);
857 if ( which
== wxIMAGE_LIST_NORMAL
)
859 return m_imageListNormal
;
861 else if ( which
== wxIMAGE_LIST_SMALL
)
863 return m_imageListSmall
;
865 else if ( which
== wxIMAGE_LIST_STATE
)
867 return m_imageListState
;
872 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
876 m_genericImpl
->SetImageList(imageList
, which
);
880 if ( which
== wxIMAGE_LIST_NORMAL
)
882 if (m_ownsImageListNormal
) delete m_imageListNormal
;
883 m_imageListNormal
= imageList
;
884 m_ownsImageListNormal
= false;
886 else if ( which
== wxIMAGE_LIST_SMALL
)
888 if (m_ownsImageListSmall
) delete m_imageListSmall
;
889 m_imageListSmall
= imageList
;
890 m_ownsImageListSmall
= false;
892 else if ( which
== wxIMAGE_LIST_STATE
)
894 if (m_ownsImageListState
) delete m_imageListState
;
895 m_imageListState
= imageList
;
896 m_ownsImageListState
= false;
900 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
904 m_genericImpl
->AssignImageList(imageList
, which
);
908 SetImageList(imageList
, which
);
909 if ( which
== wxIMAGE_LIST_NORMAL
)
910 m_ownsImageListNormal
= true;
911 else if ( which
== wxIMAGE_LIST_SMALL
)
912 m_ownsImageListSmall
= true;
913 else if ( which
== wxIMAGE_LIST_STATE
)
914 m_ownsImageListState
= true;
917 // ----------------------------------------------------------------------------
919 // ----------------------------------------------------------------------------
921 // Arranges the items
922 bool wxListCtrl::Arrange(int flag
)
925 return m_genericImpl
->Arrange(flag
);
930 bool wxListCtrl::DeleteItem(long item
)
933 return m_genericImpl
->DeleteItem(item
);
937 m_dbImpl
->MacDelete(item
);
938 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
939 event
.SetEventObject( this );
940 event
.m_itemIndex
= item
;
941 GetEventHandler()->ProcessEvent( event
);
948 bool wxListCtrl::DeleteAllItems()
951 return m_genericImpl
->DeleteAllItems();
955 m_dbImpl
->MacClear();
956 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
957 event
.SetEventObject( this );
958 GetEventHandler()->ProcessEvent( event
);
964 bool wxListCtrl::DeleteAllColumns()
967 return m_genericImpl
->DeleteAllColumns();
972 m_dbImpl
->GetColumnCount(&cols
);
973 for (UInt32 col
= 0; col
< cols
; col
++)
983 bool wxListCtrl::DeleteColumn(int col
)
986 return m_genericImpl
->DeleteColumn(col
);
990 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
997 // Clears items, and columns if there are any.
998 void wxListCtrl::ClearAll()
1002 m_genericImpl
->ClearAll();
1013 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1016 return m_genericImpl
->EditLabel(item
, textControlClass
);
1020 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(item
);
1021 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)id
, kMinColumnId
) );
1026 // End label editing, optionally cancelling the edit
1027 bool wxListCtrl::EndEditLabel(bool cancel
)
1029 // TODO: generic impl. doesn't have this method - is it needed for us?
1031 return true; // m_genericImpl->EndEditLabel(cancel);
1034 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1038 // Ensures this item is visible
1039 bool wxListCtrl::EnsureVisible(long item
)
1042 return m_genericImpl
->EnsureVisible(item
);
1046 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1047 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1053 // Find an item whose label matches this string, starting from the item after 'start'
1054 // or the beginning if 'start' is -1.
1055 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1058 return m_genericImpl
->FindItem(start
, str
, partial
);
1063 // Find an item whose data matches this data, starting from the item after 'start'
1064 // or the beginning if 'start' is -1.
1065 long wxListCtrl::FindItem(long start
, long data
)
1068 return m_genericImpl
->FindItem(start
, data
);
1070 long idx
= start
+ 1;
1071 long count
= GetItemCount();
1075 if (GetItemData(idx
) == data
)
1083 // Find an item nearest this position in the specified direction, starting from
1084 // the item after 'start' or the beginning if 'start' is -1.
1085 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1088 return m_genericImpl
->FindItem(start
, pt
, direction
);
1092 // Determines which item (if any) is at the specified point,
1093 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1095 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1098 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1104 // Inserts an item, returning the index of the new item if successful,
1106 long wxListCtrl::InsertItem(wxListItem
& info
)
1108 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1111 return m_genericImpl
->InsertItem(info
);
1115 int count
= GetItemCount();
1117 if (info
.m_itemId
> count
)
1118 info
.m_itemId
= count
;
1120 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1121 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1122 event
.SetEventObject( this );
1123 event
.m_itemIndex
= info
.m_itemId
;
1124 GetEventHandler()->ProcessEvent( event
);
1127 return info
.m_itemId
;
1130 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1133 return m_genericImpl
->InsertItem(index
, label
);
1136 info
.m_text
= label
;
1137 info
.m_mask
= wxLIST_MASK_TEXT
;
1138 info
.m_itemId
= index
;
1139 return InsertItem(info
);
1142 // Inserts an image item
1143 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1146 return m_genericImpl
->InsertItem(index
, imageIndex
);
1149 info
.m_image
= imageIndex
;
1150 info
.m_mask
= wxLIST_MASK_IMAGE
;
1151 info
.m_itemId
= index
;
1152 return InsertItem(info
);
1155 // Inserts an image/string item
1156 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1159 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1162 info
.m_image
= imageIndex
;
1163 info
.m_text
= label
;
1164 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1165 info
.m_itemId
= index
;
1166 return InsertItem(info
);
1169 // For list view mode (only), inserts a column.
1170 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1173 return m_genericImpl
->InsertColumn(col
, item
);
1177 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1180 DataBrowserPropertyType type
= kDataBrowserTextType
;
1181 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1182 if (imageList
&& imageList
->GetImageCount() > 0)
1184 wxBitmap bmp
= imageList
->GetBitmap(0);
1186 type
= kDataBrowserIconAndTextType
;
1189 fprintf(stderr
, "Flush is %d\n", item
.GetAlign());
1190 SInt16 just
= teFlushDefault
;
1191 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1193 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1195 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1197 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1198 just
= teFlushRight
;
1200 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, item
.GetWidth());
1202 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1204 DataBrowserTableViewColumnID id
;
1205 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1206 DataBrowserPropertyFlags flags
;
1207 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1208 flags
|= kDataBrowserPropertyIsEditable
;
1209 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1216 long wxListCtrl::InsertColumn(long col
,
1217 const wxString
& heading
,
1222 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1225 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1226 item
.m_text
= heading
;
1229 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1230 item
.m_width
= width
;
1232 item
.m_format
= format
;
1234 return InsertColumn(col
, item
);
1237 // scroll the control by the given number of pixels (exception: in list view,
1238 // dx is interpreted as number of columns)
1239 bool wxListCtrl::ScrollList(int dx
, int dy
)
1242 return m_genericImpl
->ScrollList(dx
, dy
);
1246 m_dbImpl
->SetScrollPosition(dx
, dy
);
1252 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1255 return m_genericImpl
->SortItems(fn
, data
);
1260 // ----------------------------------------------------------------------------
1261 // virtual list controls
1262 // ----------------------------------------------------------------------------
1264 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1266 // this is a pure virtual function, in fact - which is not really pure
1267 // because the controls which are not virtual don't need to implement it
1268 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1270 return wxEmptyString
;
1273 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1275 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1277 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1281 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1284 return OnGetItemImage(item
);
1289 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1291 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1292 _T("invalid item index in OnGetItemAttr()") );
1294 // no attributes by default
1298 void wxListCtrl::SetItemCount(long count
)
1300 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1304 m_genericImpl
->SetItemCount(count
);
1311 void wxListCtrl::RefreshItem(long item
)
1315 m_genericImpl
->RefreshItem(item
);
1320 GetItemRect(item
, rect
);
1324 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1328 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1332 wxRect rect1
, rect2
;
1333 GetItemRect(itemFrom
, rect1
);
1334 GetItemRect(itemTo
, rect2
);
1336 wxRect rect
= rect1
;
1337 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
1343 // wxMac internal data structures
1345 wxMacListCtrlItem::~wxMacListCtrlItem()
1349 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
1350 DataBrowserItemNotification message
,
1351 DataBrowserItemDataRef itemData
) const
1354 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
1356 // we want to depend on as little as possible to make sure tear-down of controls is safe
1357 if ( message
== kDataBrowserItemRemoved
)
1359 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
1361 delete (wxClientData
*) (m_data
);
1367 else if ( message
== kDataBrowserItemAdded
)
1369 // we don't issue events on adding, the item is not really stored in the list yet, so we
1370 // avoid asserts by gettting out now
1374 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1377 bool trigger
= false;
1379 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1380 bool isSingle
= list
->GetWindowStyle() | wxLC_SINGLE_SEL
;
1382 event
.SetEventObject( list
);
1383 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
1384 if ( !list
->IsVirtual() )
1386 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1391 case kDataBrowserItemDeselected
:
1392 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1394 trigger
= !lb
->IsSelectionSuppressed();
1397 case kDataBrowserItemSelected
:
1398 trigger
= !lb
->IsSelectionSuppressed();
1401 case kDataBrowserItemDoubleClicked
:
1402 event
.SetEventType( wxEVT_LEFT_DCLICK
);
1406 case kDataBrowserEditStarted
:
1407 // TODO : how to veto ?
1408 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
1412 case kDataBrowserEditStopped
:
1413 // TODO probably trigger only upon the value store callback, because
1414 // here IIRC we cannot veto
1415 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
1425 // direct notification is not always having the listbox GetSelection() having in synch with event
1426 wxPostEvent( list
->GetEventHandler(), event
);
1432 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
1433 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
1435 OSStatus err
= noErr
;
1436 m_clientDataItemsType
= wxClientData_None
;
1438 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
1439 if ( style
& wxLC_SINGLE_SEL
)
1441 options
|= kDataBrowserSelectOnlyOne
;
1445 options
|= kDataBrowserCmdTogglesSelection
;
1448 err
= SetSelectionFlags( options
);
1449 verify_noerr( err
);
1451 if ( style
& wxLC_LIST
)
1453 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
1454 verify_noerr( AutoSizeColumns() );
1457 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
1458 verify_noerr( SetHeaderButtonHeight( 0 ) );
1460 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1461 if ( style
& wxLC_SORT_ASCENDING
)
1463 m_sortOrder
= SortOrder_Text_Ascending
;
1464 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1465 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
1467 else if ( style
& wxLC_SORT_DESCENDING
)
1469 m_sortOrder
= SortOrder_Text_Descending
;
1470 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1471 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderDecreasing
);
1475 m_sortOrder
= SortOrder_None
;
1476 SetDataBrowserSortProperty( m_controlRef
, kMinColumnId
);
1477 SetDataBrowserSortOrder( m_controlRef
, kDataBrowserOrderIncreasing
);
1480 if ( style
& wxLC_VRULES
)
1482 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1483 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
1487 verify_noerr( AutoSizeColumns() );
1488 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
1489 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
1492 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
1496 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
1498 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1501 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1502 listItem
->SetColumnInfo( column
, item
);
1503 UpdateState(dataItem
, item
);
1507 // apply changes that need to happen immediately, rather than when the
1508 // databrowser control fires a callback.
1509 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
1511 bool isSelected
= IsItemSelected( dataItem
);
1512 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
1514 // toggle the selection state if wxListInfo state and actual state don't match.
1515 if ( isSelected
!= isSelectedState
)
1517 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
1518 if (!isSelectedState
)
1519 options
= kDataBrowserItemsRemove
;
1520 SetSelectedItem(dataItem
, options
);
1522 // TODO: Set column width if item width > than current column width
1525 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
1527 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1528 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
1531 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1532 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
1534 long mask
= item
.GetMask();
1536 // by default, get everything for backwards compatibility
1539 if ( mask
& wxLIST_MASK_TEXT
)
1540 item
.SetText(oldItem
->GetText());
1541 if ( mask
& wxLIST_MASK_IMAGE
)
1542 item
.SetImage(oldItem
->GetImage());
1543 if ( mask
& wxLIST_MASK_DATA
)
1544 item
.SetData(oldItem
->GetData());
1545 if ( mask
& wxLIST_MASK_STATE
)
1546 item
.SetState(oldItem
->GetState());
1547 if ( mask
& wxLIST_MASK_WIDTH
)
1548 item
.SetWidth(oldItem
->GetWidth());
1549 if ( mask
& wxLIST_MASK_FORMAT
)
1550 item
.SetAlign(oldItem
->GetAlign());
1552 item
.SetTextColour(oldItem
->GetTextColour());
1553 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
1554 item
.SetFont(oldItem
->GetFont());
1558 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
1560 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
1561 MacSetColumnInfo(n
, 0, item
);
1564 wxMacListCtrlItem
* wxMacDataBrowserListCtrlControl::CreateItem()
1566 return new wxMacListCtrlItem();
1569 wxMacListCtrlItem::wxMacListCtrlItem()
1571 m_rowItems
= wxListItemList();
1574 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
1576 return GetColumnInfo(column
)->GetImage();
1579 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
1581 GetColumnInfo(column
)->SetImage(imageIndex
);
1584 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
1589 return GetColumnInfo(column
)->GetText();
1592 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
1594 GetColumnInfo(column
)->SetText(text
);
1596 // for compatibility with superclass APIs
1601 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
1603 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
1604 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
1606 return node
->GetData();
1609 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
1611 return m_rowItems
.GetCount() > column
;
1614 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
1617 if ( column
>= m_rowItems
.GetCount() )
1619 wxListItem
* listItem
= new wxListItem(*item
);
1620 //listItem->SetAlign(item->GetAlign());
1621 //listItem->SetBackgroundColour(item->GetBackgroundColour());
1622 //listItem->SetColumn(item->GetColumn());
1623 //listItem->SetData(item->GetData());
1624 //listItem->SetFont(item->GetFont());
1625 //listItem->SetId(GetOrder());
1626 //listItem->SetImage(item->GetImage());
1627 //listItem->SetMask(item->GetMask());
1629 //listItem->SetText(item->GetText());
1630 m_rowItems
.Append( listItem
);
1633 wxListItem
* listItem
= GetColumnInfo( column
);
1634 long mask
= item
->GetMask();
1635 if (mask
& wxLIST_MASK_TEXT
)
1636 listItem
->SetText(item
->GetText());
1637 if (mask
& wxLIST_MASK_DATA
)
1638 listItem
->SetData(item
->GetData());
1639 if (mask
& wxLIST_MASK_IMAGE
)
1640 listItem
->SetImage(item
->GetImage());
1641 if (mask
& wxLIST_MASK_STATE
)
1642 listItem
->SetState(item
->GetState());
1643 if (mask
& wxLIST_MASK_FORMAT
)
1644 listItem
->SetAlign(item
->GetAlign());
1645 if (mask
& wxLIST_MASK_WIDTH
)
1646 listItem
->SetWidth(item
->GetWidth());
1650 OSStatus
wxMacListCtrlItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1651 DataBrowserPropertyID property
,
1652 DataBrowserItemDataRef itemData
,
1656 OSStatus err
= errDataBrowserPropertyNotSupported
;
1657 wxListCtrl
* list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1662 case kDataBrowserItemIsEditableProperty
:
1663 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
1665 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
1670 if ( property
>= kMinColumnId
)
1672 short listColumn
= property
- kMinColumnId
;
1674 if (HasColumnInfo(listColumn
))
1676 wxListItem
* item
= GetColumnInfo(listColumn
);
1677 wxMacCFStringHolder cfStr
;
1679 if (item
->GetText())
1681 cfStr
.Assign( item
->GetText(), wxLocale::GetSystemEncoding() );
1682 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
1686 int imgIndex
= item
->GetImage();
1687 if ( (item
->GetMask() & wxLIST_MASK_IMAGE
) )
1689 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
1690 if (imageList
&& imageList
->GetImageCount() > 0)
1692 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
1693 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
1694 ::SetDataBrowserItemDataIcon(itemData
, icon
);
1708 if ( property
>= kMinColumnId
)
1710 short listColumn
= property
- kMinColumnId
;
1712 if (HasColumnInfo(listColumn
))
1714 // TODO probably send the 'end edit' from here, as we
1715 // can then deal with the veto
1717 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
1718 wxMacCFStringHolder
cfStr(sr
) ;;
1719 list
->SetItem( owner
->GetLineFromItem(this) , listColumn
, cfStr
.AsString() ) ;
1727 // don't duplicate the numeric order column handling
1728 if (err
== errDataBrowserPropertyNotSupported
)
1729 err
= wxMacDataItem::GetSetData(owner
, property
, itemData
, changeValue
);
1734 #endif // wxUSE_LISTCTRL