]> git.saurik.com Git - wxWidgets.git/commitdiff
Implementing LIST_ITEM_RIGHT_CLICK event support, and fixing sorting (turning off...
authorKevin Ollivier <kevino@theolliviers.com>
Sun, 24 Dec 2006 18:39:40 +0000 (18:39 +0000)
committerKevin Ollivier <kevino@theolliviers.com>
Sun, 24 Dec 2006 18:39:40 +0000 (18:39 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/mac/carbon/listctrl.h
src/mac/carbon/listctrl_mac.cpp

index 821f2568ab70757d305b461efe2f6f02b39e903c..5f28a5a27819162b6e5e36018ae1fa2f8fc1d481 100644 (file)
@@ -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)
index 1ff5991fec86a40cc2079a9d8fa76e5823e17594..f855a233ee7ba6fd87c6bc20290ee52cb7108902 100644 (file)
@@ -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_Text_Ascending;
-        SetSortOrder( kDataBrowserOrderIncreasing );
-    }
-    else if ( style & wxLC_SORT_DESCENDING )
+    
+    m_sortOrder = SortOrder_None;
+    
+    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 );