+OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemID,
+ DataBrowserPropertyID property,
+ DataBrowserItemDataRef itemData,
+ Boolean changeValue )
+{
+ wxString text;
+ int imgIndex = -1;
+ short listColumn = property - kMinColumnId;
+
+ OSStatus err = errDataBrowserPropertyNotSupported;
+ wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
+ wxMacListCtrlItem* lcItem;
+
+ if (listColumn >= 0)
+ {
+ if (!m_isVirtual)
+ {
+ lcItem = (wxMacListCtrlItem*) itemID;
+ if (lcItem->HasColumnInfo(listColumn)){
+ wxListItem* item = lcItem->GetColumnInfo(listColumn);
+ if (item->GetMask() & wxLIST_MASK_TEXT)
+ text = item->GetText();
+ if (item->GetMask() & wxLIST_MASK_IMAGE)
+ imgIndex = item->GetImage();
+ }
+ }
+ else
+ {
+ text = list->OnGetItemText( (long)itemID-1, listColumn );
+ imgIndex = list->OnGetItemColumnImage( (long)itemID-1, listColumn );
+ }
+ }
+
+ if ( !changeValue )
+ {
+ switch (property)
+ {
+ case kDataBrowserItemIsEditableProperty :
+ if ( list && list->HasFlag( wxLC_EDIT_LABELS ) )
+ {
+ verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
+ err = noErr ;
+ }
+ break ;
+ default :
+ if ( property >= kMinColumnId )
+ {
+ wxMacCFStringHolder cfStr;
+
+ if (text){
+ cfStr.Assign( text, wxLocale::GetSystemEncoding() );
+ err = ::SetDataBrowserItemDataText( itemData, cfStr );
+ err = noErr;
+ }
+
+
+
+ if ( imgIndex != -1 )
+ {
+ wxImageList* imageList = list->GetImageList(wxIMAGE_LIST_SMALL);
+ if (imageList && imageList->GetImageCount() > 0){
+ wxBitmap bmp = imageList->GetBitmap(imgIndex);
+ IconRef icon = bmp.GetBitmapData()->GetIconRef();
+ ::SetDataBrowserItemDataIcon(itemData, icon);
+ }
+ }
+
+ }
+ break ;
+ }
+
+ }
+ else
+ {
+ switch (property)
+ {
+ default:
+ if ( property >= kMinColumnId )
+ {
+ short listColumn = property - kMinColumnId;
+
+ // TODO probably send the 'end edit' from here, as we
+ // can then deal with the veto
+ CFStringRef sr ;
+ verify_noerr( GetDataBrowserItemDataText( itemData , &sr ) ) ;
+ wxMacCFStringHolder cfStr(sr) ;;
+ if (m_isVirtual)
+ list->SetItem( (long)itemData-1 , listColumn, cfStr.AsString() ) ;
+ else
+ {
+ if (lcItem)
+ lcItem->SetColumnTextValue( listColumn, cfStr.AsString() );
+ }
+ err = noErr ;
+ }
+ break;
+ }
+ }
+ return err;
+}
+
+void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID,
+ DataBrowserItemNotification message,
+ DataBrowserItemDataRef itemData )
+{
+ // we want to depend on as little as possible to make sure tear-down of controls is safe
+ if ( message == kDataBrowserItemRemoved)
+ {
+ // make sure MacDelete does the proper teardown.
+ return;
+ }
+ else if ( message == kDataBrowserItemAdded )
+ {
+ // we don't issue events on adding, the item is not really stored in the list yet, so we
+ // avoid asserts by getting out now
+ return ;
+ }
+
+ wxListCtrl *list = wxDynamicCast( GetPeer() , wxListCtrl );
+ if ( list )
+ {
+ bool trigger = false;
+
+ wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() );
+ bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0;
+
+ event.SetEventObject( list );
+ if ( !list->IsVirtual() )
+ {
+ DataBrowserTableViewRowIndex result = 0;
+ verify_noerr( GetItemRow( itemID, &result ) ) ;
+ event.m_itemIndex = result;
+
+ if (event.m_itemIndex >= 0)
+ MacGetColumnInfo(event.m_itemIndex,0,event.m_item);
+ }
+ else
+ {
+ event.m_itemIndex = (long)itemID;
+ }
+
+ switch (message)
+ {
+ case kDataBrowserItemDeselected:
+ event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
+ if ( !isSingle )
+ trigger = IsSelectionSuppressed();
+ break;
+
+ case kDataBrowserItemSelected:
+ trigger = IsSelectionSuppressed();
+ break;
+
+ case kDataBrowserItemDoubleClicked:
+ event.SetEventType( wxEVT_LEFT_DCLICK );
+ trigger = true;
+ break;
+
+ case kDataBrowserEditStarted :
+ // TODO : how to veto ?
+ event.SetEventType( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT ) ;
+ trigger = true ;
+ break ;
+
+ case kDataBrowserEditStopped :
+ // TODO probably trigger only upon the value store callback, because
+ // here IIRC we cannot veto
+ event.SetEventType( wxEVT_COMMAND_LIST_END_LABEL_EDIT ) ;
+ trigger = true ;
+ break ;
+
+ default:
+ break;
+ }
+
+ if ( trigger )
+ {
+ // direct notification is not always having the listbox GetSelection() having in synch with event
+ wxPostEvent( list->GetEventHandler(), event );
+ }
+ }
+}
+
+Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneID,
+ DataBrowserItemID itemTwoID,
+ DataBrowserPropertyID sortProperty)
+{
+
+ bool retval = false;
+ wxString itemText;
+ wxString otherItemText;
+ int colId = sortProperty - kMinColumnId;
+ long itemNum = 0;
+ long otherItemNum = 0;
+
+ wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
+
+ // means we need to
+ if (colId >= 0)
+ {
+ if (!m_isVirtual)
+ {
+ wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
+ wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
+ wxListCtrlCompare func = list->GetCompareFunc();
+ if (func != NULL && item->HasColumnInfo(colId) && otherItem->HasColumnInfo(colId))
+ return func(item->GetColumnInfo(colId)->GetData(), otherItem->GetColumnInfo(colId)->GetData(), list->GetCompareFuncData()) >= 0;
+
+ itemNum = item->GetOrder();
+ otherItemNum = otherItem->GetOrder();
+ if (item->HasColumnInfo(colId))
+ itemText = item->GetColumnInfo(colId)->GetText();
+ if (otherItem->HasColumnInfo(colId))
+ otherItemText = otherItem->GetColumnInfo(colId)->GetText();
+ }
+ else
+ {
+ itemNum = (long)itemOneID;
+ otherItemNum = (long)itemTwoID;
+ itemText = list->OnGetItemText( itemNum-1, colId );
+ otherItemText = list->OnGetItemText( otherItemNum-1, colId );
+
+ }
+
+ DataBrowserSortOrder sort;
+ verify_noerr(GetSortOrder(&sort));
+
+ if ( sort == kDataBrowserOrderIncreasing )
+ {
+ retval = itemText.CmpNoCase( otherItemText ) > 0;
+ }
+ else if ( sort == kDataBrowserOrderDecreasing )
+ {
+ retval = itemText.CmpNoCase( otherItemText ) < 0;
+ }
+ }
+ else{
+ // fallback for undefined cases
+ retval = itemOneID < itemTwoID;
+ }
+
+ return retval;
+}
+