+ HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft;
+ HIThemeTextInfo info;
+ bool setup = false;
+#if wxMAC_USE_CORE_TEXT
+ if ( UMAGetSystemVersion() >= 0x1050 )
+ {
+ info.version = kHIThemeTextInfoVersionOne;
+ info.fontID = kThemeViewsFont;
+ if (font.Ok())
+ {
+ info.fontID = kThemeSpecifiedFont;
+ info.font = (CTFontRef) font.MacGetCTFont();
+ setup = true;
+ }
+ }
+#endif
+#if wxMAC_USE_ATSU_TEXT
+ if ( !setup )
+ {
+ info.version = kHIThemeTextInfoVersionZero;
+ info.fontID = kThemeViewsFont;
+
+ if (font.Ok())
+ {
+ if (font.GetFamily() != wxFONTFAMILY_DEFAULT)
+ info.fontID = font.MacGetThemeFontID();
+
+ ::TextSize( (short)(font.MacGetFontSize()) ) ;
+ ::TextFace( font.MacGetFontStyle() ) ;
+ }
+ }
+#endif
+
+ wxListItem item;
+ list->GetColumn(listColumn, item);
+ if (item.GetMask() & wxLIST_MASK_FORMAT)
+ {
+ if (item.GetAlign() == wxLIST_FORMAT_LEFT)
+ hFlush = kHIThemeTextHorizontalFlushLeft;
+ else if (item.GetAlign() == wxLIST_FORMAT_CENTER)
+ hFlush = kHIThemeTextHorizontalFlushCenter;
+ else if (item.GetAlign() == wxLIST_FORMAT_RIGHT)
+ {
+ hFlush = kHIThemeTextHorizontalFlushRight;
+ textCGRect.origin.x -= kItemPadding; // give a little extra paddding
+ }
+ }
+
+ info.state = active ? kThemeStateActive : kThemeStateInactive;
+ info.horizontalFlushness = hFlush;
+ info.verticalFlushness = kHIThemeTextVerticalFlushCenter;
+ info.options = kHIThemeTextBoxOptionNone;
+ info.truncationPosition = kHIThemeTextTruncationEnd;
+ info.truncationMaxLines = 1;
+
+ CGContextSaveGState(context);
+ CGContextSetRGBFillColor (context, (float)labelColor.red / (float)USHRT_MAX,
+ (float)labelColor.green / (float)USHRT_MAX,
+ (float)labelColor.blue / (float)USHRT_MAX, 1.0);
+
+ HIThemeDrawTextBox(cfString, &textCGRect, &info, context, kHIThemeOrientationNormal);
+
+ CGContextRestoreGState(context);
+
+#ifndef __LP64__
+ if (savedState != NULL)
+ SetThemeDrawingState(savedState, true);
+#endif
+}
+
+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 && 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
+ {
+ long itemNum = (long)itemID-1;
+ if (itemNum >= 0 && itemNum < list->GetItemCount())
+ {
+ text = list->OnGetItemText( itemNum, listColumn );
+ imgIndex = list->OnGetItemColumnImage( itemNum, 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 )
+ {
+ if (!text.IsEmpty()){
+ wxCFStringRef cfStr( 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.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 ) ) ;
+ wxCFStringRef 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 WXUNUSED(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() );
+
+ event.SetEventObject( list );
+ if ( !list->IsVirtual() )
+ {
+ DataBrowserTableViewRowIndex result = 0;
+ verify_noerr( GetItemRow( itemID, &result ) ) ;
+ event.m_itemIndex = result;
+ }
+ else
+ {
+ event.m_itemIndex = (long)itemID-1;
+ }
+ event.m_item.m_itemId = event.m_itemIndex;
+ list->GetItem(event.m_item);
+
+ switch (message)
+ {
+ case kDataBrowserItemDeselected:
+ event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
+ // as the generic implementation is also triggering this
+ // event for single selection, we do the same (different than listbox)
+ trigger = !IsSelectionSuppressed();
+ break;
+
+ case kDataBrowserItemSelected:
+ trigger = !IsSelectionSuppressed();
+
+ break;
+
+ case kDataBrowserItemDoubleClicked:
+ event.SetEventType( wxEVT_COMMAND_LIST_ITEM_ACTIVATED );
+ 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;
+ long itemOrder;
+ long otherItemOrder;
+
+ int colId = sortProperty - kMinColumnId;
+
+ wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );
+
+ DataBrowserSortOrder sort;
+ verify_noerr(GetSortOrder(&sort));
+
+ if (colId >= 0)
+ {
+ if (!m_isVirtual)
+ {
+ wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
+ wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
+
+ itemOrder = item->GetOrder();
+ otherItemOrder = item->GetOrder();
+
+ wxListCtrlCompare func = list->GetCompareFunc();
+ if (func != NULL)
+ {
+ long item1 = -1;
+ long item2 = -1;
+ if (item && item->HasColumnInfo(0))
+ item1 = item->GetColumnInfo(0)->GetData();
+ if (otherItem && otherItem->HasColumnInfo(0))
+ item2 = otherItem->GetColumnInfo(0)->GetData();
+
+ if (item1 > -1 && item2 > -1)
+ {
+ int result = func(item1, item2, list->GetCompareFuncData());
+ if (sort == kDataBrowserOrderIncreasing)
+ return result >= 0;
+ else
+ return result < 0;
+ }
+ }
+
+ // we can't use the native control's sorting abilities, so just
+ // sort by item id.
+ return itemOrder < otherItemOrder;
+ }
+ else
+ {
+
+ long itemNum = (long)itemOneID;
+ long otherItemNum = (long)itemTwoID;
+
+ // virtual listctrls don't support sorting
+ return itemNum < otherItemNum;
+ }
+ }
+ else{
+ // fallback for undefined cases
+ retval = itemOneID < itemTwoID;
+ }
+
+ return retval;