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
& wxNO_BORDER
, 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 wxSize
wxListCtrl::DoGetBestSize() const
496 return m_genericImpl
->GetBestSize();
498 return wxWindow::DoGetBestSize();
501 bool wxListCtrl::SetFont(const wxFont
& font
)
504 rv
= wxControl::SetFont(font
);
506 rv
= m_genericImpl
->SetFont(font
);
510 bool wxListCtrl::SetForegroundColour(const wxColour
& colour
)
514 rv
= m_genericImpl
->SetForegroundColour(colour
);
516 SetTextColour(colour
);
520 bool wxListCtrl::SetBackgroundColour(const wxColour
& colour
)
524 rv
= m_genericImpl
->SetBackgroundColour(colour
);
530 wxColour
wxListCtrl::GetBackgroundColour()
533 return m_genericImpl
->GetBackgroundColour();
540 // ----------------------------------------------------------------------------
542 // ----------------------------------------------------------------------------
544 // Gets information about this column
545 bool wxListCtrl::GetColumn(int col
, wxListItem
& item
) const
548 return m_genericImpl
->GetColumn(col
, item
);
555 wxColumnList::compatibility_iterator node
= m_colsInfo
.Item( col
);
556 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
557 wxListItem
* column
= node
->GetData();
559 long mask
= column
->GetMask();
560 if (mask
& wxLIST_MASK_TEXT
)
561 item
.SetText(column
->GetText());
562 if (mask
& wxLIST_MASK_DATA
)
563 item
.SetData(column
->GetData());
564 if (mask
& wxLIST_MASK_IMAGE
)
565 item
.SetImage(column
->GetImage());
566 if (mask
& wxLIST_MASK_STATE
)
567 item
.SetState(column
->GetState());
568 if (mask
& wxLIST_MASK_FORMAT
)
569 item
.SetAlign(column
->GetAlign());
570 if (mask
& wxLIST_MASK_WIDTH
)
571 item
.SetWidth(column
->GetWidth());
577 // Sets information about this column
578 bool wxListCtrl::SetColumn(int col
, wxListItem
& item
)
581 return m_genericImpl
->SetColumn(col
, item
);
585 if ( col
>= (int)m_colsInfo
.GetCount() )
587 wxListItem
* listItem
= new wxListItem(item
);
588 m_colsInfo
.Append( listItem
);
593 GetColumn( col
, listItem
);
594 long mask
= item
.GetMask();
595 if (mask
& wxLIST_MASK_TEXT
)
596 listItem
.SetText(item
.GetText());
597 if (mask
& wxLIST_MASK_DATA
)
598 listItem
.SetData(item
.GetData());
599 if (mask
& wxLIST_MASK_IMAGE
)
600 listItem
.SetImage(item
.GetImage());
601 if (mask
& wxLIST_MASK_STATE
)
602 listItem
.SetState(item
.GetState());
603 if (mask
& wxLIST_MASK_FORMAT
)
604 listItem
.SetAlign(item
.GetAlign());
605 if (mask
& wxLIST_MASK_WIDTH
)
606 listItem
.SetWidth(item
.GetWidth());
609 // change the appearance in the databrowser.
610 DataBrowserListViewHeaderDesc columnDesc
;
611 columnDesc
.version
=kDataBrowserListViewLatestHeaderDesc
;
612 verify_noerr( m_dbImpl
->GetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
615 if (item.GetMask() & wxLIST_MASK_TEXT)
619 enc = m_font.GetEncoding();
621 enc = wxLocale::GetSystemEncoding();
622 wxMacCFStringHolder cfTitle;
623 cfTitle.Assign( item.GetText() , enc );
624 if(columnDesc.titleString)
625 CFRelease(columnDesc.titleString);
626 columnDesc.titleString = cfTitle;
630 if (item
.GetMask() & wxLIST_MASK_IMAGE
&& item
.GetImage() != -1 )
632 columnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
633 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
634 if (imageList
&& imageList
->GetImageCount() > 0 )
636 wxBitmap bmp
= imageList
->GetBitmap( item
.GetImage() );
637 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
638 columnDesc
.btnContentInfo
.u
.iconRef
= icon
;
642 verify_noerr( m_dbImpl
->SetHeaderDesc( kMinColumnId
+ col
, &columnDesc
) );
648 int wxListCtrl::GetColumnCount() const
651 return m_genericImpl
->GetColumnCount();
656 m_dbImpl
->GetColumnCount(&count
);
663 // Gets the column width
664 int wxListCtrl::GetColumnWidth(int col
) const
667 return m_genericImpl
->GetColumnWidth(col
);
671 return m_dbImpl
->GetColumnWidth(col
);
677 // Sets the column width
678 bool wxListCtrl::SetColumnWidth(int col
, int width
)
681 return m_genericImpl
->SetColumnWidth(col
, width
);
686 if (width
== wxLIST_AUTOSIZE
|| width
== wxLIST_AUTOSIZE_USEHEADER
)
691 for (int column
= 0; column
< GetColumnCount(); column
++)
693 m_dbImpl
->SetColumnWidth(col
, mywidth
);
697 m_dbImpl
->SetColumnWidth(col
, mywidth
);
705 // Gets the number of items that can fit vertically in the
706 // visible area of the list control (list or report view)
707 // or the total number of items in the list control (icon
708 // or small icon view)
709 int wxListCtrl::GetCountPerPage() const
712 return m_genericImpl
->GetCountPerPage();
721 // Gets the edit control for editing labels.
722 wxTextCtrl
* wxListCtrl::GetEditControl() const
725 return m_genericImpl
->GetEditControl();
730 // Gets information about the item
731 bool wxListCtrl::GetItem(wxListItem
& info
) const
734 return m_genericImpl
->GetItem(info
);
739 m_dbImpl
->MacGetColumnInfo(info
.m_itemId
, info
.m_col
, info
);
742 info
.SetText( OnGetItemText(info
.m_itemId
, info
.m_col
) );
743 info
.SetImage( OnGetItemColumnImage(info
.m_itemId
, info
.m_col
) );
744 wxListItemAttr
* attrs
= OnGetItemAttr( info
.m_itemId
);
747 info
.SetFont( attrs
->GetFont() );
748 info
.SetBackgroundColour( attrs
->GetBackgroundColour() );
749 info
.SetTextColour( attrs
->GetTextColour() );
757 // Sets information about the item
758 bool wxListCtrl::SetItem(wxListItem
& info
)
761 return m_genericImpl
->SetItem(info
);
764 m_dbImpl
->MacSetColumnInfo( info
.m_itemId
, info
.m_col
, &info
);
769 long wxListCtrl::SetItem(long index
, int col
, const wxString
& label
, int imageId
)
772 return m_genericImpl
->SetItem(index
, col
, label
, imageId
);
776 info
.m_mask
= wxLIST_MASK_TEXT
;
777 info
.m_itemId
= index
;
781 info
.m_image
= imageId
;
782 info
.m_mask
|= wxLIST_MASK_IMAGE
;
784 return SetItem(info
);
788 // Gets the item state
789 int wxListCtrl::GetItemState(long item
, long stateMask
) const
792 return m_genericImpl
->GetItemState(item
, stateMask
);
796 info
.m_mask
= wxLIST_MASK_STATE
;
797 info
.m_stateMask
= stateMask
;
798 info
.m_itemId
= item
;
806 // Sets the item state
807 bool wxListCtrl::SetItemState(long item
, long state
, long stateMask
)
810 return m_genericImpl
->SetItemState(item
, state
, stateMask
);
813 info
.m_mask
= wxLIST_MASK_STATE
;
814 info
.m_stateMask
= stateMask
;
815 info
.m_state
= state
;
816 info
.m_itemId
= item
;
817 return SetItem(info
);
820 // Sets the item image
821 bool wxListCtrl::SetItemImage(long item
, int image
, int WXUNUSED(selImage
))
823 return SetItemColumnImage(item
, 0, image
);
826 // Sets the item image
827 bool wxListCtrl::SetItemColumnImage(long item
, long column
, int image
)
830 return m_genericImpl
->SetItemColumnImage(item
, column
, image
);
834 info
.m_mask
= wxLIST_MASK_IMAGE
;
835 info
.m_image
= image
;
836 info
.m_itemId
= item
;
839 return SetItem(info
);
842 // Gets the item text
843 wxString
wxListCtrl::GetItemText(long item
) const
846 return m_genericImpl
->GetItemText(item
);
850 info
.m_mask
= wxLIST_MASK_TEXT
;
851 info
.m_itemId
= item
;
854 return wxEmptyString
;
858 // Sets the item text
859 void wxListCtrl::SetItemText(long item
, const wxString
& str
)
862 return m_genericImpl
->SetItemText(item
, str
);
866 info
.m_mask
= wxLIST_MASK_TEXT
;
867 info
.m_itemId
= item
;
873 // Gets the item data
874 long wxListCtrl::GetItemData(long item
) const
877 return m_genericImpl
->GetItemData(item
);
881 info
.m_mask
= wxLIST_MASK_DATA
;
882 info
.m_itemId
= item
;
889 // Sets the item data
890 bool wxListCtrl::SetItemData(long item
, long data
)
893 return m_genericImpl
->SetItemData(item
, data
);
897 info
.m_mask
= wxLIST_MASK_DATA
;
898 info
.m_itemId
= item
;
901 return SetItem(info
);
904 wxRect
wxListCtrl::GetViewRect() const
906 wxASSERT_MSG( !HasFlag(wxLC_REPORT
| wxLC_LIST
),
907 _T("wxListCtrl::GetViewRect() only works in icon mode") );
910 return m_genericImpl
->GetViewRect();
916 // Gets the item rectangle
917 bool wxListCtrl::GetItemRect(long item
, wxRect
& rect
, int code
) const
920 return m_genericImpl
->GetItemRect(item
, rect
, code
);
925 DataBrowserItemID id
;
926 DataBrowserPropertyID col
= kMinColumnId
;
928 DataBrowserPropertyPart part
= kDataBrowserPropertyEnclosingPart
;
929 if ( code
== wxLIST_RECT_LABEL
)
930 part
= kDataBrowserPropertyTextPart
;
931 else if ( code
== wxLIST_RECT_ICON
)
932 part
= kDataBrowserPropertyIconPart
;
934 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
936 wxMacDataItem
* thisItem
= m_dbImpl
->GetItemFromLine(item
);
937 id
= (DataBrowserItemID
) thisItem
;
942 GetDataBrowserItemPartBounds( m_dbImpl
->GetControlRef(), id
, col
, part
, &bounds
);
944 rect
.x
= bounds
.left
;
946 rect
.width
= GetClientSize().x
; // we need the width of the whole row, not just the item.
947 rect
.height
= bounds
.bottom
- bounds
.top
;
952 // Gets the item position
953 bool wxListCtrl::GetItemPosition(long item
, wxPoint
& pos
) const
956 return m_genericImpl
->GetItemPosition(item
, pos
);
958 bool success
= false;
963 GetItemRect(item
, itemRect
);
964 pos
= itemRect
.GetPosition();
971 // Sets the item position.
972 bool wxListCtrl::SetItemPosition(long item
, const wxPoint
& pos
)
975 return m_genericImpl
->SetItemPosition(item
, pos
);
980 // Gets the number of items in the list control
981 int wxListCtrl::GetItemCount() const
984 return m_genericImpl
->GetItemCount();
987 return m_dbImpl
->MacGetCount();
992 void wxListCtrl::SetItemSpacing( int spacing
, bool isSmall
)
995 m_genericImpl
->SetItemSpacing(spacing
, isSmall
);
998 wxSize
wxListCtrl::GetItemSpacing() const
1001 return m_genericImpl
->GetItemSpacing();
1003 return wxSize(0, 0);
1006 void wxListCtrl::SetItemTextColour( long item
, const wxColour
&col
)
1010 m_genericImpl
->SetItemTextColour(item
, col
);
1015 info
.m_itemId
= item
;
1016 info
.SetTextColour( col
);
1020 wxColour
wxListCtrl::GetItemTextColour( long item
) const
1023 return m_genericImpl
->GetItemTextColour(item
);
1029 return info
.GetTextColour();
1031 return wxNullColour
;
1034 void wxListCtrl::SetItemBackgroundColour( long item
, const wxColour
&col
)
1038 m_genericImpl
->SetItemBackgroundColour(item
, col
);
1043 info
.m_itemId
= item
;
1044 info
.SetBackgroundColour( col
);
1048 wxColour
wxListCtrl::GetItemBackgroundColour( long item
) const
1051 return m_genericImpl
->GetItemBackgroundColour(item
);
1057 return info
.GetBackgroundColour();
1059 return wxNullColour
;
1062 void wxListCtrl::SetItemFont( long item
, const wxFont
&f
)
1066 m_genericImpl
->SetItemFont(item
, f
);
1071 info
.m_itemId
= item
;
1076 wxFont
wxListCtrl::GetItemFont( long item
) const
1079 return m_genericImpl
->GetItemFont(item
);
1085 return info
.GetFont();
1091 // Gets the number of selected items in the list control
1092 int wxListCtrl::GetSelectedItemCount() const
1095 return m_genericImpl
->GetSelectedItemCount();
1098 return m_dbImpl
->GetSelectedItemCount(NULL
, true);
1103 // Gets the text colour of the listview
1104 wxColour
wxListCtrl::GetTextColour() const
1107 return m_genericImpl
->GetTextColour();
1109 // TODO: we need owner drawn list items to customize text color.
1113 return wxNullColour
;
1116 // Sets the text colour of the listview
1117 void wxListCtrl::SetTextColour(const wxColour
& col
)
1121 m_genericImpl
->SetTextColour(col
);
1129 // Gets the index of the topmost visible item when in
1130 // list or report view
1131 long wxListCtrl::GetTopItem() const
1134 return m_genericImpl
->GetTopItem();
1139 // Searches for an item, starting from 'item'.
1140 // 'geometry' is one of
1141 // wxLIST_NEXT_ABOVE/ALL/BELOW/LEFT/RIGHT.
1142 // 'state' is a state bit flag, one or more of
1143 // wxLIST_STATE_DROPHILITED/FOCUSED/SELECTED/CUT.
1144 // item can be -1 to find the first item that matches the
1146 // Returns the item or -1 if unsuccessful.
1147 long wxListCtrl::GetNextItem(long item
, int geom
, int state
) const
1150 return m_genericImpl
->GetNextItem(item
, geom
, state
);
1152 if (m_dbImpl
&& geom
== wxLIST_NEXT_ALL
&& state
== wxLIST_STATE_SELECTED
)
1154 long count
= m_dbImpl
->MacGetCount() ;
1155 for ( long line
= item
+ 1 ; line
< count
; line
++ )
1157 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(line
);
1158 if ( m_dbImpl
->IsItemSelected(id
) )
1168 wxImageList
*wxListCtrl::GetImageList(int which
) const
1171 return m_genericImpl
->GetImageList(which
);
1173 if ( which
== wxIMAGE_LIST_NORMAL
)
1175 return m_imageListNormal
;
1177 else if ( which
== wxIMAGE_LIST_SMALL
)
1179 return m_imageListSmall
;
1181 else if ( which
== wxIMAGE_LIST_STATE
)
1183 return m_imageListState
;
1188 void wxListCtrl::SetImageList(wxImageList
*imageList
, int which
)
1192 m_genericImpl
->SetImageList(imageList
, which
);
1196 if ( which
== wxIMAGE_LIST_NORMAL
)
1198 if (m_ownsImageListNormal
) delete m_imageListNormal
;
1199 m_imageListNormal
= imageList
;
1200 m_ownsImageListNormal
= false;
1202 else if ( which
== wxIMAGE_LIST_SMALL
)
1204 if (m_ownsImageListSmall
) delete m_imageListSmall
;
1205 m_imageListSmall
= imageList
;
1206 m_ownsImageListSmall
= false;
1208 else if ( which
== wxIMAGE_LIST_STATE
)
1210 if (m_ownsImageListState
) delete m_imageListState
;
1211 m_imageListState
= imageList
;
1212 m_ownsImageListState
= false;
1216 void wxListCtrl::AssignImageList(wxImageList
*imageList
, int which
)
1220 m_genericImpl
->AssignImageList(imageList
, which
);
1224 SetImageList(imageList
, which
);
1225 if ( which
== wxIMAGE_LIST_NORMAL
)
1226 m_ownsImageListNormal
= true;
1227 else if ( which
== wxIMAGE_LIST_SMALL
)
1228 m_ownsImageListSmall
= true;
1229 else if ( which
== wxIMAGE_LIST_STATE
)
1230 m_ownsImageListState
= true;
1233 // ----------------------------------------------------------------------------
1235 // ----------------------------------------------------------------------------
1237 // Arranges the items
1238 bool wxListCtrl::Arrange(int flag
)
1241 return m_genericImpl
->Arrange(flag
);
1246 bool wxListCtrl::DeleteItem(long item
)
1249 return m_genericImpl
->DeleteItem(item
);
1253 m_dbImpl
->MacDelete(item
);
1254 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ITEM
, GetId() );
1255 event
.SetEventObject( this );
1256 event
.m_itemIndex
= item
;
1257 GetEventHandler()->ProcessEvent( event
);
1263 // Deletes all items
1264 bool wxListCtrl::DeleteAllItems()
1267 return m_genericImpl
->DeleteAllItems();
1271 m_dbImpl
->MacClear();
1272 wxListEvent
event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
, GetId() );
1273 event
.SetEventObject( this );
1274 GetEventHandler()->ProcessEvent( event
);
1279 // Deletes all items
1280 bool wxListCtrl::DeleteAllColumns()
1283 return m_genericImpl
->DeleteAllColumns();
1288 m_dbImpl
->GetColumnCount(&cols
);
1289 for (UInt32 col
= 0; col
< cols
; col
++)
1299 bool wxListCtrl::DeleteColumn(int col
)
1302 return m_genericImpl
->DeleteColumn(col
);
1306 OSStatus err
= m_dbImpl
->RemoveColumn(col
);
1307 return err
== noErr
;
1313 // Clears items, and columns if there are any.
1314 void wxListCtrl::ClearAll()
1318 m_genericImpl
->ClearAll();
1329 wxTextCtrl
* wxListCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
1332 return m_genericImpl
->EditLabel(item
, textControlClass
);
1336 wxMacDataItem
* id
= m_dbImpl
->GetItemFromLine(item
);
1337 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), (DataBrowserItemID
)id
, kMinColumnId
) );
1342 // End label editing, optionally cancelling the edit
1343 bool wxListCtrl::EndEditLabel(bool cancel
)
1345 // TODO: generic impl. doesn't have this method - is it needed for us?
1347 return true; // m_genericImpl->EndEditLabel(cancel);
1350 verify_noerr( SetDataBrowserEditItem(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
, kMinColumnId
) );
1354 // Ensures this item is visible
1355 bool wxListCtrl::EnsureVisible(long item
)
1358 return m_genericImpl
->EnsureVisible(item
);
1362 wxMacDataItem
* dataItem
= m_dbImpl
->GetItemFromLine(item
);
1363 m_dbImpl
->RevealItem(dataItem
, kDataBrowserRevealWithoutSelecting
);
1369 // Find an item whose label matches this string, starting from the item after 'start'
1370 // or the beginning if 'start' is -1.
1371 long wxListCtrl::FindItem(long start
, const wxString
& str
, bool partial
)
1374 return m_genericImpl
->FindItem(start
, str
, partial
);
1379 // Find an item whose data matches this data, starting from the item after 'start'
1380 // or the beginning if 'start' is -1.
1381 long wxListCtrl::FindItem(long start
, long data
)
1384 return m_genericImpl
->FindItem(start
, data
);
1386 long idx
= start
+ 1;
1387 long count
= GetItemCount();
1391 if (GetItemData(idx
) == data
)
1399 // Find an item nearest this position in the specified direction, starting from
1400 // the item after 'start' or the beginning if 'start' is -1.
1401 long wxListCtrl::FindItem(long start
, const wxPoint
& pt
, int direction
)
1404 return m_genericImpl
->FindItem(start
, pt
, direction
);
1408 // Determines which item (if any) is at the specified point,
1409 // giving details in 'flags' (see wxLIST_HITTEST_... flags above)
1411 wxListCtrl::HitTest(const wxPoint
& point
, int& flags
, long *ptrSubItem
) const
1414 return m_genericImpl
->HitTest(point
, flags
, ptrSubItem
);
1416 flags
= wxLIST_HITTEST_NOWHERE
;
1419 int colHeaderHeight
= 22; // TODO: Find a way to get this value from the db control?
1420 UInt16 rowHeight
= 0;
1421 m_dbImpl
->GetDefaultRowHeight(&rowHeight
);
1424 if ( !(GetWindowStyleFlag() & wxLC_NO_HEADER
) )
1425 y
-= colHeaderHeight
;
1427 int row
= y
/ rowHeight
;
1428 DataBrowserItemID id
;
1429 m_dbImpl
->GetItemID( (DataBrowserTableViewRowIndex
) row
, &id
);
1431 // TODO: Use GetDataBrowserItemPartBounds to return if we are in icon or label
1432 if ( !(GetWindowStyleFlag() & wxLC_VIRTUAL
) )
1434 wxMacListCtrlItem
* lcItem
;
1435 lcItem
= (wxMacListCtrlItem
*) id
;
1438 flags
= wxLIST_HITTEST_ONITEM
;
1444 if (row
< GetItemCount() )
1446 flags
= wxLIST_HITTEST_ONITEM
;
1456 // Inserts an item, returning the index of the new item if successful,
1458 long wxListCtrl::InsertItem(wxListItem
& info
)
1460 wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual controls") );
1463 return m_genericImpl
->InsertItem(info
);
1467 int count
= GetItemCount();
1469 if (info
.m_itemId
> count
)
1470 info
.m_itemId
= count
;
1472 m_dbImpl
->MacInsertItem(info
.m_itemId
, &info
);
1473 wxListEvent
event( wxEVT_COMMAND_LIST_INSERT_ITEM
, GetId() );
1474 event
.SetEventObject( this );
1475 event
.m_itemIndex
= info
.m_itemId
;
1476 GetEventHandler()->ProcessEvent( event
);
1479 return info
.m_itemId
;
1482 long wxListCtrl::InsertItem(long index
, const wxString
& label
)
1485 return m_genericImpl
->InsertItem(index
, label
);
1488 info
.m_text
= label
;
1489 info
.m_mask
= wxLIST_MASK_TEXT
;
1490 info
.m_itemId
= index
;
1491 return InsertItem(info
);
1494 // Inserts an image item
1495 long wxListCtrl::InsertItem(long index
, int imageIndex
)
1498 return m_genericImpl
->InsertItem(index
, imageIndex
);
1501 info
.m_image
= imageIndex
;
1502 info
.m_mask
= wxLIST_MASK_IMAGE
;
1503 info
.m_itemId
= index
;
1504 return InsertItem(info
);
1507 // Inserts an image/string item
1508 long wxListCtrl::InsertItem(long index
, const wxString
& label
, int imageIndex
)
1511 return m_genericImpl
->InsertItem(index
, label
, imageIndex
);
1514 info
.m_image
= imageIndex
;
1515 info
.m_text
= label
;
1516 info
.m_mask
= wxLIST_MASK_IMAGE
| wxLIST_MASK_TEXT
;
1517 info
.m_itemId
= index
;
1518 return InsertItem(info
);
1521 // For list view mode (only), inserts a column.
1522 long wxListCtrl::InsertColumn(long col
, wxListItem
& item
)
1525 return m_genericImpl
->InsertColumn(col
, item
);
1529 int width
= item
.GetWidth();
1530 if ( !(item
.GetMask() & wxLIST_MASK_WIDTH
) )
1533 DataBrowserPropertyType type
= kDataBrowserCustomType
; //kDataBrowserTextType;
1534 wxImageList
* imageList
= GetImageList(wxIMAGE_LIST_SMALL
);
1535 if (imageList
&& imageList
->GetImageCount() > 0)
1537 wxBitmap bmp
= imageList
->GetBitmap(0);
1539 // type = kDataBrowserIconAndTextType;
1542 SInt16 just
= teFlushDefault
;
1543 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
1545 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
1547 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
1549 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
1550 just
= teFlushRight
;
1552 m_dbImpl
->InsertColumn(col
, type
, item
.GetText(), just
, width
);
1553 SetColumn(col
, item
);
1555 // set/remove options based on the wxListCtrl type.
1556 DataBrowserTableViewColumnID id
;
1557 m_dbImpl
->GetColumnIDFromIndex(col
, &id
);
1558 DataBrowserPropertyFlags flags
;
1559 verify_noerr(m_dbImpl
->GetPropertyFlags(id
, &flags
));
1560 if (GetWindowStyleFlag() & wxLC_EDIT_LABELS
)
1561 flags
|= kDataBrowserPropertyIsEditable
;
1563 if (GetWindowStyleFlag() & wxLC_VIRTUAL
){
1564 flags
&= ~kDataBrowserListViewSortableColumn
;
1566 verify_noerr(m_dbImpl
->SetPropertyFlags(id
, flags
));
1572 long wxListCtrl::InsertColumn(long col
,
1573 const wxString
& heading
,
1578 return m_genericImpl
->InsertColumn(col
, heading
, format
, width
);
1581 item
.m_mask
= wxLIST_MASK_TEXT
| wxLIST_MASK_FORMAT
;
1582 item
.m_text
= heading
;
1585 item
.m_mask
|= wxLIST_MASK_WIDTH
;
1586 item
.m_width
= width
;
1588 item
.m_format
= format
;
1590 return InsertColumn(col
, item
);
1593 // scroll the control by the given number of pixels (exception: in list view,
1594 // dx is interpreted as number of columns)
1595 bool wxListCtrl::ScrollList(int dx
, int dy
)
1598 return m_genericImpl
->ScrollList(dx
, dy
);
1602 m_dbImpl
->SetScrollPosition(dx
, dy
);
1608 bool wxListCtrl::SortItems(wxListCtrlCompare fn
, long data
)
1611 return m_genericImpl
->SortItems(fn
, data
);
1616 m_compareFuncData
= data
;
1622 // ----------------------------------------------------------------------------
1623 // virtual list controls
1624 // ----------------------------------------------------------------------------
1626 wxString
wxListCtrl::OnGetItemText(long WXUNUSED(item
), long WXUNUSED(col
)) const
1628 // this is a pure virtual function, in fact - which is not really pure
1629 // because the controls which are not virtual don't need to implement it
1630 wxFAIL_MSG( _T("wxListCtrl::OnGetItemText not supposed to be called") );
1632 return wxEmptyString
;
1635 int wxListCtrl::OnGetItemImage(long WXUNUSED(item
)) const
1637 wxCHECK_MSG(!GetImageList(wxIMAGE_LIST_SMALL
),
1639 wxT("List control has an image list, OnGetItemImage or OnGetItemColumnImage should be overridden."));
1643 int wxListCtrl::OnGetItemColumnImage(long item
, long column
) const
1646 return OnGetItemImage(item
);
1651 wxListItemAttr
*wxListCtrl::OnGetItemAttr(long WXUNUSED_UNLESS_DEBUG(item
)) const
1653 wxASSERT_MSG( item
>= 0 && item
< GetItemCount(),
1654 _T("invalid item index in OnGetItemAttr()") );
1656 // no attributes by default
1660 void wxListCtrl::SetItemCount(long count
)
1662 wxASSERT_MSG( IsVirtual(), _T("this is for virtual controls only") );
1666 m_genericImpl
->SetItemCount(count
);
1672 // we need to temporarily disable the new item creation notification
1673 // procedure to speed things up
1674 // FIXME: Even this doesn't seem to help much...
1675 DataBrowserCallbacks callbacks
;
1676 DataBrowserItemNotificationUPP itemUPP
;
1677 GetDataBrowserCallbacks(m_dbImpl
->GetControlRef(), &callbacks
);
1678 itemUPP
= callbacks
.u
.v1
.itemNotificationCallback
;
1679 callbacks
.u
.v1
.itemNotificationCallback
= 0;
1680 m_dbImpl
->SetCallbacks(&callbacks
);
1681 ::AddDataBrowserItems(m_dbImpl
->GetControlRef(), kDataBrowserNoItem
,
1682 count
, NULL
, kDataBrowserItemNoProperty
);
1683 callbacks
.u
.v1
.itemNotificationCallback
= itemUPP
;
1684 m_dbImpl
->SetCallbacks(&callbacks
);
1689 void wxListCtrl::RefreshItem(long item
)
1693 m_genericImpl
->RefreshItem(item
);
1698 GetItemRect(item
, rect
);
1702 void wxListCtrl::RefreshItems(long itemFrom
, long itemTo
)
1706 m_genericImpl
->RefreshItems(itemFrom
, itemTo
);
1710 wxRect rect1
, rect2
;
1711 GetItemRect(itemFrom
, rect1
);
1712 GetItemRect(itemTo
, rect2
);
1714 wxRect rect
= rect1
;
1715 rect
.height
= rect2
.GetBottom() - rect1
.GetTop();
1721 // wxMac internal data structures
1723 wxMacListCtrlItem::~wxMacListCtrlItem()
1727 void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl
*owner
,
1728 DataBrowserItemNotification message
,
1729 DataBrowserItemDataRef itemData
) const
1732 wxMacDataBrowserListCtrlControl
*lb
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>(owner
);
1734 // we want to depend on as little as possible to make sure tear-down of controls is safe
1735 if ( message
== kDataBrowserItemRemoved
)
1737 if ( lb
!= NULL
&& lb
->GetClientDataType() == wxClientData_Object
)
1739 delete (wxClientData
*) (m_data
);
1745 else if ( message
== kDataBrowserItemAdded
)
1747 // we don't issue events on adding, the item is not really stored in the list yet, so we
1748 // avoid asserts by gettting out now
1752 wxListCtrl
*list
= wxDynamicCast( owner
->GetPeer() , wxListCtrl
);
1755 bool trigger
= false;
1757 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
1758 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
1760 event
.SetEventObject( list
);
1761 event
.m_itemIndex
= owner
->GetLineFromItem( this ) ;
1762 if ( !list
->IsVirtual() )
1764 lb
->MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
1769 case kDataBrowserItemDeselected
:
1770 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
1772 trigger
= !lb
->IsSelectionSuppressed();
1775 case kDataBrowserItemSelected
:
1776 trigger
= !lb
->IsSelectionSuppressed();
1779 case kDataBrowserItemDoubleClicked
:
1780 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
1784 case kDataBrowserEditStarted
:
1785 // TODO : how to veto ?
1786 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
1790 case kDataBrowserEditStopped
:
1791 // TODO probably trigger only upon the value store callback, because
1792 // here IIRC we cannot veto
1793 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
1803 // direct notification is not always having the listbox GetSelection() having in synch with event
1804 wxPostEvent( list
->GetEventHandler(), event
);
1810 wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
1811 : wxMacDataItemBrowserControl( peer
, pos
, size
, style
)
1813 OSStatus err
= noErr
;
1814 m_clientDataItemsType
= wxClientData_None
;
1815 m_isVirtual
= false;
1817 if ( style
& wxLC_VIRTUAL
)
1820 DataBrowserSelectionFlags options
= kDataBrowserDragSelect
;
1821 if ( style
& wxLC_SINGLE_SEL
)
1823 options
|= kDataBrowserSelectOnlyOne
;
1827 options
|= kDataBrowserCmdTogglesSelection
;
1830 err
= SetSelectionFlags( options
);
1831 verify_noerr( err
);
1833 DataBrowserCustomCallbacks callbacks
;
1834 InitializeDataBrowserCustomCallbacks( &callbacks
, kDataBrowserLatestCustomCallbacks
);
1836 if ( gDataBrowserDrawItemUPP
== NULL
)
1837 gDataBrowserDrawItemUPP
= NewDataBrowserDrawItemUPP(DataBrowserDrawItemProc
);
1839 // if ( gDataBrowserEditItemUPP == NULL )
1840 // gDataBrowserEditItemUPP = NewDataBrowserEditItemUPP(DataBrowserEditTextProc);
1842 if ( gDataBrowserHitTestUPP
== NULL
)
1843 gDataBrowserHitTestUPP
= NewDataBrowserHitTestUPP(DataBrowserHitTestProc
);
1845 callbacks
.u
.v1
.drawItemCallback
= gDataBrowserDrawItemUPP
;
1846 // callbacks.u.v1.editTextCallback = gDataBrowserEditItemUPP;
1847 callbacks
.u
.v1
.hitTestCallback
= gDataBrowserHitTestUPP
;
1849 SetDataBrowserCustomCallbacks( GetControlRef(), &callbacks
);
1851 if ( style
& wxLC_LIST
)
1853 InsertColumn(0, kDataBrowserIconAndTextType
, wxEmptyString
, -1, -1);
1854 verify_noerr( AutoSizeColumns() );
1857 if ( style
& wxLC_LIST
|| style
& wxLC_NO_HEADER
)
1858 verify_noerr( SetHeaderButtonHeight( 0 ) );
1861 SetSortProperty( kMinColumnId
- 1 );
1863 SetSortProperty( kMinColumnId
);
1864 if ( style
& wxLC_SORT_ASCENDING
)
1866 m_sortOrder
= SortOrder_Text_Ascending
;
1867 SetSortOrder( kDataBrowserOrderIncreasing
);
1869 else if ( style
& wxLC_SORT_DESCENDING
)
1871 m_sortOrder
= SortOrder_Text_Descending
;
1872 SetSortOrder( kDataBrowserOrderDecreasing
);
1876 m_sortOrder
= SortOrder_None
;
1879 if ( style
& wxLC_VRULES
)
1881 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1882 verify_noerr( DataBrowserChangeAttributes(m_controlRef
, kDataBrowserAttributeListViewDrawColumnDividers
, kDataBrowserAttributeNone
) );
1886 verify_noerr( SetHiliteStyle(kDataBrowserTableViewFillHilite
) );
1887 err
= SetHasScrollBars( (style
& wxHSCROLL
) != 0 , true );
1890 pascal Boolean
wxMacDataBrowserListCtrlControl::DataBrowserEditTextProc(
1892 DataBrowserItemID itemID
,
1893 DataBrowserPropertyID property
,
1894 CFStringRef theString
,
1895 Rect
*maxEditTextRect
,
1896 Boolean
*shrinkToFit
)
1898 Boolean result
= false;
1899 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1902 result
= ctl
->ConfirmEditText(itemID
, property
, theString
, maxEditTextRect
, shrinkToFit
);
1903 theString
= CFSTR("Hello!");
1908 bool wxMacDataBrowserListCtrlControl::ConfirmEditText(
1909 DataBrowserItemID itemID
,
1910 DataBrowserPropertyID property
,
1911 CFStringRef theString
,
1912 Rect
*maxEditTextRect
,
1913 Boolean
*shrinkToFit
)
1915 //wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
1919 pascal void wxMacDataBrowserListCtrlControl::DataBrowserDrawItemProc(
1921 DataBrowserItemID itemID
,
1922 DataBrowserPropertyID property
,
1923 DataBrowserItemState itemState
,
1924 const Rect
*itemRect
,
1926 Boolean colorDevice
)
1928 wxMacDataBrowserListCtrlControl
* ctl
= dynamic_cast<wxMacDataBrowserListCtrlControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1931 ctl
->DrawItem(itemID
, property
, itemState
, itemRect
, gdDepth
, colorDevice
);
1935 // routines needed for DrawItem
1940 kTextBoxHeight
= 14,
1941 kIconTextSpacingV
= 2,
1943 kContentHeight
= kIconHeight
+ kTextBoxHeight
+ kIconTextSpacingV
1946 static void calculateCGDrawingBounds(CGRect inItemRect
, CGRect
*outIconRect
, CGRect
*outTextRect
, bool hasIcon
= false)
1949 float iconH
, iconW
= 0;
1950 float padding
= kItemPadding
;
1953 iconH
= kIconHeight
;
1955 padding
= padding
*2;
1958 textBottom
= inItemRect
.origin
.y
;
1960 *outIconRect
= CGRectMake(inItemRect
.origin
.x
+ kItemPadding
,
1961 textBottom
+ kIconTextSpacingV
, kIconWidth
,
1964 *outTextRect
= CGRectMake(inItemRect
.origin
.x
+ padding
+ iconW
,
1965 textBottom
+ kIconTextSpacingV
, inItemRect
.size
.width
- padding
- iconW
,
1966 inItemRect
.size
.height
- kIconTextSpacingV
);
1969 void wxMacDataBrowserListCtrlControl::DrawItem(
1970 DataBrowserItemID itemID
,
1971 DataBrowserPropertyID property
,
1972 DataBrowserItemState itemState
,
1973 const Rect
*itemRect
,
1975 Boolean colorDevice
)
1978 wxFont font
= wxNullFont
;
1980 short listColumn
= property
- kMinColumnId
;
1982 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
1983 wxMacListCtrlItem
* lcItem
;
1984 wxColour color
= *wxBLACK
;
1985 wxColour bgColor
= wxNullColour
;
1987 if (listColumn
>= 0)
1991 lcItem
= (wxMacListCtrlItem
*) itemID
;
1992 if (lcItem
->HasColumnInfo(listColumn
)){
1993 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
1995 // we always use the 0 column to get font and text/background colors.
1996 if (lcItem
->HasColumnInfo(0))
1998 wxListItem
* firstItem
= lcItem
->GetColumnInfo(0);
1999 color
= firstItem
->GetTextColour();
2000 bgColor
= firstItem
->GetBackgroundColour();
2001 font
= firstItem
->GetFont();
2004 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2005 text
= item
->GetText();
2006 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2007 imgIndex
= item
->GetImage();
2013 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2014 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2015 wxListItemAttr
* attrs
= list
->OnGetItemAttr( (long)itemID
-1 );
2018 if (attrs
->HasBackgroundColour())
2019 bgColor
= attrs
->GetBackgroundColour();
2020 if (attrs
->HasTextColour())
2021 color
= attrs
->GetTextColour();
2022 if (attrs
->HasFont())
2023 font
= attrs
->GetFont();
2028 wxColour listBgColor
= list
->GetBackgroundColour();
2029 if (bgColor
== wxNullColour
)
2030 bgColor
= listBgColor
;
2032 wxFont listFont
= list
->GetFont();
2033 if (font
== wxNullFont
)
2036 wxMacCFStringHolder cfString
;
2037 cfString
.Assign( text
, wxLocale::GetSystemEncoding() );
2040 CGRect enclosingCGRect
, iconCGRect
, textCGRect
;
2042 ThemeDrawingState savedState
= NULL
;
2043 CGContextRef context
= (CGContextRef
)list
->MacGetDrawingContext();
2044 RGBColor labelColor
;
2046 GetDataBrowserItemPartBounds(GetControlRef(), itemID
, property
, kDataBrowserPropertyEnclosingPart
,
2049 enclosingCGRect
= CGRectMake(enclosingRect
.left
,
2051 enclosingRect
.right
- enclosingRect
.left
,
2052 enclosingRect
.bottom
- enclosingRect
.top
);
2054 active
= IsControlActive(GetControlRef());
2056 if (itemState
== kDataBrowserItemIsSelected
)
2058 RGBColor foregroundColor
;
2060 GetThemeDrawingState(&savedState
);
2062 GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor
, 32, true, &foregroundColor
);
2063 GetThemeTextColor(kThemeTextColorWhite
, gdDepth
, colorDevice
, &labelColor
);
2065 CGContextSaveGState(context
);
2067 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2068 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2069 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2070 CGContextFillRect(context
, enclosingCGRect
);
2072 CGContextRestoreGState(context
);
2078 labelColor
= MAC_WXCOLORREF( color
.GetPixel() );
2079 else if (list
->GetTextColour().Ok())
2080 labelColor
= MAC_WXCOLORREF( list
->GetTextColour().GetPixel() );
2084 labelColor
.green
= 0;
2085 labelColor
.blue
= 0;
2090 RGBColor foregroundColor
= MAC_WXCOLORREF( bgColor
.GetPixel() );
2091 CGContextSaveGState(context
);
2093 CGContextSetRGBFillColor(context
, (float)foregroundColor
.red
/ (float)USHRT_MAX
,
2094 (float)foregroundColor
.green
/ (float)USHRT_MAX
,
2095 (float)foregroundColor
.blue
/ (float)USHRT_MAX
, 1.0);
2096 CGContextFillRect(context
, enclosingCGRect
);
2098 CGContextRestoreGState(context
);
2102 calculateCGDrawingBounds(enclosingCGRect
, &iconCGRect
, &textCGRect
, (imgIndex
!= -1) );
2106 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2107 if (imageList
&& imageList
->GetImageCount() > 0){
2108 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2109 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2113 iconLabel
.green
= 0;
2116 CGContextSaveGState(context
);
2117 CGContextTranslateCTM(context
, 0,iconCGRect
.origin
.y
+ CGRectGetMaxY(iconCGRect
));
2118 CGContextScaleCTM(context
,1.0f
,-1.0f
);
2119 PlotIconRefInContext(context
, &iconCGRect
, kAlignNone
,
2120 active
? kTransformNone
: kTransformDisabled
, &iconLabel
,
2121 kPlotIconRefNormalFlags
, icon
);
2123 CGContextRestoreGState(context
);
2127 HIThemeTextHorizontalFlush hFlush
= kHIThemeTextHorizontalFlushLeft
;
2128 UInt16 fontID
= kThemeViewsFont
;
2132 if (font
.GetFamily() != wxFONTFAMILY_DEFAULT
)
2133 fontID
= font
.MacGetThemeFontID();
2135 // FIXME: replace these with CG or ATSUI calls so we can remove this #ifndef.
2137 ::TextSize( (short)(font
.MacGetFontSize()) ) ;
2138 ::TextFace( font
.MacGetFontStyle() ) ;
2143 list
->GetColumn(listColumn
, item
);
2144 if (item
.GetMask() & wxLIST_MASK_FORMAT
)
2146 if (item
.GetAlign() == wxLIST_FORMAT_LEFT
)
2147 hFlush
= kHIThemeTextHorizontalFlushLeft
;
2148 else if (item
.GetAlign() == wxLIST_FORMAT_CENTER
)
2149 hFlush
= kHIThemeTextHorizontalFlushCenter
;
2150 else if (item
.GetAlign() == wxLIST_FORMAT_RIGHT
)
2152 hFlush
= kHIThemeTextHorizontalFlushRight
;
2153 textCGRect
.origin
.x
-= kItemPadding
; // give a little extra paddding
2157 HIThemeTextInfo info
;
2158 info
.version
= kHIThemeTextInfoVersionZero
;
2159 info
.state
= active
? kThemeStateActive
: kThemeStateInactive
;
2160 info
.fontID
= fontID
;
2161 info
.horizontalFlushness
= hFlush
;
2162 info
.verticalFlushness
= kHIThemeTextVerticalFlushCenter
;
2163 info
.options
= kHIThemeTextBoxOptionNone
;
2164 info
.truncationPosition
= kHIThemeTextTruncationEnd
;
2165 info
.truncationMaxLines
= 1;
2167 CGContextSaveGState(context
);
2168 CGContextSetRGBFillColor (context
, (float)labelColor
.red
/ (float)USHRT_MAX
,
2169 (float)labelColor
.green
/ (float)USHRT_MAX
,
2170 (float)labelColor
.blue
/ (float)USHRT_MAX
, 1.0);
2172 HIThemeDrawTextBox(cfString
, &textCGRect
, &info
, context
, kHIThemeOrientationNormal
);
2174 CGContextRestoreGState(context
);
2176 if (savedState
!= NULL
)
2177 SetThemeDrawingState(savedState
, true);
2180 OSStatus
wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID
,
2181 DataBrowserPropertyID property
,
2182 DataBrowserItemDataRef itemData
,
2183 Boolean changeValue
)
2187 short listColumn
= property
- kMinColumnId
;
2189 OSStatus err
= errDataBrowserPropertyNotSupported
;
2190 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2191 wxMacListCtrlItem
* lcItem
;
2193 if (listColumn
>= 0)
2197 lcItem
= (wxMacListCtrlItem
*) itemID
;
2198 if (lcItem
->HasColumnInfo(listColumn
)){
2199 wxListItem
* item
= lcItem
->GetColumnInfo(listColumn
);
2200 if (item
->GetMask() & wxLIST_MASK_TEXT
)
2201 text
= item
->GetText();
2202 if (item
->GetMask() & wxLIST_MASK_IMAGE
)
2203 imgIndex
= item
->GetImage();
2208 text
= list
->OnGetItemText( (long)itemID
-1, listColumn
);
2209 imgIndex
= list
->OnGetItemColumnImage( (long)itemID
-1, listColumn
);
2217 case kDataBrowserItemIsEditableProperty
:
2218 if ( list
&& list
->HasFlag( wxLC_EDIT_LABELS
) )
2220 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
2225 if ( property
>= kMinColumnId
)
2227 wxMacCFStringHolder cfStr
;
2230 cfStr
.Assign( text
, wxLocale::GetSystemEncoding() );
2231 err
= ::SetDataBrowserItemDataText( itemData
, cfStr
);
2237 if ( imgIndex
!= -1 )
2239 wxImageList
* imageList
= list
->GetImageList(wxIMAGE_LIST_SMALL
);
2240 if (imageList
&& imageList
->GetImageCount() > 0){
2241 wxBitmap bmp
= imageList
->GetBitmap(imgIndex
);
2242 IconRef icon
= bmp
.GetBitmapData()->GetIconRef();
2243 ::SetDataBrowserItemDataIcon(itemData
, icon
);
2257 if ( property
>= kMinColumnId
)
2259 short listColumn
= property
- kMinColumnId
;
2261 // TODO probably send the 'end edit' from here, as we
2262 // can then deal with the veto
2264 verify_noerr( GetDataBrowserItemDataText( itemData
, &sr
) ) ;
2265 wxMacCFStringHolder
cfStr(sr
) ;;
2267 list
->SetItem( (long)itemData
-1 , listColumn
, cfStr
.AsString() ) ;
2271 lcItem
->SetColumnTextValue( listColumn
, cfStr
.AsString() );
2281 void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID
,
2282 DataBrowserItemNotification message
,
2283 DataBrowserItemDataRef itemData
)
2285 // we want to depend on as little as possible to make sure tear-down of controls is safe
2286 if ( message
== kDataBrowserItemRemoved
)
2288 // make sure MacDelete does the proper teardown.
2291 else if ( message
== kDataBrowserItemAdded
)
2293 // we don't issue events on adding, the item is not really stored in the list yet, so we
2294 // avoid asserts by getting out now
2298 wxListCtrl
*list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2301 bool trigger
= false;
2303 wxListEvent
event( wxEVT_COMMAND_LIST_ITEM_SELECTED
, list
->GetId() );
2304 bool isSingle
= (list
->GetWindowStyle() & wxLC_SINGLE_SEL
) != 0;
2306 event
.SetEventObject( list
);
2307 if ( !list
->IsVirtual() )
2309 DataBrowserTableViewRowIndex result
= 0;
2310 verify_noerr( GetItemRow( itemID
, &result
) ) ;
2311 event
.m_itemIndex
= result
;
2313 if (event
.m_itemIndex
>= 0)
2314 MacGetColumnInfo(event
.m_itemIndex
,0,event
.m_item
);
2318 event
.m_itemIndex
= (long)itemID
;
2323 case kDataBrowserItemDeselected
:
2324 event
.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED
);
2326 trigger
= !IsSelectionSuppressed();
2329 case kDataBrowserItemSelected
:
2330 trigger
= !IsSelectionSuppressed();
2334 case kDataBrowserItemDoubleClicked
:
2335 event
.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED
);
2339 case kDataBrowserEditStarted
:
2340 // TODO : how to veto ?
2341 event
.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
) ;
2345 case kDataBrowserEditStopped
:
2346 // TODO probably trigger only upon the value store callback, because
2347 // here IIRC we cannot veto
2348 event
.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT
) ;
2358 // direct notification is not always having the listbox GetSelection() having in synch with event
2359 wxPostEvent( list
->GetEventHandler(), event
);
2364 Boolean
wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID
,
2365 DataBrowserItemID itemTwoID
,
2366 DataBrowserPropertyID sortProperty
)
2369 bool retval
= false;
2371 wxString otherItemText
;
2372 int colId
= sortProperty
- kMinColumnId
;
2374 long otherItemNum
= 0;
2376 wxListCtrl
* list
= wxDynamicCast( GetPeer() , wxListCtrl
);
2383 wxMacListCtrlItem
* item
= (wxMacListCtrlItem
*)itemOneID
;
2384 wxMacListCtrlItem
* otherItem
= (wxMacListCtrlItem
*)itemTwoID
;
2385 wxListCtrlCompare func
= list
->GetCompareFunc();
2386 if (func
!= NULL
&& item
->HasColumnInfo(colId
) && otherItem
->HasColumnInfo(colId
))
2387 return func(item
->GetColumnInfo(colId
)->GetData(), otherItem
->GetColumnInfo(colId
)->GetData(), list
->GetCompareFuncData()) >= 0;
2389 itemNum
= item
->GetOrder();
2390 otherItemNum
= otherItem
->GetOrder();
2391 if (item
->HasColumnInfo(colId
))
2392 itemText
= item
->GetColumnInfo(colId
)->GetText();
2393 if (otherItem
->HasColumnInfo(colId
))
2394 otherItemText
= otherItem
->GetColumnInfo(colId
)->GetText();
2398 itemNum
= (long)itemOneID
;
2399 otherItemNum
= (long)itemTwoID
;
2400 itemText
= list
->OnGetItemText( itemNum
-1, colId
);
2401 otherItemText
= list
->OnGetItemText( otherItemNum
-1, colId
);
2405 DataBrowserSortOrder sort
;
2406 verify_noerr(GetSortOrder(&sort
));
2408 if ( sort
== kDataBrowserOrderIncreasing
)
2410 retval
= itemText
.CmpNoCase( otherItemText
) > 0;
2412 else if ( sort
== kDataBrowserOrderDecreasing
)
2414 retval
= itemText
.CmpNoCase( otherItemText
) < 0;
2418 // fallback for undefined cases
2419 retval
= itemOneID
< itemTwoID
;
2425 wxMacDataBrowserListCtrlControl::~wxMacDataBrowserListCtrlControl()
2429 void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
* item
)
2431 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2434 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2435 listItem
->SetColumnInfo( column
, item
);
2436 UpdateState(dataItem
, item
);
2440 // apply changes that need to happen immediately, rather than when the
2441 // databrowser control fires a callback.
2442 void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem
* dataItem
, wxListItem
* listItem
)
2444 bool isSelected
= IsItemSelected( dataItem
);
2445 bool isSelectedState
= (listItem
->GetState() == wxLIST_STATE_SELECTED
);
2447 // toggle the selection state if wxListInfo state and actual state don't match.
2448 if ( isSelected
!= isSelectedState
)
2450 DataBrowserSetOption options
= kDataBrowserItemsAdd
;
2451 if (!isSelectedState
)
2452 options
= kDataBrowserItemsRemove
;
2453 SetSelectedItem(dataItem
, options
);
2455 // TODO: Set column width if item width > than current column width
2458 void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row
, unsigned int column
, wxListItem
& item
)
2460 wxMacDataItem
* dataItem
= GetItemFromLine(row
);
2461 // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate
2464 wxMacListCtrlItem
* listItem
= dynamic_cast<wxMacListCtrlItem
*>(dataItem
);
2465 wxListItem
* oldItem
= listItem
->GetColumnInfo( column
);
2467 long mask
= item
.GetMask();
2469 // by default, get everything for backwards compatibility
2472 if ( mask
& wxLIST_MASK_TEXT
)
2473 item
.SetText(oldItem
->GetText());
2474 if ( mask
& wxLIST_MASK_IMAGE
)
2475 item
.SetImage(oldItem
->GetImage());
2476 if ( mask
& wxLIST_MASK_DATA
)
2477 item
.SetData(oldItem
->GetData());
2478 if ( mask
& wxLIST_MASK_STATE
)
2479 item
.SetState(oldItem
->GetState());
2480 if ( mask
& wxLIST_MASK_WIDTH
)
2481 item
.SetWidth(oldItem
->GetWidth());
2482 if ( mask
& wxLIST_MASK_FORMAT
)
2483 item
.SetAlign(oldItem
->GetAlign());
2485 item
.SetTextColour(oldItem
->GetTextColour());
2486 item
.SetBackgroundColour(oldItem
->GetBackgroundColour());
2487 item
.SetFont(oldItem
->GetFont());
2491 void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n
, wxListItem
* item
)
2493 wxMacDataItemBrowserControl::MacInsert(n
, item
->GetText());
2494 MacSetColumnInfo(n
, 0, item
);
2497 wxMacDataItem
* wxMacDataBrowserListCtrlControl::CreateItem()
2499 return new wxMacListCtrlItem();
2502 wxMacListCtrlItem::wxMacListCtrlItem()
2504 m_rowItems
= wxListItemList();
2507 int wxMacListCtrlItem::GetColumnImageValue( unsigned int column
)
2509 return GetColumnInfo(column
)->GetImage();
2512 void wxMacListCtrlItem::SetColumnImageValue( unsigned int column
, int imageIndex
)
2514 GetColumnInfo(column
)->SetImage(imageIndex
);
2517 const wxString
& wxMacListCtrlItem::GetColumnTextValue( unsigned int column
)
2522 return GetColumnInfo(column
)->GetText();
2525 void wxMacListCtrlItem::SetColumnTextValue( unsigned int column
, const wxString
& text
)
2527 GetColumnInfo(column
)->SetText(text
);
2529 // for compatibility with superclass APIs
2534 wxListItem
* wxMacListCtrlItem::GetColumnInfo( unsigned int column
)
2536 wxListItemList::compatibility_iterator node
= m_rowItems
.Item( column
);
2537 wxASSERT_MSG( node
, _T("invalid column index in wxMacListCtrlItem") );
2539 return node
->GetData();
2542 bool wxMacListCtrlItem::HasColumnInfo( unsigned int column
)
2544 return m_rowItems
.GetCount() > column
;
2547 void wxMacListCtrlItem::SetColumnInfo( unsigned int column
, wxListItem
* item
)
2550 if ( column
>= m_rowItems
.GetCount() )
2552 wxListItem
* listItem
= new wxListItem(*item
);
2553 m_rowItems
.Append( listItem
);
2557 wxListItem
* listItem
= GetColumnInfo( column
);
2558 long mask
= item
->GetMask();
2559 if (mask
& wxLIST_MASK_TEXT
)
2560 listItem
->SetText(item
->GetText());
2561 if (mask
& wxLIST_MASK_DATA
)
2562 listItem
->SetData(item
->GetData());
2563 if (mask
& wxLIST_MASK_IMAGE
)
2564 listItem
->SetImage(item
->GetImage());
2565 if (mask
& wxLIST_MASK_STATE
)
2566 listItem
->SetState(item
->GetState());
2567 if (mask
& wxLIST_MASK_FORMAT
)
2568 listItem
->SetAlign(item
->GetAlign());
2569 if (mask
& wxLIST_MASK_WIDTH
)
2570 listItem
->SetWidth(item
->GetWidth());
2572 listItem
->SetTextColour(item
->GetTextColour());
2573 listItem
->SetBackgroundColour(item
->GetBackgroundColour());
2574 listItem
->SetFont(item
->GetFont());
2578 #endif // wxUSE_LISTCTRL