X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e96bbb453c4065b2219cbd606a95f069ab04746c..ded83b1a5cebd3c1257f4d254c97d3cfb39bb5aa:/src/mac/carbon/listctrl_mac.cpp?ds=sidebyside diff --git a/src/mac/carbon/listctrl_mac.cpp b/src/mac/carbon/listctrl_mac.cpp index a3dc96b13b..31dfaa7fa8 100644 --- a/src/mac/carbon/listctrl_mac.cpp +++ b/src/mac/carbon/listctrl_mac.cpp @@ -626,6 +626,12 @@ int wxListCtrl::GetItemCount() const return m_count; } +void wxListCtrl::SetItemSpacing( int spacing, bool isSmall ) +{ + if (m_genericImpl) + m_genericImpl->SetItemSpacing(spacing, isSmall); +} + wxSize wxListCtrl::GetItemSpacing() const { if (m_genericImpl) @@ -1018,6 +1024,11 @@ long wxListCtrl::InsertItem(wxListItem& info) return m_genericImpl->InsertItem(info); if (m_dbImpl){ + int count = GetItemCount(); + + if (info.m_itemId > count) + info.m_itemId = count; + m_dbImpl->MacInsertItem(info.m_itemId, &info ); wxListEvent event( wxEVT_COMMAND_LIST_INSERT_ITEM, GetId() ); event.SetEventObject( this ); @@ -1074,8 +1085,9 @@ long wxListCtrl::InsertColumn(long col, wxListItem& item) return m_genericImpl->InsertColumn(col, item); if (m_dbImpl){ - if ( !(item.GetMask() & wxLIST_MASK_WIDTH) ) //item.GetWidth() == 0) - item.SetWidth(300); + if ( !(item.GetMask() & wxLIST_MASK_WIDTH) ) + item.SetWidth(150); + DataBrowserPropertyType type = kDataBrowserTextType; wxImageList* imageList = GetImageList(wxIMAGE_LIST_SMALL); if (imageList && imageList->GetImageCount() > 0){ @@ -1094,7 +1106,17 @@ long wxListCtrl::InsertColumn(long col, wxListItem& item) else if (item.GetAlign() == wxLIST_FORMAT_RIGHT) just = teFlushRight; } - m_dbImpl->InsertColumn(col, type, item.GetText(), just, -1, item.GetWidth()); + m_dbImpl->InsertColumn(col, type, item.GetText(), just, item.GetWidth()); + + if (GetWindowStyleFlag() & wxLC_EDIT_LABELS) + { + DataBrowserTableViewColumnID id; + m_dbImpl->GetColumnIDFromIndex(col, &id); + DataBrowserPropertyFlags flags; + verify_noerr(m_dbImpl->GetPropertyFlags(id, &flags)); + flags |= kDataBrowserPropertyIsEditable; + verify_noerr(m_dbImpl->SetPropertyFlags(id, flags)); + } } return col; @@ -1234,7 +1256,7 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , DataBrowserItemDataRef itemData ) const { - wxMacDataBrowserListControl *lb = dynamic_cast(owner); + wxMacDataBrowserListCtrlControl *lb = dynamic_cast(owner); // we want to depend on as little as possible to make sure tear-down of controls is safe if ( message == kDataBrowserItemRemoved) @@ -1247,36 +1269,36 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , delete this; 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 gettting out now + return ; + } - // TO STEFAN: I'm getting a couple different problems here and I'd appreciate - // if you could take a look at them. - // 1) wxDynamicCast fails during shutdown. This doesn't suprise me, but - // you have similar listbox code, so I'm wondering why this case is different. - // 2) owner->GetLineFromItem( this ) always asserts. - // 3) the !lb->IsSelectionSuppressed code also fails with EXC_BAD_ACCESS - - // To be honest, I think there are casting issues here, but I don't work enough - // in C++ that these things are clear to me, so I'm hoping another pair of eyes - // would help. ;-) - // In any case, I set trigger to false so that these events are not sent. - - // during shutdown, this may fail. wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl ); if ( list ){ bool trigger = false; - wxCommandEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() ); + wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() ); bool isSingle = list->GetWindowStyle() | wxLC_SINGLE_SEL; + event.SetEventObject( list ); + event.m_itemIndex = owner->GetLineFromItem( this ) ; + if ( !list->IsVirtual() ) + { + lb->MacGetColumnInfo(event.m_itemIndex,0,event.m_item); + } + switch (message) { case kDataBrowserItemDeselected: event.SetEventType(wxEVT_COMMAND_LIST_ITEM_DESELECTED); - //if ( !isSingle ) - // trigger = !lb->IsSelectionSuppressed(); + if ( !isSingle ) + trigger = !lb->IsSelectionSuppressed(); break; case kDataBrowserItemSelected: - //trigger = !lb->IsSelectionSuppressed(); + trigger = !lb->IsSelectionSuppressed(); break; case kDataBrowserItemDoubleClicked: @@ -1284,24 +1306,27 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , 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 ) { - event.SetEventObject( list ); - //if ( list->HasClientObjectData() ) - // event.SetClientObject( (wxClientData*) m_data ); - //else if ( list->HasClientUntypedData() ) - // event.SetClientData( m_data ); - event.SetString( m_label ); - event.SetInt( owner->GetLineFromItem( this ) ); - event.SetExtraLong( !isSingle ? message == kDataBrowserItemSelected : true ); - wxPostEvent( list->GetEventHandler(), event ); - // direct notification is not always having the listbox GetSelection() having in synch with event - // list->GetEventHandler()->ProcessEvent(event); + wxPostEvent( list->GetEventHandler(), event ); } } @@ -1326,31 +1351,6 @@ wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer err = SetSelectionFlags( options ); verify_noerr( err ); - // create the numeric order column - DataBrowserListViewColumnDesc columnDesc; - columnDesc.headerBtnDesc.titleOffset = 0; - columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc; - - columnDesc.headerBtnDesc.btnFontStyle.flags = - kControlUseFontMask | kControlUseJustMask; - - columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent; - columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault; - columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont; - columnDesc.headerBtnDesc.btnFontStyle.style = normal; - columnDesc.headerBtnDesc.titleString = NULL; - - columnDesc.headerBtnDesc.minimumWidth = 0; - columnDesc.headerBtnDesc.maximumWidth = 0; - columnDesc.propertyDesc.propertyID = kNumericOrderColumnId; - columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart; - columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn; -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 - columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; -#endif - - verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); - if ( style & wxLC_LIST ){ InsertColumn(0, kDataBrowserIconAndTextType, wxEmptyString, -1, -1); verify_noerr( AutoSizeColumns() ); @@ -1373,7 +1373,7 @@ wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer else { m_sortOrder = SortOrder_None; - SetDataBrowserSortProperty( m_controlRef , kNumericOrderColumnId); + SetDataBrowserSortProperty( m_controlRef , kMinColumnId); SetDataBrowserSortOrder( m_controlRef , kDataBrowserOrderIncreasing); } @@ -1417,7 +1417,9 @@ void wxMacDataBrowserListCtrlControl::UpdateState(wxMacDataItem* dataItem, wxLis void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item ) { wxMacDataItem* dataItem = GetItemFromLine(row); - if (item){ + // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate + //if (item) + { wxMacListCtrlItem* listItem = dynamic_cast(dataItem); wxListItem* oldItem = listItem->GetColumnInfo( column ); @@ -1541,42 +1543,67 @@ OSStatus wxMacListCtrlItem::GetSetData( wxMacDataItemBrowserControl *owner , DataBrowserItemDataRef itemData, bool changeValue ) { + OSStatus err = errDataBrowserPropertyNotSupported; + wxListCtrl* list = wxDynamicCast( owner->GetPeer() , wxListCtrl ); if ( !changeValue ) { - if ( property >= kMinColumnId ){ - short listColumn = property - kMinColumnId; - - if (HasColumnInfo(listColumn)){ - wxListItem* item = GetColumnInfo(listColumn); - wxMacCFStringHolder cfStr; - - if (item->GetText()){ - cfStr.Assign( item->GetText(), wxLocale::GetSystemEncoding() ); - err = ::SetDataBrowserItemDataText( itemData, cfStr ); - err = noErr; + switch (property) + { + case kDataBrowserItemIsEditableProperty : + if ( list && list->HasFlag( wxLC_EDIT_LABELS ) ) + { + verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true )); + err = noErr ; } - - int imgIndex = item->GetImage(); - if (imgIndex != -1){ - wxListCtrl* list = wxDynamicCast( owner->GetPeer() , wxListCtrl ); - 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 ; + default : + if ( property >= kMinColumnId ){ + short listColumn = property - kMinColumnId; + + if (HasColumnInfo(listColumn)){ + wxListItem* item = GetColumnInfo(listColumn); + wxMacCFStringHolder cfStr; + + if (item->GetText()){ + cfStr.Assign( item->GetText(), wxLocale::GetSystemEncoding() ); + err = ::SetDataBrowserItemDataText( itemData, cfStr ); + err = noErr; + } + + int imgIndex = item->GetImage(); + if ( (item->GetMask() & wxLIST_MASK_IMAGE) ){ + 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) { - // no editable props here - default: + default: + if ( property >= kMinColumnId ){ + short listColumn = property - kMinColumnId; + + if (HasColumnInfo(listColumn)){ + // 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) ;; + list->SetItem( owner->GetLineFromItem(this) , listColumn, cfStr.AsString() ) ; + err = noErr ; + } + } break; } }