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
)
118 WX_DEFINE_LIST(wxColumnList
)
120 // so we can check for column clicks
121 static const EventTypeSpec eventList
[] =
123 { kEventClassControl
, kEventControlHit
},
124 { kEventClassControl
, kEventControlDraw
}
127 static pascal OSStatus
wxMacListCtrlEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
129 OSStatus result
= eventNotHandledErr
;
131 wxMacCarbonEvent
cEvent( event
) ;
133 ControlRef controlRef
;
134 cEvent
.GetParameter( kEventParamDirectObject
, &controlRef
) ;
136 wxListCtrl
*window
= (wxListCtrl
*) data
;
137 wxListEvent
le( wxEVT_COMMAND_LIST_COL_CLICK
, window
->GetId() );
138 le
.SetEventObject( window
);
140 switch ( GetEventKind( event
) )
142 // check if the column was clicked on and fire an event if so
143 case kEventControlHit
:
145 ControlPartCode result
= cEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
, typeControlPartCode
) ;
146 if (result
== kControlButtonPart
){
147 DataBrowserPropertyID col
;
148 GetDataBrowserSortProperty(controlRef
, &col
);
149 int column
= col
- kMinColumnId
;
151 window
->GetEventHandler()->ProcessEvent( le
);
153 result
= CallNextEventHandler(handler
, event
);
156 case kEventControlDraw
:
158 CGContextRef context
= cEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
, typeCGContextRef
) ;
159 window
->MacSetDrawingContext(context
);
160 result
= CallNextEventHandler(handler
, event
);
161 window
->MacSetDrawingContext(NULL
);
172 DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler
)
174 class wxMacListCtrlItem
: public wxMacListBoxItem
179 virtual void Notification(wxMacDataItemBrowserControl
*owner
,
180 DataBrowserItemNotification message
,
181 DataBrowserItemDataRef itemData
) const;
183 virtual void SetColumnInfo( unsigned int column
, wxListItem
* item
);
184 virtual wxListItem
* GetColumnInfo( unsigned int column
);
185 virtual bool HasColumnInfo( unsigned int column
);
187 virtual void SetColumnTextValue( unsigned int column
, const wxString
& text
);
188 virtual const wxString
& GetColumnTextValue( unsigned int column
);
190 virtual int GetColumnImageValue( unsigned int column
);
191 virtual void SetColumnImageValue( unsigned int column
, int imageIndex
);
193 virtual ~wxMacListCtrlItem();
195 wxListItemList m_rowItems
;
198 DataBrowserDrawItemUPP gDataBrowserDrawItemUPP
= NULL
;
199 //DataBrowserEditItemUPP gDataBrowserEditItemUPP = NULL;
200 DataBrowserHitTestUPP gDataBrowserHitTestUPP
= NULL
;
202 // TODO: Make a better name!!
203 class wxMacDataBrowserListCtrlControl
: public wxMacDataItemBrowserControl
206 wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
207 virtual ~wxMacDataBrowserListCtrlControl();
209 // create a list item (can be a subclass of wxMacListBoxItem)
211 virtual wxMacDataItem
* CreateItem();
213 virtual void MacInsertItem( unsigned int n
, wxListItem
* item
);
214 virtual void MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
);
215 virtual void MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
);
216 virtual void UpdateState(wxMacDataItem
* dataItem
, wxListItem
* item
);
219 // we need to override to provide specialized handling for virtual wxListCtrls
220 virtual OSStatus
GetSetItemData(DataBrowserItemID itemID
,
221 DataBrowserPropertyID property
,
222 DataBrowserItemDataRef itemData
,
223 Boolean changeValue
);
225 virtual void ItemNotification(
226 DataBrowserItemID itemID
,
227 DataBrowserItemNotification message
,
228 DataBrowserItemDataRef itemData
);
230 virtual Boolean
CompareItems(DataBrowserItemID itemOneID
,
231 DataBrowserItemID itemTwoID
,
232 DataBrowserPropertyID sortProperty
);
234 static pascal void DataBrowserDrawItemProc(ControlRef browser
,
235 DataBrowserItemID item
,
236 DataBrowserPropertyID property
,
237 DataBrowserItemState itemState
,
240 Boolean colorDevice
);
242 virtual void DrawItem(DataBrowserItemID itemID
,
243 DataBrowserPropertyID property
,
244 DataBrowserItemState itemState
,
245 const Rect
*itemRect
,
247 Boolean colorDevice
);
249 static pascal Boolean
DataBrowserEditTextProc(ControlRef browser
,
250 DataBrowserItemID item
,
251 DataBrowserPropertyID property
,
252 CFStringRef theString
,
253 Rect
*maxEditTextRect
,
254 Boolean
*shrinkToFit
);
256 static pascal Boolean
DataBrowserHitTestProc(ControlRef browser
,
257 DataBrowserItemID itemID
,
258 DataBrowserPropertyID property
,
260 const Rect
*mouseRect
) { return true; }
262 virtual bool ConfirmEditText(DataBrowserItemID item
,
263 DataBrowserPropertyID property
,
264 CFStringRef theString
,
265 Rect
*maxEditTextRect
,
266 Boolean
*shrinkToFit
);
270 wxClientDataType m_clientDataItemsType
;
275 class wxMacListCtrlEventDelegate
: public wxEvtHandler
278 wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
);
279 virtual bool ProcessEvent( wxEvent
& event
);
286 wxMacListCtrlEventDelegate::wxMacListCtrlEventDelegate( wxListCtrl
* list
, int id
)
292 bool wxMacListCtrlEventDelegate::ProcessEvent( wxEvent
& event
)
294 // even though we use a generic list ctrl underneath, make sure
295 // we present ourselves as wxListCtrl.
296 event
.SetEventObject( m_list
);
299 if ( !event
.IsKindOf( CLASSINFO( wxCommandEvent
) ) )
301 if (m_list
->GetEventHandler()->ProcessEvent( event
))
304 return wxEvtHandler::ProcessEvent(event
);
307 // ============================================================================
309 // ============================================================================
311 wxMacListControl
* wxListCtrl::GetPeer() const
313 return dynamic_cast<wxMacListControl
*>(m_peer
);
316 // ----------------------------------------------------------------------------
317 // wxListCtrl construction
318 // ----------------------------------------------------------------------------
320 void wxListCtrl::Init()
322 m_imageListNormal
= NULL
;
323 m_imageListSmall
= NULL
;
324 m_imageListState
= NULL
;
326 // keep track of if we created our own image lists, or if they were assigned
328 m_ownsImageListNormal
= m_ownsImageListSmall
= m_ownsImageListState
= false;
332 m_genericImpl
= NULL
;
334 m_compareFunc
= NULL
;
335 m_compareFuncData
= 0;
336 m_colsInfo
= wxColumnList();
337 m_textColor
= wxNullColour
;
338 m_bgColor
= wxNullColour
;
341 class wxGenericListCtrlHook
: public wxGenericListCtrl
344 wxGenericListCtrlHook(wxListCtrl
* parent
,
349 const wxValidator
& validator
,
350 const wxString
& name
)
351 : wxGenericListCtrl(parent
, id
, pos
, size
, style
, validator
, name
),
352 m_nativeListCtrl(parent
)
357 virtual wxListItemAttr
* OnGetItemAttr(long item
) const
359 return m_nativeListCtrl
->OnGetItemAttr(item
);
362 virtual int OnGetItemImage(long item
) const
364 return m_nativeListCtrl
->OnGetItemImage(item
);
367 virtual int OnGetItemColumnImage(long item
, long column
) const
369 return m_nativeListCtrl
->OnGetItemColumnImage(item
, column
);
372 virtual wxString
OnGetItemText(long item
, long column
) const
374 return m_nativeListCtrl
->OnGetItemText(item
, column
);
377 wxListCtrl
* m_nativeListCtrl
;
381 bool wxListCtrl::Create(wxWindow
*parent
,
386 const wxValidator
& validator
,
387 const wxString
& name
)
390 // for now, we'll always use the generic list control for ICON and LIST views,
391 // because they dynamically change the number of columns on resize.
392 // Also, allow the user to set it to use the list ctrl as well.
393 // Also, use generic list control in VIRTUAL mode.
394 if ( (wxSystemOptions::HasOption( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
)
395 && (wxSystemOptions::GetOptionInt( wxMAC_ALWAYS_USE_GENERIC_LISTCTRL
) == 1)) ||
396 (style
& wxLC_ICON
) || (style
& wxLC_SMALL_ICON
) || (style
& wxLC_LIST
) || (style
& wxLC_EDIT_LABELS
) )
398 m_macIsUserPane
= true;
400 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
402 m_genericImpl
= new wxGenericListCtrlHook(this, id
, pos
, size
, style
, validator
, name
);
403 m_genericImpl
->PushEventHandler( new wxMacListCtrlEventDelegate( this, GetId() ) );
409 m_macIsUserPane
= false;
411 if ( !wxWindow::Create(parent
, id
, pos
, size
, style
, name
) )
413 m_dbImpl
= new wxMacDataBrowserListCtrlControl( this, pos
, size
, style
);
416 MacPostControlCreate( pos
, size
);
418 InstallControlEventHandler( m_peer
->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
419 GetEventTypeCount(eventList
), eventList
, this,
420 (EventHandlerRef
*)&m_macListCtrlEventHandler
);
426 wxListCtrl::~wxListCtrl()
430 m_genericImpl
->PopEventHandler(/* deleteHandler = */ true);
433 if (m_ownsImageListNormal
)
434 delete m_imageListNormal
;
435 if (m_ownsImageListSmall
)
436 delete m_imageListSmall
;
437 if (m_ownsImageListState
)
438 delete m_imageListState
;
441 // ----------------------------------------------------------------------------
442 // set/get/change style
443 // ----------------------------------------------------------------------------
445 // Add or remove a single window style
446 void wxListCtrl::SetSingleStyle(long style
, bool add
)
448 long flag
= GetWindowStyleFlag();
450 // Get rid of conflicting styles
453 if ( style
& wxLC_MASK_TYPE
)
454 flag
= flag
& ~wxLC_MASK_TYPE
;
455 if ( style
& wxLC_MASK_ALIGN
)
456 flag
= flag
& ~wxLC_MASK_ALIGN
;
457 if ( style
& wxLC_MASK_SORT
)
458 flag
= flag
& ~wxLC_MASK_SORT
;
466 SetWindowStyleFlag(flag
);
469 // Set the whole window style
470 void wxListCtrl::SetWindowStyleFlag(long flag
)
472 if ( flag
!= m_windowStyle
)
474 m_windowStyle
= flag
;
478 m_genericImpl
->SetWindowStyleFlag(flag
);
485 void wxListCtrl::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
487 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);
490 m_genericImpl
->SetSize(x
, y
, width
, height
, sizeFlags
);
493 bool wxListCtrl::SetFont(const wxFont
& font
)
496 rv
= wxControl::SetFont(font
);
498 rv
= m_genericImpl
->SetFont(font
);
502 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
506 rv
= m_genericImpl
->SetForegroundColour(colour
);
508 SetTextColour(colour
);
512 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
516 rv
= m_genericImpl
->SetBackgroundColour(colour
);
522 wxColour
wxListCtrl::GetBackgroundColour()
525 return m_genericImpl
->GetBackgroundColour();
532 // ----------------------------------------------------------------------------
534 // ----------------------------------------------------------------------------
536 // Gets information about this column
537 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
540 return m_genericImpl
->GetColumn(col
, item
);
547 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
548 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
549 wxListItem
* column
= node
->GetData();
551 long mask
= column
->GetMask();
552 if (mask
& wxLIST_MASK_TEXT
)
553 item
.SetText(column
->GetText());
554 if (mask
& wxLIST_MASK_DATA
)
555 item
.SetData(column
->GetData());
556 if (mask
& wxLIST_MASK_IMAGE
)
557 item
.SetImage(column
->GetImage());
558 if (mask
& wxLIST_MASK_STATE
)
559 item
.SetState(column
->GetState());
560 if (mask
& wxLIST_MASK_FORMAT
)
561 item
.SetAlign(column
->GetAlign());
562 if (mask
& wxLIST_MASK_WIDTH
)
563 item
.SetWidth(column
->GetWidth());
569 // Sets information about this column
570 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
573 return m_genericImpl
->SetColumn(col
, item
);
577 if ( col
>= (int)m_colsInfo
.GetCount() )
579 wxListItem
* listItem
= new wxListItem(item
);
580 m_colsInfo
.Append( listItem
);
585 GetColumn( col
, listItem
);
586 long mask
= item
.GetMask();
587 if (mask
& wxLIST_MASK_TEXT
)
588 listItem
.SetText(item
.GetText());
589 if (mask
& wxLIST_MASK_DATA
)
590 listItem
.SetData(item
.GetData());
591 if (mask
& wxLIST_MASK_IMAGE
)
592 listItem
.SetImage(item
.GetImage());
593 if (mask
& wxLIST_MASK_STATE
)
594 listItem
.SetState(item
.GetState());
595 if (mask
& wxLIST_MASK_FORMAT
)
596 listItem
.SetAlign(item
.GetAlign());
597 if (mask
& wxLIST_MASK_WIDTH
)
598 listItem
.SetWidth(item
.GetWidth());
601 // change the appearance in the databrowser.
602 DataBrowserListViewHeaderDesc columnDesc
;
603 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
604 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
607 if (item.GetMask() & wxLIST_MASK_TEXT)
611 enc = m_font.GetEncoding();
613 enc = wxLocale::GetSystemEncoding();
614 wxMacCFStringHolder cfTitle;
615 cfTitle.Assign( item.GetText() , enc );
616 if(columnDesc.titleString)
617 CFRelease(columnDesc.titleString);
618 columnDesc.titleString = cfTitle;
622 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
624 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
625 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
626 if (imageList
&& imageList
->GetImageCount() > 0 )
628 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
629 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
630 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
634 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
640 int wxListCtrl::GetColumnCount() const
643 return m_genericImpl
->GetColumnCount();
648 m_dbImpl
->GetColumnCount(&count
);
655 // Gets the column width
656 int wxListCtrl::GetColumnWidth(int col
) const
659 return m_genericImpl
->GetColumnWidth(col
);
663 return m_dbImpl
->GetColumnWidth(col
);
669 // Sets the column width
670 bool wxListCtrl::SetColumnWidth(int col
, int width
)
673 return m_genericImpl
->SetColumnWidth(col
, width
);
678 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
683 for (int column
= 0; column
< GetColumnCount(); column
++)
685 m_dbImpl
->SetColumnWidth(col
, mywidth
);
689 m_dbImpl
->SetColumnWidth(col
, mywidth
);
697 // Gets the number of items that can fit vertically in the
698 // visible area of the list control (list or report view)
699 // or the total number of items in the list control (icon
700 // or small icon view)
701 int wxListCtrl::GetCountPerPage() const
704 return m_genericImpl
->GetCountPerPage();
713 // Gets the edit control for editing labels.
714 wxTextCtrl
* wxListCtrl::GetEditControl() const
717 return m_genericImpl
->GetEditControl();
722 // Gets information about the item
723 bool wxListCtrl::GetItem(wxListItem
& info
) const
726 return m_genericImpl
->GetItem(info
);
731 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
734 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
735 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
736 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
739 info
.SetFont( attrs
->GetFont() );
740 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
741 info
.SetTextColour( attrs
->GetTextColour() );
749 // Sets information about the item
750 bool wxListCtrl::SetItem(wxListItem
& info
)
753 return m_genericImpl
->SetItem(info
);
756 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
761 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
764 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
768 info
.m_mask
= wxLIST_MASK_TEXT
;
769 info
.m_itemId
= index
;
773 info
.m_image
= imageId
;
774 info
.m_mask
|= wxLIST_MASK_IMAGE
;
776 return SetItem(info
);
780 // Gets the item state
781 int wxListCtrl::GetItemState(long item
, long stateMask
) const
784 return m_genericImpl
->GetItemState(item
, stateMask
);
788 info
.m_mask
= wxLIST_MASK_STATE
;
789 info
.m_stateMask
= stateMask
;
790 info
.m_itemId
= item
;
798 // Sets the item state
799 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
802 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
805 info
.m_mask
= wxLIST_MASK_STATE
;
806 info
.m_stateMask
= stateMask
;
807 info
.m_state
= state
;
808 info
.m_itemId
= item
;
809 return SetItem(info
);
812 // Sets the item image
813 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
815 return SetItemColumnImage(item
, 0, image
);
818 // Sets the item image
819 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
822 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
826 info
.m_mask
= wxLIST_MASK_IMAGE
;
827 info
.m_image
= image
;
828 info
.m_itemId
= item
;
831 return SetItem(info
);
834 // Gets the item text
835 wxString
wxListCtrl::GetItemText(long item
) const
838 return m_genericImpl
->GetItemText(item
);
842 info
.m_mask
= wxLIST_MASK_TEXT
;
843 info
.m_itemId
= item
;
846 return wxEmptyString
;
850 // Sets the item text
851 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
854 return m_genericImpl
->SetItemText(item
, str
);
858 info
.m_mask
= wxLIST_MASK_TEXT
;
859 info
.m_itemId
= item
;
865 // Gets the item data
866 long wxListCtrl::GetItemData(long item
) const
869 return m_genericImpl
->GetItemData(item
);
873 info
.m_mask
= wxLIST_MASK_DATA
;
874 info
.m_itemId
= item
;
881 // Sets the item data
882 bool wxListCtrl::SetItemData(long item
, long data
)
885 return m_genericImpl
->SetItemData(item
, data
);
889 info
.m_mask
= wxLIST_MASK_DATA
;
890 info
.m_itemId
= item
;
893 return SetItem(info
);
896 wxRect
wxListCtrl::GetViewRect() const
898 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
899 _T("wxListCtrl::GetViewRect() only works in icon mode") );
902 return m_genericImpl
->GetViewRect();
908 // Gets the item rectangle
909 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
912 return m_genericImpl
->GetItemRect(item
, rect
, code
);
917 DataBrowserItemID id
;
918 DataBrowserPropertyID col
= kMinColumnId
;
920 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
921 if ( code
== wxLIST_RECT_LABEL
)
922 part
= kDataBrowserPropertyTextPart
;
923 else if ( code
== wxLIST_RECT_ICON
)
924 part
= kDataBrowserPropertyIconPart
;
926 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
928 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
929 id
= (DataBrowserItemID
) thisItem
;
934 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
936 rect
.x
= bounds
.left
;
938 rect
.width
= GetClientSize().x
; // we need the width of the whole row, not just the item.
939 rect
.height
= bounds
.bottom
- bounds
.top
;
944 // Gets the item position
945 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
948 return m_genericImpl
->GetItemPosition(item
, pos
);
950 bool success
= false;
955 GetItemRect(item
, itemRect
);
956 pos
= itemRect
.GetPosition();
963 // Sets the item position.
964 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
967 return m_genericImpl
->SetItemPosition(item
, pos
);
972 // Gets the number of items in the list control
973 int wxListCtrl::GetItemCount() const
976 return m_genericImpl
->GetItemCount();
979 return m_dbImpl
->MacGetCount();
984 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
987 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
990 wxSize
wxListCtrl::GetItemSpacing() const
993 return m_genericImpl
->GetItemSpacing();
998 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1002 m_genericImpl
->SetItemTextColour(item
, col
);
1007 info
.m_itemId
= item
;
1008 info
.SetTextColour( col
);
1012 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1015 return m_genericImpl
->GetItemTextColour(item
);
1021 return info
.GetTextColour();
1023 return wxNullColour
;
1026 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1030 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1035 info
.m_itemId
= item
;
1036 info
.SetBackgroundColour( col
);
1040 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1043 return m_genericImpl
->GetItemBackgroundColour(item
);
1049 return info
.GetBackgroundColour();
1051 return wxNullColour
;
1054 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1058 m_genericImpl
->SetItemFont(item
, f
);
1063 info
.m_itemId
= item
;
1068 wxFont
wxListCtrl::GetItemFont( long item
) const
1071 return m_genericImpl
->GetItemFont(item
);
1077 return info
.GetFont();
1083 // Gets the number of selected items in the list control
1084 int wxListCtrl::GetSelectedItemCount() const
1087 return m_genericImpl
->GetSelectedItemCount();
1090 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1095 // Gets the text colour of the listview
1096 wxColour
wxListCtrl::GetTextColour() const
1099 return m_genericImpl
->GetTextColour();
1101 // TODO: we need owner drawn list items to customize text color.
1105 return wxNullColour
;
1108 // Sets the text colour of the listview
1109 void wxListCtrl::SetTextColour(const wxColour
& col
)
1113 m_genericImpl
->SetTextColour(col
);
1121 // Gets the index of the topmost visible item when in
1122 // list or report view
1123 long wxListCtrl::GetTopItem() const
1126 return m_genericImpl
->GetTopItem();
1131 // Searches for an item, starting from 'item'.
1132 // 'geometry' is one of
1133 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1134 // 'state' is a state bit flag, one or more of
1135 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1136 // item can be -1 to find the first item that matches the
1138 // Returns the item or -1 if unsuccessful.
1139 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1142 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1144 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1146 long count
= m_dbImpl
->MacGetCount() ;
1147 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1149 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1150 if ( m_dbImpl
->IsItemSelected(id
) )
1160 wxImageList
*wxListCtrl::GetImageList(int which
) const
1163 return m_genericImpl
->GetImageList(which
);
1165 if ( which
== wxIMAGE_LIST_NORMAL
)
1167 return m_imageListNormal
;
1169 else if ( which
== wxIMAGE_LIST_SMALL
)
1171 return m_imageListSmall
;
1173 else if ( which
== wxIMAGE_LIST_STATE
)
1175 return m_imageListState
;
1180 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1184 m_genericImpl
->SetImageList(imageList
, which
);
1188 if ( which
== wxIMAGE_LIST_NORMAL
)
1190 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1191 m_imageListNormal
= imageList
;
1192 m_ownsImageListNormal
= false;
1194 else if ( which
== wxIMAGE_LIST_SMALL
)
1196 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1197 m_imageListSmall
= imageList
;
1198 m_ownsImageListSmall
= false;
1200 else if ( which
== wxIMAGE_LIST_STATE
)
1202 if (m_ownsImageListState
) delete m_imageListState
;
1203 m_imageListState
= imageList
;
1204 m_ownsImageListState
= false;
1208 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1212 m_genericImpl
->AssignImageList(imageList
, which
);
1216 SetImageList(imageList
, which
);
1217 if ( which
== wxIMAGE_LIST_NORMAL
)
1218 m_ownsImageListNormal
= true;
1219 else if ( which
== wxIMAGE_LIST_SMALL
)
1220 m_ownsImageListSmall
= true;
1221 else if ( which
== wxIMAGE_LIST_STATE
)
1222 m_ownsImageListState
= true;
1225 // ----------------------------------------------------------------------------
1227 // ----------------------------------------------------------------------------
1229 // Arranges the items
1230 bool wxListCtrl::Arrange(int flag
)
1233 return m_genericImpl
->Arrange(flag
);
1238 bool wxListCtrl::DeleteItem(long item
)
1241 return m_genericImpl
->DeleteItem(item
);
1245 m_dbImpl
->MacDelete(item
);
1246 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1247 event
.SetEventObject( this );
1248 event
.m_itemIndex
= item
;
1249 GetEventHandler()->ProcessEvent( event
);
1255 // Deletes all items
1256 bool wxListCtrl::DeleteAllItems()
1259 return m_genericImpl
->DeleteAllItems();
1263 m_dbImpl
->MacClear();
1264 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1265 event
.SetEventObject( this );
1266 GetEventHandler()->ProcessEvent( event
);
1271 // Deletes all items
1272 bool wxListCtrl::DeleteAllColumns()
1275 return m_genericImpl
->DeleteAllColumns();
1280 m_dbImpl
->GetColumnCount(&cols
);
1281 for (UInt32 col
= 0; col
< cols
; col
++)
1291 bool wxListCtrl::DeleteColumn(int col
)
1294 return m_genericImpl
->DeleteColumn(col
);
1298 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1299 return err
== noErr
;
1305 // Clears items, and columns if there are any.
1306 void wxListCtrl::ClearAll()
1310 m_genericImpl
->ClearAll();
1321 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1324 return m_genericImpl
->EditLabel(item
, textControlClass
);
1328 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(item
);
1329 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)id
, kMinColumnId
) );
1334 // End label editing, optionally cancelling the edit
1335 bool wxListCtrl::EndEditLabel(bool cancel
)
1337 // TODO: generic impl. doesn't have this method - is it needed for us?
1339 return true; // m_genericImpl->EndEditLabel(cancel);
1342 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1346 // Ensures this item is visible
1347 bool wxListCtrl::EnsureVisible(long item
)
1350 return m_genericImpl
->EnsureVisible(item
);
1354 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1355 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1361 // Find an item whose label matches this string, starting from the item after 'start'
1362 // or the beginning if 'start' is -1.
1363 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1366 return m_genericImpl
->FindItem(start
, str
, partial
);
1371 // Find an item whose data matches this data, starting from the item after 'start'
1372 // or the beginning if 'start' is -1.
1373 long wxListCtrl::FindItem(long start
, long data
)
1376 return m_genericImpl
->FindItem(start
, data
);
1378 long idx
= start
+ 1;
1379 long count
= GetItemCount();
1383 if (GetItemData(idx
) == data
)
1391 // Find an item nearest this position in the specified direction, starting from
1392 // the item after 'start' or the beginning if 'start' is -1.
1393 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1396 return m_genericImpl
->FindItem(start
, pt
, direction
);
1400 // Determines which item (if any) is at the specified point,
1401 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1403 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1406 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1408 flags
= wxLIST_HITTEST_NOWHERE
;
1411 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1412 UInt16 rowHeight
= 0;
1413 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1416 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1417 y
-= colHeaderHeight
;
1419 int row
= y
/ rowHeight
;
1420 DataBrowserItemID id
;
1421 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1423 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1424 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1426 wxMacListCtrlItem
* lcItem
;
1427 lcItem
= (wxMacListCtrlItem
*) id
;
1430 flags
= wxLIST_HITTEST_ONITEM
;
1436 if (row
< GetItemCount() )
1438 flags
= wxLIST_HITTEST_ONITEM
;
1448 // Inserts an item, returning the index of the new item if successful,
1450 long wxListCtrl::InsertItem(wxListItem
& info
)
1452 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1455 return m_genericImpl
->InsertItem(info
);
1459 int count
= GetItemCount();
1461 if (info
.m_itemId
> count
)
1462 info
.m_itemId
= count
;
1464 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1465 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1466 event
.SetEventObject( this );
1467 event
.m_itemIndex
= info
.m_itemId
;
1468 GetEventHandler()->ProcessEvent( event
);
1471 return info
.m_itemId
;
1474 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1477 return m_genericImpl
->InsertItem(index
, label
);
1480 info
.m_text
= label
;
1481 info
.m_mask
= wxLIST_MASK_TEXT
;
1482 info
.m_itemId
= index
;
1483 return InsertItem(info
);
1486 // Inserts an image item
1487 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1490 return m_genericImpl
->InsertItem(index
, imageIndex
);
1493 info
.m_image
= imageIndex
;
1494 info
.m_mask
= wxLIST_MASK_IMAGE
;
1495 info
.m_itemId
= index
;
1496 return InsertItem(info
);
1499 // Inserts an image/string item
1500 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1503 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1506 info
.m_image
= imageIndex
;
1507 info
.m_text
= label
;
1508 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1509 info
.m_itemId
= index
;
1510 return InsertItem(info
);
1513 // For list view mode (only), inserts a column.
1514 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1517 return m_genericImpl
->InsertColumn(col
, item
);
1521 int width
= item
.GetWidth();
1522 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1525 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1526 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1527 if (imageList
&& imageList
->GetImageCount() > 0)
1529 wxBitmap bmp
= imageList
->GetBitmap(0);
1531 // type = kDataBrowserIconAndTextType;
1534 SInt16 just
= teFlushDefault
;
1535 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1537 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1539 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1541 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1542 just
= teFlushRight
;
1544 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1545 SetColumn(col
, item
);
1547 // set/remove options based on the wxListCtrl type.
1548 DataBrowserTableViewColumnID id
;
1549 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1550 DataBrowserPropertyFlags flags
;
1551 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1552 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1553 flags
|= kDataBrowserPropertyIsEditable
;
1555 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1556 flags
&= ~kDataBrowserListViewSortableColumn
;
1558 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1564 long wxListCtrl::InsertColumn(long col
,
1565 const wxString
& heading
,
1570 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1573 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1574 item
.m_text
= heading
;
1577 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1578 item
.m_width
= width
;
1580 item
.m_format
= format
;
1582 return InsertColumn(col
, item
);
1585 // scroll the control by the given number of pixels (exception: in list view,
1586 // dx is interpreted as number of columns)
1587 bool wxListCtrl::ScrollList(int dx
, int dy
)
1590 return m_genericImpl
->ScrollList(dx
, dy
);
1594 m_dbImpl
->SetScrollPosition(dx
, dy
);
1600 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1603 return m_genericImpl
->SortItems(fn
, data
);
1608 m_compareFuncData
= data
;
1614 // ----------------------------------------------------------------------------
1615 // virtual list controls
1616 // ----------------------------------------------------------------------------
1618 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1620 // this is a pure virtual function, in fact - which is not really pure
1621 // because the controls which are not virtual don't need to implement it
1622 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1624 return wxEmptyString
;
1627 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1629 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1631 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1635 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1638 return OnGetItemImage(item
);
1643 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1645 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1646 _T("invalid item index in OnGetItemAttr()") );
1648 // no attributes by default
1652 void wxListCtrl::SetItemCount(long count
)
1654 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1658 m_genericImpl
->SetItemCount(count
);
1664 // we need to temporarily disable the new item creation notification
1665 // procedure to speed things up
1666 // FIXME: Even this doesn't seem to help much...
1667 DataBrowserCallbacks callbacks
;
1668 DataBrowserItemNotificationUPP itemUPP
;
1669 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
1670 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
1671 callbacks
.u
.v1
.itemNotificationCallback
= 0;
1672 m_dbImpl
->SetCallbacks(&callbacks
);
1673 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
1674 count
, NULL
, kDataBrowserItemNoProperty
);
1675 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
1676 m_dbImpl
->SetCallbacks(&callbacks
);
1681 void wxListCtrl::RefreshItem(long item
)
1685 m_genericImpl
->RefreshItem(item
);
1690 GetItemRect(item
, rect
);
1694 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1698 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1702 wxRect rect1
, rect2
;
1703 GetItemRect(itemFrom
, rect1
);
1704 GetItemRect(itemTo
, rect2
);
1706 wxRect rect
= rect1
;
1707 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
1713 // wxMac internal data structures
1715 wxMacListCtrlItem::~wxMacListCtrlItem()
1719 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
1720 DataBrowserItemNotification message
,
1721 DataBrowserItemDataRef itemData
) const
1724 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
1726 // we want to depend on as little as possible to make sure tear-down of controls is safe
1727 if ( message
== kDataBrowserItemRemoved
)
1729 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
1731 delete (wxClientData
*) (m_data
);
1737 else if ( message
== kDataBrowserItemAdded
)
1739 // we don't issue events on adding, the item is not really stored in the list yet, so we
1740 // avoid asserts by gettting out now
1744 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1747 bool trigger
= false;
1749 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1750 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
1752 event
.SetEventObject( list
);
1753 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
1754 if ( !list
->IsVirtual() )
1756 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1761 case kDataBrowserItemDeselected
:
1762 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1764 trigger
= !lb
->IsSelectionSuppressed();
1767 case kDataBrowserItemSelected
:
1768 trigger
= !lb
->IsSelectionSuppressed();
1771 case kDataBrowserItemDoubleClicked
:
1772 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1776 case kDataBrowserEditStarted
:
1777 // TODO : how to veto ?
1778 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
1782 case kDataBrowserEditStopped
:
1783 // TODO probably trigger only upon the value store callback, because
1784 // here IIRC we cannot veto
1785 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
1795 // direct notification is not always having the listbox GetSelection() having in synch with event
1796 wxPostEvent( list
->GetEventHandler(), event
);
1802 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
1803 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
1805 OSStatus err
= noErr
;
1806 m_clientDataItemsType
= wxClientData_None
;
1807 m_isVirtual
= false;
1809 if ( style
& wxLC_VIRTUAL
)
1812 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
1813 if ( style
& wxLC_SINGLE_SEL
)
1815 options
|= kDataBrowserSelectOnlyOne
;
1819 options
|= kDataBrowserCmdTogglesSelection
;
1822 err
= SetSelectionFlags( options
);
1823 verify_noerr( err
);
1825 DataBrowserCustomCallbacks callbacks
;
1826 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
1828 if ( gDataBrowserDrawItemUPP
== NULL
)
1829 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
1831 // if ( gDataBrowserEditItemUPP == NULL )
1832 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
1834 if ( gDataBrowserHitTestUPP
== NULL
)
1835 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
1837 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
1838 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
1839 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
1841 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
1843 if ( style
& wxLC_LIST
)
1845 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
1846 verify_noerr( AutoSizeColumns() );
1849 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
1850 verify_noerr( SetHeaderButtonHeight( 0 ) );
1853 SetSortProperty( kMinColumnId
- 1 );
1855 SetSortProperty( kMinColumnId
);
1856 if ( style
& wxLC_SORT_ASCENDING
)
1858 m_sortOrder
= SortOrder_Text_Ascending
;
1859 SetSortOrder( kDataBrowserOrderIncreasing
);
1861 else if ( style
& wxLC_SORT_DESCENDING
)
1863 m_sortOrder
= SortOrder_Text_Descending
;
1864 SetSortOrder( kDataBrowserOrderDecreasing
);
1868 m_sortOrder
= SortOrder_None
;
1871 if ( style
& wxLC_VRULES
)
1873 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1874 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
1878 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
1879 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
1882 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
1884 DataBrowserItemID itemID
,
1885 DataBrowserPropertyID property
,
1886 CFStringRef theString
,
1887 Rect
*maxEditTextRect
,
1888 Boolean
*shrinkToFit
)
1890 Boolean result
= false;
1891 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1894 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
1895 theString
= CFSTR("Hello!");
1900 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
1901 DataBrowserItemID itemID
,
1902 DataBrowserPropertyID property
,
1903 CFStringRef theString
,
1904 Rect
*maxEditTextRect
,
1905 Boolean
*shrinkToFit
)
1907 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
1911 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
1913 DataBrowserItemID itemID
,
1914 DataBrowserPropertyID property
,
1915 DataBrowserItemState itemState
,
1916 const Rect
*itemRect
,
1918 Boolean colorDevice
)
1920 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1923 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
1927 // routines needed for DrawItem
1932 kTextBoxHeight
= 14,
1933 kIconTextSpacingV
= 2,
1935 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
1938 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
1941 float iconH
, iconW
= 0;
1942 float padding
= kItemPadding
;
1945 iconH
= kIconHeight
;
1947 padding
= padding
*2;
1950 textBottom
= inItemRect
.origin
.y
;
1952 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
1953 textBottom
+ kIconTextSpacingV
, kIconWidth
,
1956 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
1957 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
1958 inItemRect
.size
.height
- kIconTextSpacingV
);
1961 void wxMacDataBrowserListCtrlControl::DrawItem(
1962 DataBrowserItemID itemID
,
1963 DataBrowserPropertyID property
,
1964 DataBrowserItemState itemState
,
1965 const Rect
*itemRect
,
1967 Boolean colorDevice
)
1970 wxFont font
= wxNullFont
;
1972 short listColumn
= property
- kMinColumnId
;
1974 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1975 wxMacListCtrlItem
* lcItem
;
1976 wxColour color
= *wxBLACK
;
1977 wxColour bgColor
= wxNullColour
;
1979 if (listColumn
>= 0)
1983 lcItem
= (wxMacListCtrlItem
*) itemID
;
1984 if (lcItem
->HasColumnInfo(listColumn
)){
1985 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
1987 // we always use the 0 column to get font and text/background colors.
1988 if (lcItem
->HasColumnInfo(0))
1990 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
1991 color
= firstItem
->GetTextColour();
1992 bgColor
= firstItem
->GetBackgroundColour();
1993 font
= firstItem
->GetFont();
1996 if (item
->GetMask() & wxLIST_MASK_TEXT
)
1997 text
= item
->GetText();
1998 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
1999 imgIndex
= item
->GetImage();
2005 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2006 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2007 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2010 if (attrs
->HasBackgroundColour())
2011 bgColor
= attrs
->GetBackgroundColour();
2012 if (attrs
->HasTextColour())
2013 color
= attrs
->GetTextColour();
2014 if (attrs
->HasFont())
2015 font
= attrs
->GetFont();
2020 wxColour listBgColor
= list
->GetBackgroundColour();
2021 if (bgColor
== wxNullColour
)
2022 bgColor
= listBgColor
;
2024 wxFont listFont
= list
->GetFont();
2025 if (font
== wxNullFont
)
2028 wxMacCFStringHolder cfString
;
2029 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2032 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2034 ThemeDrawingState savedState
= NULL
;
2035 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2036 RGBColor labelColor
;
2038 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2041 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2043 enclosingRect
.right
- enclosingRect
.left
,
2044 enclosingRect
.bottom
- enclosingRect
.top
);
2046 active
= IsControlActive(GetControlRef());
2048 if (itemState
== kDataBrowserItemIsSelected
)
2050 RGBColor foregroundColor
;
2052 GetThemeDrawingState(&savedState
);
2054 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &foregroundColor
);
2055 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2057 CGContextSaveGState(context
);
2059 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2060 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2061 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2062 CGContextFillRect(context
, enclosingCGRect
);
2064 CGContextRestoreGState(context
);
2070 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2071 else if (list
->GetTextColour().Ok())
2072 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2076 labelColor
.green
= 0;
2077 labelColor
.blue
= 0;
2082 RGBColor foregroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2083 CGContextSaveGState(context
);
2085 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2086 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2087 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2088 CGContextFillRect(context
, enclosingCGRect
);
2090 CGContextRestoreGState(context
);
2094 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2098 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2099 if (imageList
&& imageList
->GetImageCount() > 0){
2100 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2101 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2105 iconLabel
.green
= 0;
2108 CGContextSaveGState(context
);
2109 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2110 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2111 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2112 active
? kTransformNone
: kTransformDisabled
, &iconLabel
,
2113 kPlotIconRefNormalFlags
, icon
);
2115 CGContextRestoreGState(context
);
2119 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2120 UInt16 fontID
= kThemeViewsFont
;
2124 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2125 fontID
= font
.MacGetThemeFontID();
2127 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2129 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2130 ::TextFace( font
.MacGetFontStyle() ) ;
2135 list
->GetColumn(listColumn
, item
);
2136 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2138 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2139 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2140 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2141 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2142 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2144 hFlush
= kHIThemeTextHorizontalFlushRight
;
2145 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2149 HIThemeTextInfo info
;
2150 info
.version
= kHIThemeTextInfoVersionZero
;
2151 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2152 info
.fontID
= fontID
;
2153 info
.horizontalFlushness
= hFlush
;
2154 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2155 info
.options
= kHIThemeTextBoxOptionNone
;
2156 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2157 info
.truncationMaxLines
= 1;
2159 CGContextSaveGState(context
);
2160 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2161 (float)labelColor
.green
/ (float)USHRT_MAX
,
2162 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2164 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2166 CGContextRestoreGState(context
);
2168 if (savedState
!= NULL
)
2169 SetThemeDrawingState(savedState
, true);
2172 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2173 DataBrowserPropertyID property
,
2174 DataBrowserItemDataRef itemData
,
2175 Boolean changeValue
)
2179 short listColumn
= property
- kMinColumnId
;
2181 OSStatus err
= errDataBrowserPropertyNotSupported
;
2182 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2183 wxMacListCtrlItem
* lcItem
;
2185 if (listColumn
>= 0)
2189 lcItem
= (wxMacListCtrlItem
*) itemID
;
2190 if (lcItem
->HasColumnInfo(listColumn
)){
2191 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2192 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2193 text
= item
->GetText();
2194 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2195 imgIndex
= item
->GetImage();
2200 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2201 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2209 case kDataBrowserItemIsEditableProperty
:
2210 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2212 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2217 if ( property
>= kMinColumnId
)
2219 wxMacCFStringHolder cfStr
;
2222 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2223 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2229 if ( imgIndex
!= -1 )
2231 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2232 if (imageList
&& imageList
->GetImageCount() > 0){
2233 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2234 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2235 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2249 if ( property
>= kMinColumnId
)
2251 short listColumn
= property
- kMinColumnId
;
2253 // TODO probably send the 'end edit' from here, as we
2254 // can then deal with the veto
2256 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2257 wxMacCFStringHolder
cfStr(sr
) ;;
2259 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2263 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2273 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2274 DataBrowserItemNotification message
,
2275 DataBrowserItemDataRef itemData
)
2277 // we want to depend on as little as possible to make sure tear-down of controls is safe
2278 if ( message
== kDataBrowserItemRemoved
)
2280 // make sure MacDelete does the proper teardown.
2283 else if ( message
== kDataBrowserItemAdded
)
2285 // we don't issue events on adding, the item is not really stored in the list yet, so we
2286 // avoid asserts by getting out now
2290 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2293 bool trigger
= false;
2295 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2296 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2298 event
.SetEventObject( list
);
2299 if ( !list
->IsVirtual() )
2301 DataBrowserTableViewRowIndex result
= 0;
2302 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2303 event
.m_itemIndex
= result
;
2305 if (event
.m_itemIndex
>= 0)
2306 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2310 event
.m_itemIndex
= (long)itemID
;
2315 case kDataBrowserItemDeselected
:
2316 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2318 trigger
= !IsSelectionSuppressed();
2321 case kDataBrowserItemSelected
:
2322 trigger
= !IsSelectionSuppressed();
2326 case kDataBrowserItemDoubleClicked
:
2327 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2331 case kDataBrowserEditStarted
:
2332 // TODO : how to veto ?
2333 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2337 case kDataBrowserEditStopped
:
2338 // TODO probably trigger only upon the value store callback, because
2339 // here IIRC we cannot veto
2340 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2350 // direct notification is not always having the listbox GetSelection() having in synch with event
2351 wxPostEvent( list
->GetEventHandler(), event
);
2356 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2357 DataBrowserItemID itemTwoID
,
2358 DataBrowserPropertyID sortProperty
)
2361 bool retval
= false;
2363 wxString otherItemText
;
2364 int colId
= sortProperty
- kMinColumnId
;
2366 long otherItemNum
= 0;
2368 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2375 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2376 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2377 wxListCtrlCompare func
= list
->GetCompareFunc();
2378 if (func
!= NULL
&& item
->HasColumnInfo(colId
) && otherItem
->HasColumnInfo(colId
))
2379 return func(item
->GetColumnInfo(colId
)->GetData(), otherItem
->GetColumnInfo(colId
)->GetData(), list
->GetCompareFuncData()) >= 0;
2381 itemNum
= item
->GetOrder();
2382 otherItemNum
= otherItem
->GetOrder();
2383 if (item
->HasColumnInfo(colId
))
2384 itemText
= item
->GetColumnInfo(colId
)->GetText();
2385 if (otherItem
->HasColumnInfo(colId
))
2386 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
2390 itemNum
= (long)itemOneID
;
2391 otherItemNum
= (long)itemTwoID
;
2392 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2393 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2397 DataBrowserSortOrder sort
;
2398 verify_noerr(GetSortOrder(&sort
));
2400 if ( sort
== kDataBrowserOrderIncreasing
)
2402 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2404 else if ( sort
== kDataBrowserOrderDecreasing
)
2406 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2410 // fallback for undefined cases
2411 retval
= itemOneID
< itemTwoID
;
2417 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2421 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2423 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2426 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2427 listItem
->SetColumnInfo( column
, item
);
2428 UpdateState(dataItem
, item
);
2432 // apply changes that need to happen immediately, rather than when the
2433 // databrowser control fires a callback.
2434 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2436 bool isSelected
= IsItemSelected( dataItem
);
2437 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2439 // toggle the selection state if wxListInfo state and actual state don't match.
2440 if ( isSelected
!= isSelectedState
)
2442 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2443 if (!isSelectedState
)
2444 options
= kDataBrowserItemsRemove
;
2445 SetSelectedItem(dataItem
, options
);
2447 // TODO: Set column width if item width > than current column width
2450 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2452 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2453 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2456 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2457 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2459 long mask
= item
.GetMask();
2461 // by default, get everything for backwards compatibility
2464 if ( mask
& wxLIST_MASK_TEXT
)
2465 item
.SetText(oldItem
->GetText());
2466 if ( mask
& wxLIST_MASK_IMAGE
)
2467 item
.SetImage(oldItem
->GetImage());
2468 if ( mask
& wxLIST_MASK_DATA
)
2469 item
.SetData(oldItem
->GetData());
2470 if ( mask
& wxLIST_MASK_STATE
)
2471 item
.SetState(oldItem
->GetState());
2472 if ( mask
& wxLIST_MASK_WIDTH
)
2473 item
.SetWidth(oldItem
->GetWidth());
2474 if ( mask
& wxLIST_MASK_FORMAT
)
2475 item
.SetAlign(oldItem
->GetAlign());
2477 item
.SetTextColour(oldItem
->GetTextColour());
2478 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2479 item
.SetFont(oldItem
->GetFont());
2483 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
2485 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
2486 MacSetColumnInfo(n
, 0, item
);
2489 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
2491 return new wxMacListCtrlItem();
2494 wxMacListCtrlItem::wxMacListCtrlItem()
2496 m_rowItems
= wxListItemList();
2499 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
2501 return GetColumnInfo(column
)->GetImage();
2504 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
2506 GetColumnInfo(column
)->SetImage(imageIndex
);
2509 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
2514 return GetColumnInfo(column
)->GetText();
2517 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
2519 GetColumnInfo(column
)->SetText(text
);
2521 // for compatibility with superclass APIs
2526 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
2528 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
2529 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
2531 return node
->GetData();
2534 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
2536 return m_rowItems
.GetCount() > column
;
2539 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
2542 if ( column
>= m_rowItems
.GetCount() )
2544 wxListItem
* listItem
= new wxListItem(*item
);
2545 m_rowItems
.Append( listItem
);
2549 wxListItem
* listItem
= GetColumnInfo( column
);
2550 long mask
= item
->GetMask();
2551 if (mask
& wxLIST_MASK_TEXT
)
2552 listItem
->SetText(item
->GetText());
2553 if (mask
& wxLIST_MASK_DATA
)
2554 listItem
->SetData(item
->GetData());
2555 if (mask
& wxLIST_MASK_IMAGE
)
2556 listItem
->SetImage(item
->GetImage());
2557 if (mask
& wxLIST_MASK_STATE
)
2558 listItem
->SetState(item
->GetState());
2559 if (mask
& wxLIST_MASK_FORMAT
)
2560 listItem
->SetAlign(item
->GetAlign());
2561 if (mask
& wxLIST_MASK_WIDTH
)
2562 listItem
->SetWidth(item
->GetWidth());
2564 listItem
->SetTextColour(item
->GetTextColour());
2565 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
2566 listItem
->SetFont(item
->GetFont());
2570 #endif // wxUSE_LISTCTRL