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
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#define _WX_LISTCTRL_H_
|
#define _WX_LISTCTRL_H_
|
||||||
|
|
||||||
#include "wx/generic/listctrl.h"
|
#include "wx/generic/listctrl.h"
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
|
|
||||||
class wxMacDataBrowserListCtrlControl;
|
class wxMacDataBrowserListCtrlControl;
|
||||||
class wxMacListControl;
|
class wxMacListControl;
|
||||||
@@ -306,6 +307,9 @@ class WXDLLEXPORT wxListCtrl: public wxControl
|
|||||||
|
|
||||||
void Command(wxCommandEvent& event) { ProcessCommand(event); };
|
void Command(wxCommandEvent& event) { ProcessCommand(event); };
|
||||||
|
|
||||||
|
wxListCtrlCompare GetCompareFunc() { return m_compareFunc; };
|
||||||
|
long GetCompareFuncData() { return m_compareFuncData; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// overrides needed for pimpl approach
|
// overrides needed for pimpl approach
|
||||||
virtual void DoSetSize(int x, int y,
|
virtual void DoSetSize(int x, int y,
|
||||||
@@ -317,6 +321,9 @@ protected:
|
|||||||
|
|
||||||
wxGenericListCtrl* m_genericImpl; // allow use of the generic impl.
|
wxGenericListCtrl* m_genericImpl; // allow use of the generic impl.
|
||||||
wxMacDataBrowserListCtrlControl* m_dbImpl;
|
wxMacDataBrowserListCtrlControl* m_dbImpl;
|
||||||
|
EventHandlerRef m_macListCtrlEventHandler;
|
||||||
|
wxListCtrlCompare m_compareFunc;
|
||||||
|
long m_compareFuncData;
|
||||||
|
|
||||||
wxTextCtrl* m_textCtrl; // The control used for editing a label
|
wxTextCtrl* m_textCtrl; // The control used for editing a label
|
||||||
wxImageList * m_imageListNormal; // The image list for normal icons
|
wxImageList * m_imageListNormal; // The image list for normal icons
|
||||||
|
@@ -116,6 +116,51 @@ WX_DECLARE_EXPORTED_LIST(wxListItem, wxListItemList);
|
|||||||
#include "wx/listimpl.cpp"
|
#include "wx/listimpl.cpp"
|
||||||
WX_DEFINE_LIST(wxListItemList)
|
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<ControlPartCode>(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
|
class wxMacListCtrlItem : public wxMacListBoxItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -209,6 +254,8 @@ void wxListCtrl::Init()
|
|||||||
m_textCtrl = NULL;
|
m_textCtrl = NULL;
|
||||||
m_genericImpl = NULL;
|
m_genericImpl = NULL;
|
||||||
m_dbImpl = NULL;
|
m_dbImpl = NULL;
|
||||||
|
m_compareFunc = NULL;
|
||||||
|
m_compareFuncData = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
class wxGenericListCtrlHook : public wxGenericListCtrl
|
class wxGenericListCtrlHook : public wxGenericListCtrl
|
||||||
@@ -286,6 +333,10 @@ bool wxListCtrl::Create(wxWindow *parent,
|
|||||||
m_peer = m_dbImpl;
|
m_peer = m_dbImpl;
|
||||||
|
|
||||||
MacPostControlCreate( pos, size );
|
MacPostControlCreate( pos, size );
|
||||||
|
|
||||||
|
InstallControlEventHandler( m_peer->GetControlRef() , GetwxMacListCtrlEventHandlerUPP(),
|
||||||
|
GetEventTypeCount(eventList), eventList, this,
|
||||||
|
(EventHandlerRef *)&m_macListCtrlEventHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1275,6 +1326,12 @@ bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
|
|||||||
if (m_genericImpl)
|
if (m_genericImpl)
|
||||||
return m_genericImpl->SortItems(fn, data);
|
return m_genericImpl->SortItems(fn, data);
|
||||||
|
|
||||||
|
if (m_dbImpl)
|
||||||
|
{
|
||||||
|
m_compareFunc = fn;
|
||||||
|
m_compareFuncData = data;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1732,6 +1789,10 @@ Boolean wxMacDataBrowserListCtrlControl::CompareItems(DataBrowserItemID itemOneI
|
|||||||
{
|
{
|
||||||
wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
|
wxMacListCtrlItem* item = (wxMacListCtrlItem*)itemOneID;
|
||||||
wxMacListCtrlItem* otherItem = (wxMacListCtrlItem*)itemTwoID;
|
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();
|
itemNum = item->GetOrder();
|
||||||
otherItemNum = otherItem->GetOrder();
|
otherItemNum = otherItem->GetOrder();
|
||||||
if (item->HasColumnInfo(colId))
|
if (item->HasColumnInfo(colId))
|
||||||
|
Reference in New Issue
Block a user