X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f0c8f31f407ecfce909060464c0ea655221cdab..f8d0234d39c66f3d1d7fc2346562cb96c8c7be20:/src/osx/carbon/listctrl_mac.cpp diff --git a/src/osx/carbon/listctrl_mac.cpp b/src/osx/carbon/listctrl_mac.cpp index 64641fae9c..c916795c59 100644 --- a/src/osx/carbon/listctrl_mac.cpp +++ b/src/osx/carbon/listctrl_mac.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/listctrl_mac.cpp +// Name: src/osx/listctrl_mac.cpp // Purpose: wxListCtrl // Author: Julian Smart // Modified by: Agron Selimaj @@ -148,7 +148,10 @@ static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , if (result == kControlButtonPart){ DataBrowserPropertyID col; GetDataBrowserSortProperty(controlRef, &col); - int column = col - kMinColumnId; + + DataBrowserTableViewColumnIndex column = 0; + verify_noerr( GetDataBrowserTableViewColumnPosition( controlRef, col, &column ) ); + le.m_col = column; // FIXME: we can't use the sort property for virtual listctrls // so we need to find a better way to determine which column was clicked... @@ -176,7 +179,7 @@ static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler ) -class wxMacListCtrlItem : public wxMacListBoxItem +class wxMacListCtrlItem : public wxMacDataItem { public: wxMacListCtrlItem(); @@ -214,8 +217,6 @@ public: // create a list item (can be a subclass of wxMacListBoxItem) - virtual wxMacDataItem* CreateItem(); - virtual void MacInsertItem( unsigned int n, wxListItem* item ); virtual void MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item ); virtual void MacGetColumnInfo( unsigned int row, unsigned int column, wxListItem& item ); @@ -517,10 +518,9 @@ END_EVENT_TABLE() // implementation // ============================================================================ -wxMacListControl* wxListCtrl::GetPeer() const +wxMacDataBrowserListCtrlControl* wxListCtrl::GetListPeer() const { - wxMacDataBrowserListCtrlControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserListCtrlControl); - return lb ? wx_static_cast(wxMacListControl*,lb) : 0 ; + return dynamic_cast ( GetPeer() ); } // ---------------------------------------------------------------------------- @@ -894,7 +894,7 @@ bool wxListCtrl::SetBackgroundColour(const wxColour& colour) return rv; } -wxColour wxListCtrl::GetBackgroundColour() +wxColour wxListCtrl::GetBackgroundColour() const { if (m_genericImpl) return m_genericImpl->GetBackgroundColour(); @@ -948,13 +948,9 @@ bool wxListCtrl::SetColumn(int col, wxListItem& item) if (m_dbImpl) { + wxASSERT_MSG( col < (int)m_colsInfo.GetCount(), _T("invalid column index in wxMacListCtrlItem") ); + long mask = item.GetMask(); - if ( col >= (int)m_colsInfo.GetCount() ) - { - wxListItem* listItem = new wxListItem(item); - m_colsInfo.Append( listItem ); - } - else { wxListItem listItem; GetColumn( col, listItem ); @@ -976,7 +972,10 @@ bool wxListCtrl::SetColumn(int col, wxListItem& item) // change the appearance in the databrowser. DataBrowserListViewHeaderDesc columnDesc; columnDesc.version=kDataBrowserListViewLatestHeaderDesc; - verify_noerr( m_dbImpl->GetHeaderDesc( kMinColumnId + col, &columnDesc ) ); + + DataBrowserTableViewColumnID id = 0; + verify_noerr( m_dbImpl->GetColumnIDFromIndex( col, &id ) ); + verify_noerr( m_dbImpl->GetHeaderDesc( id, &columnDesc ) ); /* if (item.GetMask() & wxLIST_MASK_TEXT) @@ -1006,7 +1005,7 @@ bool wxListCtrl::SetColumn(int col, wxListItem& item) } } - verify_noerr( m_dbImpl->SetHeaderDesc( kMinColumnId + col, &columnDesc ) ); + verify_noerr( m_dbImpl->SetHeaderDesc( id, &columnDesc ) ); } return true; @@ -1386,6 +1385,15 @@ wxRect wxListCtrl::GetViewRect() const return rect; } +bool wxListCtrl::GetSubItemRect( long item, long subItem, wxRect& rect, int code ) const +{ + if (m_genericImpl) + return m_genericImpl->GetItemRect(item, rect, code); + + // TODO: implement for DataBrowser implementation + return false; +} + // Gets the item rectangle bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const { @@ -1396,7 +1404,10 @@ bool wxListCtrl::GetItemRect(long item, wxRect& rect, int code) const if (m_dbImpl) { DataBrowserItemID id; - DataBrowserPropertyID col = kMinColumnId; + + DataBrowserTableViewColumnID col = 0; + verify_noerr( m_dbImpl->GetColumnIDFromIndex( 0, &col ) ); + Rect bounds; DataBrowserPropertyPart part = kDataBrowserPropertyEnclosingPart; if ( code == wxLIST_RECT_LABEL ) @@ -1877,7 +1888,11 @@ bool wxListCtrl::EndEditLabel(bool WXUNUSED(cancel)) return true; // m_genericImpl->EndEditLabel(cancel); if (m_dbImpl) - verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, kMinColumnId) ); + { + DataBrowserTableViewColumnID id = 0; + verify_noerr( m_dbImpl->GetColumnIDFromIndex( 0, &id ) ); + verify_noerr( SetDataBrowserEditItem(m_dbImpl->GetControlRef(), kDataBrowserNoItem, id ) ); + } return true; } @@ -2132,6 +2147,9 @@ long wxListCtrl::InsertColumn(long col, wxListItem& item) just = teFlushRight; } m_dbImpl->InsertColumn(col, type, item.GetText(), just, width); + + wxListItem* listItem = new wxListItem(item); + m_colsInfo.Insert( col, listItem ); SetColumn(col, item); // set/remove options based on the wxListCtrl type. @@ -2433,11 +2451,6 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , // we want to depend on as little as possible to make sure tear-down of controls is safe if ( message == kDataBrowserItemRemoved) { - if ( lb != NULL && lb->GetClientDataType() == wxClientData_Object ) - { - delete (wxClientData*) (m_data); - } - delete this; return; } @@ -2448,7 +2461,7 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , return ; } - wxListCtrl *list = wxDynamicCast( owner->GetPeer() , wxListCtrl ); + wxListCtrl *list = wxDynamicCast( owner->GetWXPeer() , wxListCtrl ); if ( list && lb ) { bool trigger = false; @@ -2667,9 +2680,11 @@ void wxMacDataBrowserListCtrlControl::DrawItem( wxString text; wxFont font = wxNullFont; int imgIndex = -1; - short listColumn = property - kMinColumnId; - - wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl ); + + DataBrowserTableViewColumnIndex listColumn = 0; + OSStatus err = GetColumnPosition( property, &listColumn ); + + wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); wxMacListCtrlItem* lcItem; wxColour color = *wxBLACK; wxColour bgColor = wxNullColour; @@ -2679,7 +2694,8 @@ void wxMacDataBrowserListCtrlControl::DrawItem( if (!m_isVirtual) { lcItem = (wxMacListCtrlItem*) itemID; - if (lcItem->HasColumnInfo(listColumn)){ + if (lcItem->HasColumnInfo(listColumn)) + { wxListItem* item = lcItem->GetColumnInfo(listColumn); // we always use the 0 column to get font and text/background colors. @@ -2829,7 +2845,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem( HIThemeTextHorizontalFlush hFlush = kHIThemeTextHorizontalFlushLeft; HIThemeTextInfo info; bool setup = false; -#if wxMAC_USE_CORE_TEXT +#if wxOSX_USE_CORE_TEXT if ( UMAGetSystemVersion() >= 0x1050 ) { info.version = kHIThemeTextInfoVersionOne; @@ -2842,7 +2858,7 @@ void wxMacDataBrowserListCtrlControl::DrawItem( } } #endif -#if wxMAC_USE_ATSU_TEXT +#if wxOSX_USE_ATSU_TEXT if ( !setup ) { info.version = kHIThemeTextInfoVersionZero; @@ -2902,10 +2918,12 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI { wxString text; int imgIndex = -1; - short listColumn = property - kMinColumnId; + + DataBrowserTableViewColumnIndex listColumn = 0; + verify_noerr( GetColumnPosition( property, &listColumn ) ); OSStatus err = errDataBrowserPropertyNotSupported; - wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl ); + wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); wxMacListCtrlItem* lcItem = NULL; if (listColumn >= 0) @@ -2976,7 +2994,8 @@ OSStatus wxMacDataBrowserListCtrlControl::GetSetItemData(DataBrowserItemID itemI default: if ( property >= kMinColumnId ) { - short listColumn = property - kMinColumnId; + DataBrowserTableViewColumnIndex listColumn = 0; + verify_noerr( GetColumnPosition( property, &listColumn ) ); // TODO probably send the 'end edit' from here, as we // can then deal with the veto @@ -3024,7 +3043,7 @@ void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID, return ; } - wxListCtrl *list = wxDynamicCast( GetPeer() , wxListCtrl ); + wxListCtrl *list = wxDynamicCast( GetWXPeer() , wxListCtrl ); if ( list ) { bool trigger = false; @@ -3100,9 +3119,10 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI long itemOrder; long otherItemOrder; - int colId = sortProperty - kMinColumnId; + DataBrowserTableViewColumnIndex colId = 0; + verify_noerr( GetColumnPosition( sortProperty, &colId ) ); - wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl ); + wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); DataBrowserSortOrder sort; verify_noerr(GetSortOrder(&sort)); @@ -3115,11 +3135,12 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID; itemOrder = item->GetOrder(); - otherItemOrder = item->GetOrder(); + otherItemOrder = otherItem->GetOrder(); wxListCtrlCompare func = list->GetCompareFunc(); if (func != NULL) { + long item1 = -1; long item2 = -1; if (item && item->HasColumnInfo(0)) @@ -3169,13 +3190,13 @@ void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsign wxASSERT_MSG( dataItem, _T("could not obtain wxMacDataItem for row in MacSetColumnInfo. Is row a valid wxListCtrl row?") ); if (item) { - wxMacListCtrlItem* listItem = wx_static_cast(wxMacListCtrlItem*,dataItem); + wxMacListCtrlItem* listItem = static_cast(dataItem); bool hasInfo = listItem->HasColumnInfo( column ); listItem->SetColumnInfo( column, item ); listItem->SetOrder(row); UpdateState(dataItem, item); - wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl ); + wxListCtrl* list = wxDynamicCast( GetWXPeer() , wxListCtrl ); // NB: When this call was made before a control was completely shown, it would // update the item prematurely (i.e. no text would be listed) and, on show, @@ -3183,7 +3204,11 @@ void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsign // would be shown. Making sure not to update items until the control is visible // seems to fix this issue. if (hasInfo && list->IsShown()) - UpdateItem( wxMacDataBrowserRootContainer, listItem , kMinColumnId + column ); + { + DataBrowserTableViewColumnID id = 0; + verify_noerr( GetColumnIDFromIndex( column, &id ) ); + UpdateItem( wxMacDataBrowserRootContainer, listItem , id ); + } } } @@ -3212,7 +3237,7 @@ void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsign // CS should this guard against dataItem = 0 ? , as item is not a pointer if (item) is not appropriate //if (item) { - wxMacListCtrlItem* listItem =wx_static_cast(wxMacListCtrlItem*,dataItem); + wxMacListCtrlItem* listItem = static_cast(dataItem); if (!listItem->HasColumnInfo( column )) return; @@ -3245,18 +3270,14 @@ void wxMacDataBrowserListCtrlControl::MacGetColumnInfo( unsigned int row, unsign } } } - + void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* item ) { - wxMacDataItemBrowserControl::MacInsert(n, item->GetText()); + + wxMacDataItemBrowserControl::MacInsert(n, new wxMacListCtrlItem() ); MacSetColumnInfo(n, 0, item); } -wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem() -{ - return new wxMacListCtrlItem(); -} - wxMacListCtrlItem::wxMacListCtrlItem() { m_rowItems = wxListItemList(); @@ -3278,9 +3299,10 @@ void wxMacListCtrlItem::SetColumnImageValue( unsigned int column, int imageIndex wxString wxMacListCtrlItem::GetColumnTextValue( unsigned int column ) { +/* TODO CHECK REMOVE if ( column == 0 ) return GetLabel(); - +*/ if ( HasColumnInfo(column) ) return GetColumnInfo(column)->GetText(); @@ -3292,9 +3314,11 @@ void wxMacListCtrlItem::SetColumnTextValue( unsigned int column, const wxString& if ( HasColumnInfo(column) ) GetColumnInfo(column)->SetText(text); +/* TODO CHECK REMOVE // for compatibility with superclass APIs if ( column == 0 ) SetLabel(text); +*/ } wxListItem* wxMacListCtrlItem::GetColumnInfo( unsigned int column )