1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/listctrl_mac.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"
29 #include "wx/listctrl.h"
35 #include "wx/mac/uma.h"
37 #include "wx/imaglist.h"
38 #include "wx/sysopt.h"
40 #define wxMAC_ALWAYS_USE_GENERIC_LISTCTRL wxT("mac.listctrl.always_use_generic")
42 #if wxUSE_EXTENDED_RTTI
43 WX_DEFINE_FLAGS( wxListCtrlStyle
)
45 wxBEGIN_FLAGS( wxListCtrlStyle
)
46 // new style border flags, we put them first to
47 // use them for streaming out
48 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
49 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
50 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
51 wxFLAGS_MEMBER(wxBORDER_RAISED
)
52 wxFLAGS_MEMBER(wxBORDER_STATIC
)
53 wxFLAGS_MEMBER(wxBORDER_NONE
)
55 // old style border flags
56 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
57 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
58 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
59 wxFLAGS_MEMBER(wxRAISED_BORDER
)
60 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
61 wxFLAGS_MEMBER(wxBORDER
)
63 // standard window styles
64 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
65 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
66 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
67 wxFLAGS_MEMBER(wxWANTS_CHARS
)
68 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
69 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
70 wxFLAGS_MEMBER(wxVSCROLL
)
71 wxFLAGS_MEMBER(wxHSCROLL
)
73 wxFLAGS_MEMBER(wxLC_LIST
)
74 wxFLAGS_MEMBER(wxLC_REPORT
)
75 wxFLAGS_MEMBER(wxLC_ICON
)
76 wxFLAGS_MEMBER(wxLC_SMALL_ICON
)
77 wxFLAGS_MEMBER(wxLC_ALIGN_TOP
)
78 wxFLAGS_MEMBER(wxLC_ALIGN_LEFT
)
79 wxFLAGS_MEMBER(wxLC_AUTOARRANGE
)
80 wxFLAGS_MEMBER(wxLC_USER_TEXT
)
81 wxFLAGS_MEMBER(wxLC_EDIT_LABELS
)
82 wxFLAGS_MEMBER(wxLC_NO_HEADER
)
83 wxFLAGS_MEMBER(wxLC_SINGLE_SEL
)
84 wxFLAGS_MEMBER(wxLC_SORT_ASCENDING
)
85 wxFLAGS_MEMBER(wxLC_SORT_DESCENDING
)
86 wxFLAGS_MEMBER(wxLC_VIRTUAL
)
88 wxEND_FLAGS( wxListCtrlStyle
)
90 IMPLEMENT_DYNAMIC_CLASS_XTI(wxListCtrl
, wxControl
,"wx/listctrl.h")
92 wxBEGIN_PROPERTIES_TABLE(wxListCtrl
)
93 wxEVENT_PROPERTY( TextUpdated
, wxEVT_COMMAND_TEXT_UPDATED
, wxCommandEvent
)
95 wxPROPERTY_FLAGS( WindowStyle
, wxListCtrlStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
96 wxEND_PROPERTIES_TABLE()
98 wxBEGIN_HANDLERS_TABLE(wxListCtrl
)
99 wxEND_HANDLERS_TABLE()
101 wxCONSTRUCTOR_5( wxListCtrl
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
104 TODO : Expose more information of a list's layout etc. via appropriate objects (à la NotebookPageInfo)
107 IMPLEMENT_DYNAMIC_CLASS(wxListCtrl
, wxControl
)
110 IMPLEMENT_DYNAMIC_CLASS(wxListView
, wxListCtrl
)
111 IMPLEMENT_DYNAMIC_CLASS(wxListItem
, wxObject
)
113 IMPLEMENT_DYNAMIC_CLASS(wxListEvent
, wxNotifyEvent
)
115 WX_DECLARE_EXPORTED_LIST(wxListItem
, wxListItemList
);
116 #include "wx/listimpl.cpp"
117 WX_DEFINE_LIST(wxListItemList
)
119 // so we can check for column clicks
120 static const EventTypeSpec eventList
[] =
122 { kEventClassControl
, kEventControlHit
},
125 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
127 OSStatus result
= eventNotHandledErr
;
129 wxMacCarbonEvent
cEvent( event
) ;
131 ControlRef controlRef
;
132 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
134 wxListCtrl
*window
= (wxListCtrl
*) data
;
135 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
136 le
.SetEventObject( window
);
138 switch ( GetEventKind( event
) )
140 // check if the column was clicked on and fire an event if so
141 case kEventControlHit
:
143 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
144 if (result
== kControlButtonPart
){
145 DataBrowserPropertyID col
;
146 GetDataBrowserSortProperty(controlRef
, &col
);
147 int column
= col
- kMinColumnId
;
149 window
->GetEventHandler()->ProcessEvent( le
);
151 result
= CallNextEventHandler(handler
, event
);
162 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
164 class wxMacListCtrlItem
: public wxMacListBoxItem
169 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
170 DataBrowserItemNotification message
,
171 DataBrowserItemDataRef itemData
) const;
173 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
174 virtual wxListItem
* GetColumnInfo( unsigned int column
);
175 virtual bool HasColumnInfo( unsigned int column
);
177 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
178 virtual const wxString
& GetColumnTextValue( unsigned int column
);
180 virtual int GetColumnImageValue( unsigned int column
);
181 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
183 virtual ~wxMacListCtrlItem();
185 wxListItemList m_rowItems
;
188 // TODO: Make a better name!!
189 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
192 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
193 virtual ~wxMacDataBrowserListCtrlControl();
195 // create a list item (can be a subclass of wxMacListBoxItem)
197 virtual wxMacDataItem
* CreateItem();
199 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
200 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
201 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
202 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
205 // we need to override to provide specialized handling for virtual wxListCtrls
206 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
207 DataBrowserPropertyID property
,
208 DataBrowserItemDataRef itemData
,
209 Boolean changeValue
);
211 virtual void ItemNotification(
212 DataBrowserItemID itemID
,
213 DataBrowserItemNotification message
,
214 DataBrowserItemDataRef itemData
);
216 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
217 DataBrowserItemID itemTwoID
,
218 DataBrowserPropertyID sortProperty
);
220 wxClientDataType m_clientDataItemsType
;
225 // TODO: This gives errors, find out why.
226 //BEGIN_EVENT_TABLE(wxListCtrl, wxControl)
227 // EVT_PAINT(wxListCtrl::OnPaint)
230 // ============================================================================
232 // ============================================================================
234 wxMacListControl
* wxListCtrl::GetPeer() const
236 return dynamic_cast<wxMacListControl
*>(m_peer
);
239 // ----------------------------------------------------------------------------
240 // wxListCtrl construction
241 // ----------------------------------------------------------------------------
243 void wxListCtrl::Init()
245 m_imageListNormal
= NULL
;
246 m_imageListSmall
= NULL
;
247 m_imageListState
= NULL
;
249 // keep track of if we created our own image lists, or if they were assigned
251 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
255 m_genericImpl
= NULL
;
257 m_compareFunc
= NULL
;
258 m_compareFuncData
= 0;
261 class wxGenericListCtrlHook
: public wxGenericListCtrl
264 wxGenericListCtrlHook(wxListCtrl
* parent
,
269 const wxValidator
& validator
,
270 const wxString
& name
)
271 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
272 m_nativeListCtrl(parent
)
277 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
279 return m_nativeListCtrl
->OnGetItemAttr(item
);
282 virtual int OnGetItemImage(long item
) const
284 return m_nativeListCtrl
->OnGetItemImage(item
);
287 virtual int OnGetItemColumnImage(long item
, long column
) const
289 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
292 virtual wxString
OnGetItemText(long item
, long column
) const
294 return m_nativeListCtrl
->OnGetItemText(item
, column
);
297 wxListCtrl
* m_nativeListCtrl
;
301 bool wxListCtrl::Create(wxWindow
*parent
,
306 const wxValidator
& validator
,
307 const wxString
& name
)
310 // for now, we'll always use the generic list control for ICON and LIST views,
311 // because they dynamically change the number of columns on resize.
312 // Also, allow the user to set it to use the list ctrl as well.
313 // Also, use generic list control in VIRTUAL mode.
314 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
315 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
316 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) /* || (style & wxLC_VIRTUAL) */ )
318 m_macIsUserPane
= true;
320 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
322 m_genericImpl
= new wxGenericListCtrlHook(this, id
, pos
, size
, style
, validator
, name
);
328 m_macIsUserPane
= false;
330 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
332 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
335 MacPostControlCreate( pos
, size
);
337 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
338 GetEventTypeCount(eventList
), eventList
, this,
339 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
345 wxListCtrl::~wxListCtrl()
347 if (m_ownsImageListNormal
)
348 delete m_imageListNormal
;
349 if (m_ownsImageListSmall
)
350 delete m_imageListSmall
;
351 if (m_ownsImageListState
)
352 delete m_imageListState
;
355 // ----------------------------------------------------------------------------
356 // set/get/change style
357 // ----------------------------------------------------------------------------
359 // Add or remove a single window style
360 void wxListCtrl::SetSingleStyle(long style
, bool add
)
362 long flag
= GetWindowStyleFlag();
364 // Get rid of conflicting styles
367 if ( style
& wxLC_MASK_TYPE
)
368 flag
= flag
& ~wxLC_MASK_TYPE
;
369 if ( style
& wxLC_MASK_ALIGN
)
370 flag
= flag
& ~wxLC_MASK_ALIGN
;
371 if ( style
& wxLC_MASK_SORT
)
372 flag
= flag
& ~wxLC_MASK_SORT
;
380 SetWindowStyleFlag(flag
);
383 // Set the whole window style
384 void wxListCtrl::SetWindowStyleFlag(long flag
)
386 if ( flag
!= m_windowStyle
)
388 m_windowStyle
= flag
;
392 m_genericImpl
->SetWindowStyleFlag(flag
);
399 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
401 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
404 m_genericImpl
->SetSize(x
, y
, width
, height
, sizeFlags
);
407 // ----------------------------------------------------------------------------
409 // ----------------------------------------------------------------------------
411 // Gets information about this column
412 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
415 return m_genericImpl
->GetColumn(col
, item
);
419 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
423 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
427 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
431 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) )
439 // Sets information about this column
440 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
443 return m_genericImpl
->SetColumn(col
, item
);
448 int wxListCtrl::GetColumnCount() const
451 return m_genericImpl
->GetColumnCount();
456 m_dbImpl
->GetColumnCount(&count
);
463 // Gets the column width
464 int wxListCtrl::GetColumnWidth(int col
) const
467 return m_genericImpl
->GetColumnWidth(col
);
471 return m_dbImpl
->GetColumnWidth(col
);
477 // Sets the column width
478 bool wxListCtrl::SetColumnWidth(int col
, int width
)
481 return m_genericImpl
->SetColumnWidth(col
, width
);
483 // TODO: This is setting the width of the first column
484 // to the entire window width; investigate why
490 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
495 for (int column
= 0; column
< GetColumnCount(); column
++)
497 m_dbImpl
->SetColumnWidth(col
, mywidth
);
501 m_dbImpl
->SetColumnWidth(col
, mywidth
);
509 // Gets the number of items that can fit vertically in the
510 // visible area of the list control (list or report view)
511 // or the total number of items in the list control (icon
512 // or small icon view)
513 int wxListCtrl::GetCountPerPage() const
516 return m_genericImpl
->GetCountPerPage();
525 // Gets the edit control for editing labels.
526 wxTextCtrl
* wxListCtrl::GetEditControl() const
529 return m_genericImpl
->GetEditControl();
534 // Gets information about the item
535 bool wxListCtrl::GetItem(wxListItem
& info
) const
538 return m_genericImpl
->GetItem(info
);
541 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
546 // Sets information about the item
547 bool wxListCtrl::SetItem(wxListItem
& info
)
550 return m_genericImpl
->SetItem(info
);
553 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
558 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
561 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
565 info
.m_mask
= wxLIST_MASK_TEXT
;
566 info
.m_itemId
= index
;
570 info
.m_image
= imageId
;
571 info
.m_mask
|= wxLIST_MASK_IMAGE
;
573 return SetItem(info
);
577 // Gets the item state
578 int wxListCtrl::GetItemState(long item
, long stateMask
) const
581 return m_genericImpl
->GetItemState(item
, stateMask
);
585 info
.m_mask
= wxLIST_MASK_STATE
;
586 info
.m_stateMask
= stateMask
;
587 info
.m_itemId
= item
;
595 // Sets the item state
596 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
599 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
602 info
.m_mask
= wxLIST_MASK_STATE
;
603 info
.m_stateMask
= stateMask
;
604 info
.m_state
= state
;
605 info
.m_itemId
= item
;
606 return SetItem(info
);
609 // Sets the item image
610 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
612 return SetItemColumnImage(item
, 0, image
);
615 // Sets the item image
616 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
619 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
623 info
.m_mask
= wxLIST_MASK_IMAGE
;
624 info
.m_image
= image
;
625 info
.m_itemId
= item
;
628 return SetItem(info
);
631 // Gets the item text
632 wxString
wxListCtrl::GetItemText(long item
) const
635 return m_genericImpl
->GetItemText(item
);
639 info
.m_mask
= wxLIST_MASK_TEXT
;
640 info
.m_itemId
= item
;
643 return wxEmptyString
;
647 // Sets the item text
648 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
651 return m_genericImpl
->SetItemText(item
, str
);
655 info
.m_mask
= wxLIST_MASK_TEXT
;
656 info
.m_itemId
= item
;
662 // Gets the item data
663 long wxListCtrl::GetItemData(long item
) const
666 return m_genericImpl
->GetItemData(item
);
670 info
.m_mask
= wxLIST_MASK_DATA
;
671 info
.m_itemId
= item
;
678 // Sets the item data
679 bool wxListCtrl::SetItemData(long item
, long data
)
682 return m_genericImpl
->SetItemData(item
, data
);
686 info
.m_mask
= wxLIST_MASK_DATA
;
687 info
.m_itemId
= item
;
690 return SetItem(info
);
693 wxRect
wxListCtrl::GetViewRect() const
695 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
696 _T("wxListCtrl::GetViewRect() only works in icon mode") );
699 return m_genericImpl
->GetViewRect();
705 // Gets the item rectangle
706 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
709 return m_genericImpl
->GetItemRect(item
, rect
, code
);
714 // Gets the item position
715 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
718 return m_genericImpl
->GetItemPosition(item
, pos
);
720 bool success
= false;
725 // Sets the item position.
726 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
729 return m_genericImpl
->SetItemPosition(item
, pos
);
734 // Gets the number of items in the list control
735 int wxListCtrl::GetItemCount() const
738 return m_genericImpl
->GetItemCount();
741 return m_dbImpl
->MacGetCount();
746 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
749 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
752 wxSize
wxListCtrl::GetItemSpacing() const
755 return m_genericImpl
->GetItemSpacing();
760 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
764 m_genericImpl
->SetItemTextColour(item
, col
);
769 info
.m_itemId
= item
;
770 info
.SetTextColour( col
);
774 wxColour
wxListCtrl::GetItemTextColour( long item
) const
777 return m_genericImpl
->GetItemTextColour(item
);
783 return info
.GetTextColour();
788 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
792 m_genericImpl
->SetItemBackgroundColour(item
, col
);
797 info
.m_itemId
= item
;
798 info
.SetBackgroundColour( col
);
802 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
805 return m_genericImpl
->GetItemBackgroundColour(item
);
811 return info
.GetBackgroundColour();
816 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
820 m_genericImpl
->SetItemFont(item
, f
);
825 info
.m_itemId
= item
;
830 wxFont
wxListCtrl::GetItemFont( long item
) const
833 return m_genericImpl
->GetItemFont(item
);
839 return info
.GetFont();
845 // Gets the number of selected items in the list control
846 int wxListCtrl::GetSelectedItemCount() const
849 return m_genericImpl
->GetSelectedItemCount();
852 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
857 // Gets the text colour of the listview
858 wxColour
wxListCtrl::GetTextColour() const
861 return m_genericImpl
->GetTextColour();
863 // TODO: we need owner drawn list items to customize text color.
870 // Sets the text colour of the listview
871 void wxListCtrl::SetTextColour(const wxColour
& col
)
875 m_genericImpl
->SetTextColour(col
);
879 // TODO: if we add owner-drawn item support for DataBrowser,
880 // consider supporting this property
883 // Gets the index of the topmost visible item when in
884 // list or report view
885 long wxListCtrl::GetTopItem() const
888 return m_genericImpl
->GetTopItem();
893 // Searches for an item, starting from 'item'.
894 // 'geometry' is one of
895 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
896 // 'state' is a state bit flag, one or more of
897 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
898 // item can be -1 to find the first item that matches the
900 // Returns the item or -1 if unsuccessful.
901 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
904 return m_genericImpl
->GetNextItem(item
, geom
, state
);
906 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
908 long count
= m_dbImpl
->MacGetCount() ;
909 for ( long line
= item
+ 1 ; line
< count
; line
++ )
911 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
912 if ( m_dbImpl
->IsItemSelected(id
) )
922 wxImageList
*wxListCtrl::GetImageList(int which
) const
925 return m_genericImpl
->GetImageList(which
);
927 if ( which
== wxIMAGE_LIST_NORMAL
)
929 return m_imageListNormal
;
931 else if ( which
== wxIMAGE_LIST_SMALL
)
933 return m_imageListSmall
;
935 else if ( which
== wxIMAGE_LIST_STATE
)
937 return m_imageListState
;
942 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
946 m_genericImpl
->SetImageList(imageList
, which
);
950 if ( which
== wxIMAGE_LIST_NORMAL
)
952 if (m_ownsImageListNormal
) delete m_imageListNormal
;
953 m_imageListNormal
= imageList
;
954 m_ownsImageListNormal
= false;
956 else if ( which
== wxIMAGE_LIST_SMALL
)
958 if (m_ownsImageListSmall
) delete m_imageListSmall
;
959 m_imageListSmall
= imageList
;
960 m_ownsImageListSmall
= false;
962 else if ( which
== wxIMAGE_LIST_STATE
)
964 if (m_ownsImageListState
) delete m_imageListState
;
965 m_imageListState
= imageList
;
966 m_ownsImageListState
= false;
970 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
974 m_genericImpl
->AssignImageList(imageList
, which
);
978 SetImageList(imageList
, which
);
979 if ( which
== wxIMAGE_LIST_NORMAL
)
980 m_ownsImageListNormal
= true;
981 else if ( which
== wxIMAGE_LIST_SMALL
)
982 m_ownsImageListSmall
= true;
983 else if ( which
== wxIMAGE_LIST_STATE
)
984 m_ownsImageListState
= true;
987 // ----------------------------------------------------------------------------
989 // ----------------------------------------------------------------------------
991 // Arranges the items
992 bool wxListCtrl::Arrange(int flag
)
995 return m_genericImpl
->Arrange(flag
);
1000 bool wxListCtrl::DeleteItem(long item
)
1003 return m_genericImpl
->DeleteItem(item
);
1007 m_dbImpl
->MacDelete(item
);
1008 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1009 event
.SetEventObject( this );
1010 event
.m_itemIndex
= item
;
1011 GetEventHandler()->ProcessEvent( event
);
1017 // Deletes all items
1018 bool wxListCtrl::DeleteAllItems()
1021 return m_genericImpl
->DeleteAllItems();
1025 m_dbImpl
->MacClear();
1026 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1027 event
.SetEventObject( this );
1028 GetEventHandler()->ProcessEvent( event
);
1033 // Deletes all items
1034 bool wxListCtrl::DeleteAllColumns()
1037 return m_genericImpl
->DeleteAllColumns();
1042 m_dbImpl
->GetColumnCount(&cols
);
1043 for (UInt32 col
= 0; col
< cols
; col
++)
1053 bool wxListCtrl::DeleteColumn(int col
)
1056 return m_genericImpl
->DeleteColumn(col
);
1060 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1061 return err
== noErr
;
1067 // Clears items, and columns if there are any.
1068 void wxListCtrl::ClearAll()
1072 m_genericImpl
->ClearAll();
1083 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1086 return m_genericImpl
->EditLabel(item
, textControlClass
);
1090 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(item
);
1091 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)id
, kMinColumnId
) );
1096 // End label editing, optionally cancelling the edit
1097 bool wxListCtrl::EndEditLabel(bool cancel
)
1099 // TODO: generic impl. doesn't have this method - is it needed for us?
1101 return true; // m_genericImpl->EndEditLabel(cancel);
1104 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1108 // Ensures this item is visible
1109 bool wxListCtrl::EnsureVisible(long item
)
1112 return m_genericImpl
->EnsureVisible(item
);
1116 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1117 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1123 // Find an item whose label matches this string, starting from the item after 'start'
1124 // or the beginning if 'start' is -1.
1125 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1128 return m_genericImpl
->FindItem(start
, str
, partial
);
1133 // Find an item whose data matches this data, starting from the item after 'start'
1134 // or the beginning if 'start' is -1.
1135 long wxListCtrl::FindItem(long start
, long data
)
1138 return m_genericImpl
->FindItem(start
, data
);
1140 long idx
= start
+ 1;
1141 long count
= GetItemCount();
1145 if (GetItemData(idx
) == data
)
1153 // Find an item nearest this position in the specified direction, starting from
1154 // the item after 'start' or the beginning if 'start' is -1.
1155 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1158 return m_genericImpl
->FindItem(start
, pt
, direction
);
1162 // Determines which item (if any) is at the specified point,
1163 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1165 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1168 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1174 // Inserts an item, returning the index of the new item if successful,
1176 long wxListCtrl::InsertItem(wxListItem
& info
)
1178 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1181 return m_genericImpl
->InsertItem(info
);
1185 int count
= GetItemCount();
1187 if (info
.m_itemId
> count
)
1188 info
.m_itemId
= count
;
1190 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1191 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1192 event
.SetEventObject( this );
1193 event
.m_itemIndex
= info
.m_itemId
;
1194 GetEventHandler()->ProcessEvent( event
);
1197 return info
.m_itemId
;
1200 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1203 return m_genericImpl
->InsertItem(index
, label
);
1206 info
.m_text
= label
;
1207 info
.m_mask
= wxLIST_MASK_TEXT
;
1208 info
.m_itemId
= index
;
1209 return InsertItem(info
);
1212 // Inserts an image item
1213 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1216 return m_genericImpl
->InsertItem(index
, imageIndex
);
1219 info
.m_image
= imageIndex
;
1220 info
.m_mask
= wxLIST_MASK_IMAGE
;
1221 info
.m_itemId
= index
;
1222 return InsertItem(info
);
1225 // Inserts an image/string item
1226 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1229 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1232 info
.m_image
= imageIndex
;
1233 info
.m_text
= label
;
1234 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1235 info
.m_itemId
= index
;
1236 return InsertItem(info
);
1239 // For list view mode (only), inserts a column.
1240 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1243 return m_genericImpl
->InsertColumn(col
, item
);
1247 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1250 DataBrowserPropertyType type
= kDataBrowserTextType
;
1251 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1252 if (imageList
&& imageList
->GetImageCount() > 0)
1254 wxBitmap bmp
= imageList
->GetBitmap(0);
1256 type
= kDataBrowserIconAndTextType
;
1259 SInt16 just
= teFlushDefault
;
1260 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1262 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1264 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1266 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1267 just
= teFlushRight
;
1269 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, item
.GetWidth());
1271 // set/remove options based on the wxListCtrl type.
1272 DataBrowserTableViewColumnID id
;
1273 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1274 DataBrowserPropertyFlags flags
;
1275 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1276 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1277 flags
|= kDataBrowserPropertyIsEditable
;
1279 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1280 flags
&= ~kDataBrowserListViewSortableColumn
;
1282 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1288 long wxListCtrl::InsertColumn(long col
,
1289 const wxString
& heading
,
1294 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1297 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1298 item
.m_text
= heading
;
1301 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1302 item
.m_width
= width
;
1304 item
.m_format
= format
;
1306 return InsertColumn(col
, item
);
1309 // scroll the control by the given number of pixels (exception: in list view,
1310 // dx is interpreted as number of columns)
1311 bool wxListCtrl::ScrollList(int dx
, int dy
)
1314 return m_genericImpl
->ScrollList(dx
, dy
);
1318 m_dbImpl
->SetScrollPosition(dx
, dy
);
1324 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1327 return m_genericImpl
->SortItems(fn
, data
);
1332 m_compareFuncData
= data
;
1338 // ----------------------------------------------------------------------------
1339 // virtual list controls
1340 // ----------------------------------------------------------------------------
1342 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1344 // this is a pure virtual function, in fact - which is not really pure
1345 // because the controls which are not virtual don't need to implement it
1346 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1348 return wxEmptyString
;
1351 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1353 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1355 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1359 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1362 return OnGetItemImage(item
);
1367 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1369 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1370 _T("invalid item index in OnGetItemAttr()") );
1372 // no attributes by default
1376 void wxListCtrl::SetItemCount(long count
)
1378 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1382 m_genericImpl
->SetItemCount(count
);
1388 // we need to temporarily disable the new item creation notification
1389 // procedure to speed things up
1390 // FIXME: Even this doesn't seem to help much...
1391 DataBrowserCallbacks callbacks
;
1392 DataBrowserItemNotificationUPP itemUPP
;
1393 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
1394 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
1395 callbacks
.u
.v1
.itemNotificationCallback
= 0;
1396 m_dbImpl
->SetCallbacks(&callbacks
);
1397 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
1398 count
, NULL
, kDataBrowserItemNoProperty
);
1399 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
1400 m_dbImpl
->SetCallbacks(&callbacks
);
1405 void wxListCtrl::RefreshItem(long item
)
1409 m_genericImpl
->RefreshItem(item
);
1414 GetItemRect(item
, rect
);
1418 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1422 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1426 wxRect rect1
, rect2
;
1427 GetItemRect(itemFrom
, rect1
);
1428 GetItemRect(itemTo
, rect2
);
1430 wxRect rect
= rect1
;
1431 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
1437 // wxMac internal data structures
1439 wxMacListCtrlItem::~wxMacListCtrlItem()
1443 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
1444 DataBrowserItemNotification message
,
1445 DataBrowserItemDataRef itemData
) const
1448 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
1450 // we want to depend on as little as possible to make sure tear-down of controls is safe
1451 if ( message
== kDataBrowserItemRemoved
)
1453 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
1455 delete (wxClientData
*) (m_data
);
1461 else if ( message
== kDataBrowserItemAdded
)
1463 // we don't issue events on adding, the item is not really stored in the list yet, so we
1464 // avoid asserts by gettting out now
1468 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1471 bool trigger
= false;
1473 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1474 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
1476 event
.SetEventObject( list
);
1477 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
1478 if ( !list
->IsVirtual() )
1480 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1485 case kDataBrowserItemDeselected
:
1486 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1488 trigger
= !lb
->IsSelectionSuppressed();
1491 case kDataBrowserItemSelected
:
1492 trigger
= !lb
->IsSelectionSuppressed();
1495 case kDataBrowserItemDoubleClicked
:
1496 event
.SetEventType( wxEVT_LEFT_DCLICK
);
1500 case kDataBrowserEditStarted
:
1501 // TODO : how to veto ?
1502 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
1506 case kDataBrowserEditStopped
:
1507 // TODO probably trigger only upon the value store callback, because
1508 // here IIRC we cannot veto
1509 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
1519 // direct notification is not always having the listbox GetSelection() having in synch with event
1520 wxPostEvent( list
->GetEventHandler(), event
);
1526 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
1527 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
1529 OSStatus err
= noErr
;
1530 m_clientDataItemsType
= wxClientData_None
;
1531 m_isVirtual
= false;
1533 if ( style
& wxLC_VIRTUAL
)
1536 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
1537 if ( style
& wxLC_SINGLE_SEL
)
1539 options
|= kDataBrowserSelectOnlyOne
;
1543 options
|= kDataBrowserCmdTogglesSelection
;
1546 err
= SetSelectionFlags( options
);
1547 verify_noerr( err
);
1549 if ( style
& wxLC_LIST
)
1551 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
1552 verify_noerr( AutoSizeColumns() );
1555 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
1556 verify_noerr( SetHeaderButtonHeight( 0 ) );
1559 SetSortProperty( kMinColumnId
- 1 );
1561 SetSortProperty( kMinColumnId
);
1562 if ( style
& wxLC_SORT_ASCENDING
)
1564 m_sortOrder
= SortOrder_Text_Ascending
;
1565 SetSortOrder( kDataBrowserOrderIncreasing
);
1567 else if ( style
& wxLC_SORT_DESCENDING
)
1569 m_sortOrder
= SortOrder_Text_Descending
;
1570 SetSortOrder( kDataBrowserOrderDecreasing
);
1574 m_sortOrder
= SortOrder_None
;
1577 if ( style
& wxLC_VRULES
)
1579 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1580 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
1584 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
1585 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
1588 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
1589 DataBrowserPropertyID property
,
1590 DataBrowserItemDataRef itemData
,
1591 Boolean changeValue
)
1595 short listColumn
= property
- kMinColumnId
;
1597 OSStatus err
= errDataBrowserPropertyNotSupported
;
1598 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1599 wxMacListCtrlItem
* lcItem
;
1601 if (listColumn
>= 0)
1605 lcItem
= (wxMacListCtrlItem
*) itemID
;
1606 if (lcItem
->HasColumnInfo(listColumn
)){
1607 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
1608 if (item
->GetMask() & wxLIST_MASK_TEXT
)
1609 text
= item
->GetText();
1610 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
1611 imgIndex
= item
->GetImage();
1616 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
1617 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
1625 case kDataBrowserItemIsEditableProperty
:
1626 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
1628 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
1633 if ( property
>= kMinColumnId
)
1635 wxMacCFStringHolder cfStr
;
1638 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
1639 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
1645 if ( imgIndex
!= -1 )
1647 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
1648 if (imageList
&& imageList
->GetImageCount() > 0){
1649 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
1650 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
1651 ::SetDataBrowserItemDataIcon(itemData
, icon
);
1665 if ( property
>= kMinColumnId
)
1667 short listColumn
= property
- kMinColumnId
;
1669 // TODO probably send the 'end edit' from here, as we
1670 // can then deal with the veto
1672 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
1673 wxMacCFStringHolder
cfStr(sr
) ;;
1675 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
1679 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
1689 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
1690 DataBrowserItemNotification message
,
1691 DataBrowserItemDataRef itemData
)
1693 // we want to depend on as little as possible to make sure tear-down of controls is safe
1694 if ( message
== kDataBrowserItemRemoved
)
1696 // make sure MacDelete does the proper teardown.
1699 else if ( message
== kDataBrowserItemAdded
)
1701 // we don't issue events on adding, the item is not really stored in the list yet, so we
1702 // avoid asserts by getting out now
1706 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1709 bool trigger
= false;
1711 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1712 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
1714 event
.SetEventObject( list
);
1715 if ( !list
->IsVirtual() )
1717 DataBrowserTableViewRowIndex result
= 0;
1718 verify_noerr( GetItemRow( itemID
, &result
) ) ;
1719 event
.m_itemIndex
= result
;
1721 if (event
.m_itemIndex
>= 0)
1722 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1726 event
.m_itemIndex
= (long)itemID
;
1731 case kDataBrowserItemDeselected
:
1732 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1734 trigger
= IsSelectionSuppressed();
1737 case kDataBrowserItemSelected
:
1738 trigger
= IsSelectionSuppressed();
1741 case kDataBrowserItemDoubleClicked
:
1742 event
.SetEventType( wxEVT_LEFT_DCLICK
);
1746 case kDataBrowserEditStarted
:
1747 // TODO : how to veto ?
1748 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
1752 case kDataBrowserEditStopped
:
1753 // TODO probably trigger only upon the value store callback, because
1754 // here IIRC we cannot veto
1755 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
1765 // direct notification is not always having the listbox GetSelection() having in synch with event
1766 wxPostEvent( list
->GetEventHandler(), event
);
1771 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
1772 DataBrowserItemID itemTwoID
,
1773 DataBrowserPropertyID sortProperty
)
1776 bool retval
= false;
1778 wxString otherItemText
;
1779 int colId
= sortProperty
- kMinColumnId
;
1781 long otherItemNum
= 0;
1783 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1790 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
1791 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
1792 wxListCtrlCompare func
= list
->GetCompareFunc();
1793 if (func
!= NULL
&& item
->HasColumnInfo(colId
) && otherItem
->HasColumnInfo(colId
))
1794 return func(item
->GetColumnInfo(colId
)->GetData(), otherItem
->GetColumnInfo(colId
)->GetData(), list
->GetCompareFuncData()) >= 0;
1796 itemNum
= item
->GetOrder();
1797 otherItemNum
= otherItem
->GetOrder();
1798 if (item
->HasColumnInfo(colId
))
1799 itemText
= item
->GetColumnInfo(colId
)->GetText();
1800 if (otherItem
->HasColumnInfo(colId
))
1801 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
1805 itemNum
= (long)itemOneID
;
1806 otherItemNum
= (long)itemTwoID
;
1807 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
1808 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
1812 DataBrowserSortOrder sort
;
1813 verify_noerr(GetSortOrder(&sort
));
1815 if ( sort
== kDataBrowserOrderIncreasing
)
1817 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
1819 else if ( sort
== kDataBrowserOrderDecreasing
)
1821 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
1825 // fallback for undefined cases
1826 retval
= itemOneID
< itemTwoID
;
1832 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
1836 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
1838 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1841 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1842 listItem
->SetColumnInfo( column
, item
);
1843 UpdateState(dataItem
, item
);
1847 // apply changes that need to happen immediately, rather than when the
1848 // databrowser control fires a callback.
1849 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
1851 bool isSelected
= IsItemSelected( dataItem
);
1852 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
1854 // toggle the selection state if wxListInfo state and actual state don't match.
1855 if ( isSelected
!= isSelectedState
)
1857 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
1858 if (!isSelectedState
)
1859 options
= kDataBrowserItemsRemove
;
1860 SetSelectedItem(dataItem
, options
);
1862 // TODO: Set column width if item width > than current column width
1865 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
1867 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1868 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
1871 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1872 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
1874 long mask
= item
.GetMask();
1876 // by default, get everything for backwards compatibility
1879 if ( mask
& wxLIST_MASK_TEXT
)
1880 item
.SetText(oldItem
->GetText());
1881 if ( mask
& wxLIST_MASK_IMAGE
)
1882 item
.SetImage(oldItem
->GetImage());
1883 if ( mask
& wxLIST_MASK_DATA
)
1884 item
.SetData(oldItem
->GetData());
1885 if ( mask
& wxLIST_MASK_STATE
)
1886 item
.SetState(oldItem
->GetState());
1887 if ( mask
& wxLIST_MASK_WIDTH
)
1888 item
.SetWidth(oldItem
->GetWidth());
1889 if ( mask
& wxLIST_MASK_FORMAT
)
1890 item
.SetAlign(oldItem
->GetAlign());
1892 item
.SetTextColour(oldItem
->GetTextColour());
1893 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
1894 item
.SetFont(oldItem
->GetFont());
1898 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
1900 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
1901 MacSetColumnInfo(n
, 0, item
);
1904 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
1906 return new wxMacListCtrlItem();
1909 wxMacListCtrlItem::wxMacListCtrlItem()
1911 m_rowItems
= wxListItemList();
1914 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
1916 return GetColumnInfo(column
)->GetImage();
1919 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
1921 GetColumnInfo(column
)->SetImage(imageIndex
);
1924 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
1929 return GetColumnInfo(column
)->GetText();
1932 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
1934 GetColumnInfo(column
)->SetText(text
);
1936 // for compatibility with superclass APIs
1941 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
1943 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
1944 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
1946 return node
->GetData();
1949 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
1951 return m_rowItems
.GetCount() > column
;
1954 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
1957 if ( column
>= m_rowItems
.GetCount() )
1959 wxListItem
* listItem
= new wxListItem(*item
);
1960 m_rowItems
.Append( listItem
);
1964 wxListItem
* listItem
= GetColumnInfo( column
);
1965 long mask
= item
->GetMask();
1966 if (mask
& wxLIST_MASK_TEXT
)
1967 listItem
->SetText(item
->GetText());
1968 if (mask
& wxLIST_MASK_DATA
)
1969 listItem
->SetData(item
->GetData());
1970 if (mask
& wxLIST_MASK_IMAGE
)
1971 listItem
->SetImage(item
->GetImage());
1972 if (mask
& wxLIST_MASK_STATE
)
1973 listItem
->SetState(item
->GetState());
1974 if (mask
& wxLIST_MASK_FORMAT
)
1975 listItem
->SetAlign(item
->GetAlign());
1976 if (mask
& wxLIST_MASK_WIDTH
)
1977 listItem
->SetWidth(item
->GetWidth());
1981 #endif // wxUSE_LISTCTRL