From ccea21ccf8a8c7f2012c890c9c1b916d0e725db2 Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Sun, 24 Dec 2006 18:39:40 +0000 Subject: [PATCH] Implementing LIST_ITEM_RIGHT_CLICK event support, and fixing sorting (turning off code for native sorting). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/carbon/listctrl.h | 1 + src/mac/carbon/listctrl_mac.cpp | 76 ++++++++++++++++---------------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/include/wx/mac/carbon/listctrl.h b/include/wx/mac/carbon/listctrl.h index 821f2568ab..5f28a5a278 100644 --- a/include/wx/mac/carbon/listctrl.h +++ b/include/wx/mac/carbon/listctrl.h @@ -331,6 +331,7 @@ class WXDLLEXPORT wxListCtrl: public wxControl bool HasCurrent() const { return m_current != (long)-1; } void OnLeftDown(wxMouseEvent& event); + void OnRightDown(wxMouseEvent& event); void OnDblClick(wxMouseEvent& event); void FinishEditing(wxTextCtrl *text) diff --git a/src/mac/carbon/listctrl_mac.cpp b/src/mac/carbon/listctrl_mac.cpp index 1ff5991fec..f855a233ee 100644 --- a/src/mac/carbon/listctrl_mac.cpp +++ b/src/mac/carbon/listctrl_mac.cpp @@ -507,6 +507,7 @@ void wxListCtrlTextCtrlWrapper::OnKillFocus( wxFocusEvent &event ) BEGIN_EVENT_TABLE(wxListCtrl, wxControl) EVT_LEFT_DOWN(wxListCtrl::OnLeftDown) EVT_LEFT_DCLICK(wxListCtrl::OnDblClick) + EVT_RIGHT_DOWN(wxListCtrl::OnRightDown) END_EVENT_TABLE() // ============================================================================ @@ -610,6 +611,30 @@ void wxListCtrl::OnLeftDown(wxMouseEvent& event) event.Skip(); } +void wxListCtrl::OnRightDown(wxMouseEvent& event) +{ + wxListEvent le( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, GetId() ); + le.SetEventObject(this); + le.m_pointDrag = event.GetPosition(); + le.m_itemIndex = -1; + + int flags; + long item = HitTest(event.GetPosition(), flags); + if (flags & wxLIST_HITTEST_ONITEM) + { + le.m_itemIndex = item; + if (!IsVirtual()) + { + + le.m_item.m_itemId = item; + GetItem(le.m_item); + } + } + + GetEventHandler()->ProcessEvent(le); + event.Skip(); +} + void wxListCtrl::OnDblClick(wxMouseEvent& event) { m_current = -1; @@ -2354,19 +2379,16 @@ wxMacDataBrowserListCtrlControl::wxMacDataBrowserListCtrlControl( wxWindow *peer SetSortProperty( kMinColumnId - 1 ); else SetSortProperty( kMinColumnId ); - if ( style & wxLC_SORT_ASCENDING ) + + m_sortOrder = SortOrder_None; + + if ( style & wxLC_SORT_DESCENDING ) { - m_sortOrder = SortOrder_Text_Ascending; - SetSortOrder( kDataBrowserOrderIncreasing ); - } - else if ( style & wxLC_SORT_DESCENDING ) - { - m_sortOrder = SortOrder_Text_Descending; SetSortOrder( kDataBrowserOrderDecreasing ); } - else + else if ( style & wxLC_SORT_ASCENDING ) { - m_sortOrder = SortOrder_None; + SetSortOrder( kDataBrowserOrderIncreasing ); } if ( style & wxLC_VRULES ) @@ -2880,6 +2902,9 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID; wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID; + itemOrder = item->GetOrder(); + otherItemOrder = item->GetOrder(); + wxListCtrlCompare func = list->GetCompareFunc(); if (func != NULL) { @@ -2899,19 +2924,10 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI return result < 0; } } - - if (item->HasColumnInfo(colId)) - { - wxListItem* colItem = item->GetColumnInfo(colId); - itemText = colItem->GetText(); - itemOrder = colItem->GetId(); - } - if (otherItem->HasColumnInfo(colId)) - { - wxListItem* colItem = otherItem->GetColumnInfo(colId); - otherItemText = colItem->GetText(); - otherItemOrder = colItem->GetId(); - } + + // we can't use the native control's sorting abilities, so just + // sort by item id. + return itemOrder < otherItemOrder; } else { @@ -2923,21 +2939,6 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI // virtual listctrls don't support sorting return itemNum < otherItemNum; - - - } - - if ( sort == kDataBrowserOrderIncreasing && !m_sortOrder == SortOrder_None ) - { - retval = itemText.CmpNoCase( otherItemText ) > 0; - } - else if ( sort == kDataBrowserOrderDecreasing && !m_sortOrder == SortOrder_None ) - { - retval = itemText.CmpNoCase( otherItemText ) < 0; - } - else - { - retval = itemOrder < otherItemOrder; } } else{ @@ -2961,6 +2962,7 @@ void wxMacDataBrowserListCtrlControl::MacSetColumnInfo( unsigned int row, unsign wxMacListCtrlItem* listItem = wx_static_cast(wxMacListCtrlItem*,dataItem); bool hasInfo = listItem->HasColumnInfo( column ); listItem->SetColumnInfo( column, item ); + listItem->SetOrder(row); UpdateState(dataItem, item); wxListCtrl* list = wxDynamicCast( GetPeer() , wxListCtrl );