From: Kevin Ollivier Date: Wed, 11 Oct 2006 20:04:29 +0000 (+0000) Subject: Implementing column click event handler and SortItems function for native list ctrl. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/3fd864a139e5f141d5485fcb69907fdeaade2993 Implementing column click event handler and SortItems function for native list ctrl. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41949 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/mac/carbon/listctrl.h b/include/wx/mac/carbon/listctrl.h index d61a9c55fd..eb10af0065 100644 --- a/include/wx/mac/carbon/listctrl.h +++ b/include/wx/mac/carbon/listctrl.h @@ -13,6 +13,7 @@ #define _WX_LISTCTRL_H_ #include "wx/generic/listctrl.h" +#include class wxMacDataBrowserListCtrlControl; class wxMacListControl; @@ -306,6 +307,9 @@ class WXDLLEXPORT wxListCtrl: public wxControl void Command(wxCommandEvent& event) { ProcessCommand(event); }; + wxListCtrlCompare GetCompareFunc() { return m_compareFunc; }; + long GetCompareFuncData() { return m_compareFuncData; }; + protected: // overrides needed for pimpl approach virtual void DoSetSize(int x, int y, @@ -317,7 +321,10 @@ protected: wxGenericListCtrl* m_genericImpl; // allow use of the generic impl. wxMacDataBrowserListCtrlControl* m_dbImpl; - + EventHandlerRef m_macListCtrlEventHandler; + wxListCtrlCompare m_compareFunc; + long m_compareFuncData; + wxTextCtrl* m_textCtrl; // The control used for editing a label wxImageList * m_imageListNormal; // The image list for normal icons wxImageList * m_imageListSmall; // The image list for small icons diff --git a/src/mac/carbon/listctrl_mac.cpp b/src/mac/carbon/listctrl_mac.cpp index 4d6cf5726a..5a3d06a173 100644 --- a/src/mac/carbon/listctrl_mac.cpp +++ b/src/mac/carbon/listctrl_mac.cpp @@ -116,6 +116,51 @@ WX_DECLARE_EXPORTED_LIST(wxListItem, wxListItemList); #include "wx/listimpl.cpp" WX_DEFINE_LIST(wxListItemList) +// so we can check for column clicks +static const EventTypeSpec eventList[] = +{ + { kEventClassControl, kEventControlHit }, +}; + +static pascal OSStatus wxMacListCtrlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +{ + OSStatus result = eventNotHandledErr ; + + wxMacCarbonEvent cEvent( event ) ; + + ControlRef controlRef ; + cEvent.GetParameter( kEventParamDirectObject , &controlRef ) ; + + wxListCtrl *window = (wxListCtrl*) data ; + wxListEvent le( wxEVT_COMMAND_LIST_COL_CLICK, window->GetId() ); + le.SetEventObject( window ); + + switch ( GetEventKind( event ) ) + { + // check if the column was clicked on and fire an event if so + case kEventControlHit : + { + ControlPartCode result = cEvent.GetParameter(kEventParamControlPart, typeControlPartCode) ; + if (result == kControlButtonPart){ + DataBrowserPropertyID col; + GetDataBrowserSortProperty(controlRef, &col); + int column = col - kMinColumnId; + le.m_col = column; + window->GetEventHandler()->ProcessEvent( le ); + } + result = CallNextEventHandler(handler, event); + break; + } + default : + break ; + } + + + return result ; +} + +DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacListCtrlEventHandler ) + class wxMacListCtrlItem : public wxMacListBoxItem { public: @@ -209,6 +254,8 @@ void wxListCtrl::Init() m_textCtrl = NULL; m_genericImpl = NULL; m_dbImpl = NULL; + m_compareFunc = NULL; + m_compareFuncData = 0; } class wxGenericListCtrlHook : public wxGenericListCtrl @@ -284,8 +331,12 @@ bool wxListCtrl::Create(wxWindow *parent, return false; m_dbImpl = new wxMacDataBrowserListCtrlControl( this, pos, size, style ); m_peer = m_dbImpl; - + MacPostControlCreate( pos, size ); + + InstallControlEventHandler( m_peer->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(), + GetEventTypeCount(eventList), eventList, this, + (EventHandlerRef *)&m_macListCtrlEventHandler); } return true; @@ -1274,6 +1325,12 @@ bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data) { if (m_genericImpl) return m_genericImpl->SortItems(fn, data); + + if (m_dbImpl) + { + m_compareFunc = fn; + m_compareFuncData = data; + } return true; } @@ -1732,6 +1789,10 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI { wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID; wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID; + wxListCtrlCompare func = list->GetCompareFunc(); + if (func != NULL && item->HasColumnInfo(colId) && otherItem->HasColumnInfo(colId)) + return func(item->GetColumnInfo(colId)->GetData(), otherItem->GetColumnInfo(colId)->GetData(), list->GetCompareFuncData()) >= 0; + itemNum = item->GetOrder(); otherItemNum = otherItem->GetOrder(); if (item->HasColumnInfo(colId))