X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/493e7eb40cc0ef1ad1bacb1c209ec4020fd9efe9..80a779275ae04443c568dca919adb26cf6f5002c:/src/mac/carbon/listctrl_mac.cpp?ds=inline diff --git a/src/mac/carbon/listctrl_mac.cpp b/src/mac/carbon/listctrl_mac.cpp index fcefba941e..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: @@ -149,7 +194,7 @@ public: // create a list item (can be a subclass of wxMacListBoxItem) - virtual wxMacListCtrlItem* CreateItem(); + virtual wxMacDataItem* CreateItem(); virtual void MacInsertItem( unsigned int n, wxListItem* item ); virtual void MacSetColumnInfo( unsigned int row, unsigned int column, wxListItem* item ); @@ -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 @@ -226,6 +273,7 @@ public: { } +protected: virtual wxListItemAttr * OnGetItemAttr(long item) const { return m_nativeListCtrl->OnGetItemAttr(item); @@ -246,7 +294,6 @@ public: return m_nativeListCtrl->OnGetItemText(item, column); } -protected: wxListCtrl* m_nativeListCtrl; }; @@ -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; } @@ -1414,7 +1471,7 @@ void wxMacListCtrlItem::Notification(wxMacDataItemBrowserControl *owner , bool trigger = false; wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() ); - bool isSingle = list->GetWindowStyle() | wxLC_SINGLE_SEL; + bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0; event.SetEventObject( list ); event.m_itemIndex = owner->GetLineFromItem( this ) ; @@ -1642,7 +1699,7 @@ void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID, else if ( message == kDataBrowserItemAdded ) { // we don't issue events on adding, the item is not really stored in the list yet, so we - // avoid asserts by gettting out now + // avoid asserts by getting out now return ; } @@ -1652,7 +1709,7 @@ void wxMacDataBrowserListCtrlControl::ItemNotification(DataBrowserItemID itemID, bool trigger = false; wxListEvent event( wxEVT_COMMAND_LIST_ITEM_SELECTED, list->GetId() ); - bool isSingle = list->GetWindowStyle() | wxLC_SINGLE_SEL; + bool isSingle = (list->GetWindowStyle() & wxLC_SINGLE_SEL) != 0; event.SetEventObject( list ); if ( !list->IsVirtual() ) @@ -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)) @@ -1840,7 +1901,7 @@ void wxMacDataBrowserListCtrlControl::MacInsertItem( unsigned int n, wxListItem* MacSetColumnInfo(n, 0, item); } -wxMacListCtrlItem* wxMacDataBrowserListCtrlControl::CreateItem() +wxMacDataItem* wxMacDataBrowserListCtrlControl::CreateItem() { return new wxMacListCtrlItem(); }