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 bool wxListCtrl::SetFont(const wxFont
& font
)
410 rv
= wxControl::SetFont(font
);
412 rv
= m_genericImpl
->SetFont(font
);
416 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
419 rv
= wxControl::SetForegroundColour(colour
);
421 rv
= m_genericImpl
->SetForegroundColour(colour
);
425 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
428 rv
= wxControl::SetBackgroundColour(colour
);
430 rv
= m_genericImpl
->SetBackgroundColour(colour
);
434 // ----------------------------------------------------------------------------
436 // ----------------------------------------------------------------------------
438 // Gets information about this column
439 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
442 return m_genericImpl
->GetColumn(col
, item
);
446 if ( item
.m_mask
& wxLIST_MASK_TEXT
)
450 if ( item
.m_mask
& wxLIST_MASK_FORMAT
)
454 if ( item
.m_mask
& wxLIST_MASK_IMAGE
)
458 if ( (item
.m_mask
& wxLIST_MASK_TEXT
) )
466 // Sets information about this column
467 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
470 return m_genericImpl
->SetColumn(col
, item
);
475 int wxListCtrl::GetColumnCount() const
478 return m_genericImpl
->GetColumnCount();
483 m_dbImpl
->GetColumnCount(&count
);
490 // Gets the column width
491 int wxListCtrl::GetColumnWidth(int col
) const
494 return m_genericImpl
->GetColumnWidth(col
);
498 return m_dbImpl
->GetColumnWidth(col
);
504 // Sets the column width
505 bool wxListCtrl::SetColumnWidth(int col
, int width
)
508 return m_genericImpl
->SetColumnWidth(col
, width
);
510 // TODO: This is setting the width of the first column
511 // to the entire window width; investigate why
517 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
522 for (int column
= 0; column
< GetColumnCount(); column
++)
524 m_dbImpl
->SetColumnWidth(col
, mywidth
);
528 m_dbImpl
->SetColumnWidth(col
, mywidth
);
536 // Gets the number of items that can fit vertically in the
537 // visible area of the list control (list or report view)
538 // or the total number of items in the list control (icon
539 // or small icon view)
540 int wxListCtrl::GetCountPerPage() const
543 return m_genericImpl
->GetCountPerPage();
552 // Gets the edit control for editing labels.
553 wxTextCtrl
* wxListCtrl::GetEditControl() const
556 return m_genericImpl
->GetEditControl();
561 // Gets information about the item
562 bool wxListCtrl::GetItem(wxListItem
& info
) const
565 return m_genericImpl
->GetItem(info
);
568 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
573 // Sets information about the item
574 bool wxListCtrl::SetItem(wxListItem
& info
)
577 return m_genericImpl
->SetItem(info
);
580 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
585 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
588 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
592 info
.m_mask
= wxLIST_MASK_TEXT
;
593 info
.m_itemId
= index
;
597 info
.m_image
= imageId
;
598 info
.m_mask
|= wxLIST_MASK_IMAGE
;
600 return SetItem(info
);
604 // Gets the item state
605 int wxListCtrl::GetItemState(long item
, long stateMask
) const
608 return m_genericImpl
->GetItemState(item
, stateMask
);
612 info
.m_mask
= wxLIST_MASK_STATE
;
613 info
.m_stateMask
= stateMask
;
614 info
.m_itemId
= item
;
622 // Sets the item state
623 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
626 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
629 info
.m_mask
= wxLIST_MASK_STATE
;
630 info
.m_stateMask
= stateMask
;
631 info
.m_state
= state
;
632 info
.m_itemId
= item
;
633 return SetItem(info
);
636 // Sets the item image
637 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
639 return SetItemColumnImage(item
, 0, image
);
642 // Sets the item image
643 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
646 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
650 info
.m_mask
= wxLIST_MASK_IMAGE
;
651 info
.m_image
= image
;
652 info
.m_itemId
= item
;
655 return SetItem(info
);
658 // Gets the item text
659 wxString
wxListCtrl::GetItemText(long item
) const
662 return m_genericImpl
->GetItemText(item
);
666 info
.m_mask
= wxLIST_MASK_TEXT
;
667 info
.m_itemId
= item
;
670 return wxEmptyString
;
674 // Sets the item text
675 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
678 return m_genericImpl
->SetItemText(item
, str
);
682 info
.m_mask
= wxLIST_MASK_TEXT
;
683 info
.m_itemId
= item
;
689 // Gets the item data
690 long wxListCtrl::GetItemData(long item
) const
693 return m_genericImpl
->GetItemData(item
);
697 info
.m_mask
= wxLIST_MASK_DATA
;
698 info
.m_itemId
= item
;
705 // Sets the item data
706 bool wxListCtrl::SetItemData(long item
, long data
)
709 return m_genericImpl
->SetItemData(item
, data
);
713 info
.m_mask
= wxLIST_MASK_DATA
;
714 info
.m_itemId
= item
;
717 return SetItem(info
);
720 wxRect
wxListCtrl::GetViewRect() const
722 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
723 _T("wxListCtrl::GetViewRect() only works in icon mode") );
726 return m_genericImpl
->GetViewRect();
732 // Gets the item rectangle
733 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
736 return m_genericImpl
->GetItemRect(item
, rect
, code
);
741 // Gets the item position
742 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
745 return m_genericImpl
->GetItemPosition(item
, pos
);
747 bool success
= false;
752 // Sets the item position.
753 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
756 return m_genericImpl
->SetItemPosition(item
, pos
);
761 // Gets the number of items in the list control
762 int wxListCtrl::GetItemCount() const
765 return m_genericImpl
->GetItemCount();
768 return m_dbImpl
->MacGetCount();
773 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
776 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
779 wxSize
wxListCtrl::GetItemSpacing() const
782 return m_genericImpl
->GetItemSpacing();
787 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
791 m_genericImpl
->SetItemTextColour(item
, col
);
796 info
.m_itemId
= item
;
797 info
.SetTextColour( col
);
801 wxColour
wxListCtrl::GetItemTextColour( long item
) const
804 return m_genericImpl
->GetItemTextColour(item
);
810 return info
.GetTextColour();
815 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
819 m_genericImpl
->SetItemBackgroundColour(item
, col
);
824 info
.m_itemId
= item
;
825 info
.SetBackgroundColour( col
);
829 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
832 return m_genericImpl
->GetItemBackgroundColour(item
);
838 return info
.GetBackgroundColour();
843 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
847 m_genericImpl
->SetItemFont(item
, f
);
852 info
.m_itemId
= item
;
857 wxFont
wxListCtrl::GetItemFont( long item
) const
860 return m_genericImpl
->GetItemFont(item
);
866 return info
.GetFont();
872 // Gets the number of selected items in the list control
873 int wxListCtrl::GetSelectedItemCount() const
876 return m_genericImpl
->GetSelectedItemCount();
879 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
884 // Gets the text colour of the listview
885 wxColour
wxListCtrl::GetTextColour() const
888 return m_genericImpl
->GetTextColour();
890 // TODO: we need owner drawn list items to customize text color.
897 // Sets the text colour of the listview
898 void wxListCtrl::SetTextColour(const wxColour
& col
)
902 m_genericImpl
->SetTextColour(col
);
906 // TODO: if we add owner-drawn item support for DataBrowser,
907 // consider supporting this property
910 // Gets the index of the topmost visible item when in
911 // list or report view
912 long wxListCtrl::GetTopItem() const
915 return m_genericImpl
->GetTopItem();
920 // Searches for an item, starting from 'item'.
921 // 'geometry' is one of
922 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
923 // 'state' is a state bit flag, one or more of
924 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
925 // item can be -1 to find the first item that matches the
927 // Returns the item or -1 if unsuccessful.
928 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
931 return m_genericImpl
->GetNextItem(item
, geom
, state
);
933 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
935 long count
= m_dbImpl
->MacGetCount() ;
936 for ( long line
= item
+ 1 ; line
< count
; line
++ )
938 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
939 if ( m_dbImpl
->IsItemSelected(id
) )
949 wxImageList
*wxListCtrl::GetImageList(int which
) const
952 return m_genericImpl
->GetImageList(which
);
954 if ( which
== wxIMAGE_LIST_NORMAL
)
956 return m_imageListNormal
;
958 else if ( which
== wxIMAGE_LIST_SMALL
)
960 return m_imageListSmall
;
962 else if ( which
== wxIMAGE_LIST_STATE
)
964 return m_imageListState
;
969 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
973 m_genericImpl
->SetImageList(imageList
, which
);
977 if ( which
== wxIMAGE_LIST_NORMAL
)
979 if (m_ownsImageListNormal
) delete m_imageListNormal
;
980 m_imageListNormal
= imageList
;
981 m_ownsImageListNormal
= false;
983 else if ( which
== wxIMAGE_LIST_SMALL
)
985 if (m_ownsImageListSmall
) delete m_imageListSmall
;
986 m_imageListSmall
= imageList
;
987 m_ownsImageListSmall
= false;
989 else if ( which
== wxIMAGE_LIST_STATE
)
991 if (m_ownsImageListState
) delete m_imageListState
;
992 m_imageListState
= imageList
;
993 m_ownsImageListState
= false;
997 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1001 m_genericImpl
->AssignImageList(imageList
, which
);
1005 SetImageList(imageList
, which
);
1006 if ( which
== wxIMAGE_LIST_NORMAL
)
1007 m_ownsImageListNormal
= true;
1008 else if ( which
== wxIMAGE_LIST_SMALL
)
1009 m_ownsImageListSmall
= true;
1010 else if ( which
== wxIMAGE_LIST_STATE
)
1011 m_ownsImageListState
= true;
1014 // ----------------------------------------------------------------------------
1016 // ----------------------------------------------------------------------------
1018 // Arranges the items
1019 bool wxListCtrl::Arrange(int flag
)
1022 return m_genericImpl
->Arrange(flag
);
1027 bool wxListCtrl::DeleteItem(long item
)
1030 return m_genericImpl
->DeleteItem(item
);
1034 m_dbImpl
->MacDelete(item
);
1035 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1036 event
.SetEventObject( this );
1037 event
.m_itemIndex
= item
;
1038 GetEventHandler()->ProcessEvent( event
);
1044 // Deletes all items
1045 bool wxListCtrl::DeleteAllItems()
1048 return m_genericImpl
->DeleteAllItems();
1052 m_dbImpl
->MacClear();
1053 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1054 event
.SetEventObject( this );
1055 GetEventHandler()->ProcessEvent( event
);
1060 // Deletes all items
1061 bool wxListCtrl::DeleteAllColumns()
1064 return m_genericImpl
->DeleteAllColumns();
1069 m_dbImpl
->GetColumnCount(&cols
);
1070 for (UInt32 col
= 0; col
< cols
; col
++)
1080 bool wxListCtrl::DeleteColumn(int col
)
1083 return m_genericImpl
->DeleteColumn(col
);
1087 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1088 return err
== noErr
;
1094 // Clears items, and columns if there are any.
1095 void wxListCtrl::ClearAll()
1099 m_genericImpl
->ClearAll();
1110 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1113 return m_genericImpl
->EditLabel(item
, textControlClass
);
1117 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(item
);
1118 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)id
, kMinColumnId
) );
1123 // End label editing, optionally cancelling the edit
1124 bool wxListCtrl::EndEditLabel(bool cancel
)
1126 // TODO: generic impl. doesn't have this method - is it needed for us?
1128 return true; // m_genericImpl->EndEditLabel(cancel);
1131 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1135 // Ensures this item is visible
1136 bool wxListCtrl::EnsureVisible(long item
)
1139 return m_genericImpl
->EnsureVisible(item
);
1143 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1144 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1150 // Find an item whose label matches this string, starting from the item after 'start'
1151 // or the beginning if 'start' is -1.
1152 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1155 return m_genericImpl
->FindItem(start
, str
, partial
);
1160 // Find an item whose data matches this data, starting from the item after 'start'
1161 // or the beginning if 'start' is -1.
1162 long wxListCtrl::FindItem(long start
, long data
)
1165 return m_genericImpl
->FindItem(start
, data
);
1167 long idx
= start
+ 1;
1168 long count
= GetItemCount();
1172 if (GetItemData(idx
) == data
)
1180 // Find an item nearest this position in the specified direction, starting from
1181 // the item after 'start' or the beginning if 'start' is -1.
1182 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1185 return m_genericImpl
->FindItem(start
, pt
, direction
);
1189 // Determines which item (if any) is at the specified point,
1190 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1192 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1195 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1201 // Inserts an item, returning the index of the new item if successful,
1203 long wxListCtrl::InsertItem(wxListItem
& info
)
1205 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1208 return m_genericImpl
->InsertItem(info
);
1212 int count
= GetItemCount();
1214 if (info
.m_itemId
> count
)
1215 info
.m_itemId
= count
;
1217 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1218 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1219 event
.SetEventObject( this );
1220 event
.m_itemIndex
= info
.m_itemId
;
1221 GetEventHandler()->ProcessEvent( event
);
1224 return info
.m_itemId
;
1227 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1230 return m_genericImpl
->InsertItem(index
, label
);
1233 info
.m_text
= label
;
1234 info
.m_mask
= wxLIST_MASK_TEXT
;
1235 info
.m_itemId
= index
;
1236 return InsertItem(info
);
1239 // Inserts an image item
1240 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1243 return m_genericImpl
->InsertItem(index
, imageIndex
);
1246 info
.m_image
= imageIndex
;
1247 info
.m_mask
= wxLIST_MASK_IMAGE
;
1248 info
.m_itemId
= index
;
1249 return InsertItem(info
);
1252 // Inserts an image/string item
1253 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1256 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1259 info
.m_image
= imageIndex
;
1260 info
.m_text
= label
;
1261 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1262 info
.m_itemId
= index
;
1263 return InsertItem(info
);
1266 // For list view mode (only), inserts a column.
1267 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1270 return m_genericImpl
->InsertColumn(col
, item
);
1274 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1277 DataBrowserPropertyType type
= kDataBrowserTextType
;
1278 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1279 if (imageList
&& imageList
->GetImageCount() > 0)
1281 wxBitmap bmp
= imageList
->GetBitmap(0);
1283 type
= kDataBrowserIconAndTextType
;
1286 SInt16 just
= teFlushDefault
;
1287 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1289 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1291 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1293 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1294 just
= teFlushRight
;
1296 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, item
.GetWidth());
1298 // set/remove options based on the wxListCtrl type.
1299 DataBrowserTableViewColumnID id
;
1300 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1301 DataBrowserPropertyFlags flags
;
1302 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1303 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1304 flags
|= kDataBrowserPropertyIsEditable
;
1306 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1307 flags
&= ~kDataBrowserListViewSortableColumn
;
1309 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1315 long wxListCtrl::InsertColumn(long col
,
1316 const wxString
& heading
,
1321 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1324 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1325 item
.m_text
= heading
;
1328 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1329 item
.m_width
= width
;
1331 item
.m_format
= format
;
1333 return InsertColumn(col
, item
);
1336 // scroll the control by the given number of pixels (exception: in list view,
1337 // dx is interpreted as number of columns)
1338 bool wxListCtrl::ScrollList(int dx
, int dy
)
1341 return m_genericImpl
->ScrollList(dx
, dy
);
1345 m_dbImpl
->SetScrollPosition(dx
, dy
);
1351 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1354 return m_genericImpl
->SortItems(fn
, data
);
1359 m_compareFuncData
= data
;
1365 // ----------------------------------------------------------------------------
1366 // virtual list controls
1367 // ----------------------------------------------------------------------------
1369 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1371 // this is a pure virtual function, in fact - which is not really pure
1372 // because the controls which are not virtual don't need to implement it
1373 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1375 return wxEmptyString
;
1378 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1380 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1382 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1386 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1389 return OnGetItemImage(item
);
1394 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1396 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1397 _T("invalid item index in OnGetItemAttr()") );
1399 // no attributes by default
1403 void wxListCtrl::SetItemCount(long count
)
1405 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1409 m_genericImpl
->SetItemCount(count
);
1415 // we need to temporarily disable the new item creation notification
1416 // procedure to speed things up
1417 // FIXME: Even this doesn't seem to help much...
1418 DataBrowserCallbacks callbacks
;
1419 DataBrowserItemNotificationUPP itemUPP
;
1420 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
1421 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
1422 callbacks
.u
.v1
.itemNotificationCallback
= 0;
1423 m_dbImpl
->SetCallbacks(&callbacks
);
1424 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
1425 count
, NULL
, kDataBrowserItemNoProperty
);
1426 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
1427 m_dbImpl
->SetCallbacks(&callbacks
);
1432 void wxListCtrl::RefreshItem(long item
)
1436 m_genericImpl
->RefreshItem(item
);
1441 GetItemRect(item
, rect
);
1445 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1449 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1453 wxRect rect1
, rect2
;
1454 GetItemRect(itemFrom
, rect1
);
1455 GetItemRect(itemTo
, rect2
);
1457 wxRect rect
= rect1
;
1458 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
1464 // wxMac internal data structures
1466 wxMacListCtrlItem::~wxMacListCtrlItem()
1470 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
1471 DataBrowserItemNotification message
,
1472 DataBrowserItemDataRef itemData
) const
1475 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
1477 // we want to depend on as little as possible to make sure tear-down of controls is safe
1478 if ( message
== kDataBrowserItemRemoved
)
1480 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
1482 delete (wxClientData
*) (m_data
);
1488 else if ( message
== kDataBrowserItemAdded
)
1490 // we don't issue events on adding, the item is not really stored in the list yet, so we
1491 // avoid asserts by gettting out now
1495 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1498 bool trigger
= false;
1500 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1501 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
1503 event
.SetEventObject( list
);
1504 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
1505 if ( !list
->IsVirtual() )
1507 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1512 case kDataBrowserItemDeselected
:
1513 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1515 trigger
= !lb
->IsSelectionSuppressed();
1518 case kDataBrowserItemSelected
:
1519 trigger
= !lb
->IsSelectionSuppressed();
1522 case kDataBrowserItemDoubleClicked
:
1523 event
.SetEventType( wxEVT_LEFT_DCLICK
);
1527 case kDataBrowserEditStarted
:
1528 // TODO : how to veto ?
1529 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
1533 case kDataBrowserEditStopped
:
1534 // TODO probably trigger only upon the value store callback, because
1535 // here IIRC we cannot veto
1536 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
1546 // direct notification is not always having the listbox GetSelection() having in synch with event
1547 wxPostEvent( list
->GetEventHandler(), event
);
1553 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
1554 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
1556 OSStatus err
= noErr
;
1557 m_clientDataItemsType
= wxClientData_None
;
1558 m_isVirtual
= false;
1560 if ( style
& wxLC_VIRTUAL
)
1563 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
1564 if ( style
& wxLC_SINGLE_SEL
)
1566 options
|= kDataBrowserSelectOnlyOne
;
1570 options
|= kDataBrowserCmdTogglesSelection
;
1573 err
= SetSelectionFlags( options
);
1574 verify_noerr( err
);
1576 if ( style
& wxLC_LIST
)
1578 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
1579 verify_noerr( AutoSizeColumns() );
1582 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
1583 verify_noerr( SetHeaderButtonHeight( 0 ) );
1586 SetSortProperty( kMinColumnId
- 1 );
1588 SetSortProperty( kMinColumnId
);
1589 if ( style
& wxLC_SORT_ASCENDING
)
1591 m_sortOrder
= SortOrder_Text_Ascending
;
1592 SetSortOrder( kDataBrowserOrderIncreasing
);
1594 else if ( style
& wxLC_SORT_DESCENDING
)
1596 m_sortOrder
= SortOrder_Text_Descending
;
1597 SetSortOrder( kDataBrowserOrderDecreasing
);
1601 m_sortOrder
= SortOrder_None
;
1604 if ( style
& wxLC_VRULES
)
1606 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1607 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
1611 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
1612 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
1615 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
1616 DataBrowserPropertyID property
,
1617 DataBrowserItemDataRef itemData
,
1618 Boolean changeValue
)
1622 short listColumn
= property
- kMinColumnId
;
1624 OSStatus err
= errDataBrowserPropertyNotSupported
;
1625 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1626 wxMacListCtrlItem
* lcItem
;
1628 if (listColumn
>= 0)
1632 lcItem
= (wxMacListCtrlItem
*) itemID
;
1633 if (lcItem
->HasColumnInfo(listColumn
)){
1634 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
1635 if (item
->GetMask() & wxLIST_MASK_TEXT
)
1636 text
= item
->GetText();
1637 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
1638 imgIndex
= item
->GetImage();
1643 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
1644 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
1652 case kDataBrowserItemIsEditableProperty
:
1653 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
1655 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
1660 if ( property
>= kMinColumnId
)
1662 wxMacCFStringHolder cfStr
;
1665 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
1666 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
1672 if ( imgIndex
!= -1 )
1674 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
1675 if (imageList
&& imageList
->GetImageCount() > 0){
1676 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
1677 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
1678 ::SetDataBrowserItemDataIcon(itemData
, icon
);
1692 if ( property
>= kMinColumnId
)
1694 short listColumn
= property
- kMinColumnId
;
1696 // TODO probably send the 'end edit' from here, as we
1697 // can then deal with the veto
1699 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
1700 wxMacCFStringHolder
cfStr(sr
) ;;
1702 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
1706 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
1716 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
1717 DataBrowserItemNotification message
,
1718 DataBrowserItemDataRef itemData
)
1720 // we want to depend on as little as possible to make sure tear-down of controls is safe
1721 if ( message
== kDataBrowserItemRemoved
)
1723 // make sure MacDelete does the proper teardown.
1726 else if ( message
== kDataBrowserItemAdded
)
1728 // we don't issue events on adding, the item is not really stored in the list yet, so we
1729 // avoid asserts by getting out now
1733 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1736 bool trigger
= false;
1738 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1739 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
1741 event
.SetEventObject( list
);
1742 if ( !list
->IsVirtual() )
1744 DataBrowserTableViewRowIndex result
= 0;
1745 verify_noerr( GetItemRow( itemID
, &result
) ) ;
1746 event
.m_itemIndex
= result
;
1748 if (event
.m_itemIndex
>= 0)
1749 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1753 event
.m_itemIndex
= (long)itemID
;
1758 case kDataBrowserItemDeselected
:
1759 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1761 trigger
= IsSelectionSuppressed();
1764 case kDataBrowserItemSelected
:
1765 trigger
= IsSelectionSuppressed();
1768 case kDataBrowserItemDoubleClicked
:
1769 event
.SetEventType( wxEVT_LEFT_DCLICK
);
1773 case kDataBrowserEditStarted
:
1774 // TODO : how to veto ?
1775 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
1779 case kDataBrowserEditStopped
:
1780 // TODO probably trigger only upon the value store callback, because
1781 // here IIRC we cannot veto
1782 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
1792 // direct notification is not always having the listbox GetSelection() having in synch with event
1793 wxPostEvent( list
->GetEventHandler(), event
);
1798 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
1799 DataBrowserItemID itemTwoID
,
1800 DataBrowserPropertyID sortProperty
)
1803 bool retval
= false;
1805 wxString otherItemText
;
1806 int colId
= sortProperty
- kMinColumnId
;
1808 long otherItemNum
= 0;
1810 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1817 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
1818 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
1819 wxListCtrlCompare func
= list
->GetCompareFunc();
1820 if (func
!= NULL
&& item
->HasColumnInfo(colId
) && otherItem
->HasColumnInfo(colId
))
1821 return func(item
->GetColumnInfo(colId
)->GetData(), otherItem
->GetColumnInfo(colId
)->GetData(), list
->GetCompareFuncData()) >= 0;
1823 itemNum
= item
->GetOrder();
1824 otherItemNum
= otherItem
->GetOrder();
1825 if (item
->HasColumnInfo(colId
))
1826 itemText
= item
->GetColumnInfo(colId
)->GetText();
1827 if (otherItem
->HasColumnInfo(colId
))
1828 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
1832 itemNum
= (long)itemOneID
;
1833 otherItemNum
= (long)itemTwoID
;
1834 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
1835 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
1839 DataBrowserSortOrder sort
;
1840 verify_noerr(GetSortOrder(&sort
));
1842 if ( sort
== kDataBrowserOrderIncreasing
)
1844 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
1846 else if ( sort
== kDataBrowserOrderDecreasing
)
1848 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
1852 // fallback for undefined cases
1853 retval
= itemOneID
< itemTwoID
;
1859 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
1863 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
1865 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1868 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1869 listItem
->SetColumnInfo( column
, item
);
1870 UpdateState(dataItem
, item
);
1874 // apply changes that need to happen immediately, rather than when the
1875 // databrowser control fires a callback.
1876 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
1878 bool isSelected
= IsItemSelected( dataItem
);
1879 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
1881 // toggle the selection state if wxListInfo state and actual state don't match.
1882 if ( isSelected
!= isSelectedState
)
1884 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
1885 if (!isSelectedState
)
1886 options
= kDataBrowserItemsRemove
;
1887 SetSelectedItem(dataItem
, options
);
1889 // TODO: Set column width if item width > than current column width
1892 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
1894 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
1895 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
1898 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
1899 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
1901 long mask
= item
.GetMask();
1903 // by default, get everything for backwards compatibility
1906 if ( mask
& wxLIST_MASK_TEXT
)
1907 item
.SetText(oldItem
->GetText());
1908 if ( mask
& wxLIST_MASK_IMAGE
)
1909 item
.SetImage(oldItem
->GetImage());
1910 if ( mask
& wxLIST_MASK_DATA
)
1911 item
.SetData(oldItem
->GetData());
1912 if ( mask
& wxLIST_MASK_STATE
)
1913 item
.SetState(oldItem
->GetState());
1914 if ( mask
& wxLIST_MASK_WIDTH
)
1915 item
.SetWidth(oldItem
->GetWidth());
1916 if ( mask
& wxLIST_MASK_FORMAT
)
1917 item
.SetAlign(oldItem
->GetAlign());
1919 item
.SetTextColour(oldItem
->GetTextColour());
1920 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
1921 item
.SetFont(oldItem
->GetFont());
1925 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
1927 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
1928 MacSetColumnInfo(n
, 0, item
);
1931 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
1933 return new wxMacListCtrlItem();
1936 wxMacListCtrlItem::wxMacListCtrlItem()
1938 m_rowItems
= wxListItemList();
1941 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
1943 return GetColumnInfo(column
)->GetImage();
1946 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
1948 GetColumnInfo(column
)->SetImage(imageIndex
);
1951 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
1956 return GetColumnInfo(column
)->GetText();
1959 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
1961 GetColumnInfo(column
)->SetText(text
);
1963 // for compatibility with superclass APIs
1968 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
1970 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
1971 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
1973 return node
->GetData();
1976 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
1978 return m_rowItems
.GetCount() > column
;
1981 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
1984 if ( column
>= m_rowItems
.GetCount() )
1986 wxListItem
* listItem
= new wxListItem(*item
);
1987 m_rowItems
.Append( listItem
);
1991 wxListItem
* listItem
= GetColumnInfo( column
);
1992 long mask
= item
->GetMask();
1993 if (mask
& wxLIST_MASK_TEXT
)
1994 listItem
->SetText(item
->GetText());
1995 if (mask
& wxLIST_MASK_DATA
)
1996 listItem
->SetData(item
->GetData());
1997 if (mask
& wxLIST_MASK_IMAGE
)
1998 listItem
->SetImage(item
->GetImage());
1999 if (mask
& wxLIST_MASK_STATE
)
2000 listItem
->SetState(item
->GetState());
2001 if (mask
& wxLIST_MASK_FORMAT
)
2002 listItem
->SetAlign(item
->GetAlign());
2003 if (mask
& wxLIST_MASK_WIDTH
)
2004 listItem
->SetWidth(item
->GetWidth());
2008 #endif // wxUSE_LISTCTRL