From 8158e0e169f1deb45cfffe9c50453bb926fdcd5c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Jul 2004 12:32:59 +0000 Subject: [PATCH] FindItem() implementation (patch 950021) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28461 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/generic/listctrl.cpp | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 49816121ee..3a5d5ca425 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -217,6 +217,7 @@ All (GUI): - wxTextCtrl::OnChar now inserts a tab character if wxTE_PROCESS_TAB is set - added wxKeyEvent::GetUnicodeKey() - added wxKeyEvent::CmdDown() and wxMouseEvent::CmdDown() +- implemented wxListCtrl::FindItem() for non-MSW (Robin Stoll) Unix: diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index f4ae560cec..32f5bd7060 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -76,6 +76,9 @@ #include "wx/mac/private.h" #endif +#include + + // NOTE: If using the wxListBox visual attributes works everywhere then this can // be removed, as well as the #else case below. #define _USE_VISATTR 0 @@ -677,6 +680,7 @@ public: void EnsureVisible( long index ); long FindItem( long start, const wxString& str, bool partial = false ); long FindItem( long start, long data); + long FindItem( const wxPoint& pt ); long HitTest( int x, int y, int &flags ); void InsertItem( wxListItem &item ); void InsertColumn( long col, wxListItem &item ); @@ -4284,6 +4288,21 @@ long wxListMainWindow::FindItem(long start, long data) return wxNOT_FOUND; } +long wxListMainWindow::FindItem( const wxPoint& pt ) +{ + wxPoint p; + long topItem = GetTopItem(); + + GetItemPosition( GetItemCount()-1, p ); + if( p.y == 0 ) + return topItem; + long id = (long) floor( pt.y*(GetItemCount()-topItem-1)/p.y+topItem ); + if( id >= 0 && id < (long)GetItemCount() ) + return id; + + return wxNOT_FOUND; +} + long wxListMainWindow::HitTest( int x, int y, int &flags ) { CalcUnscrolledPosition( x, y, &x, &y ); @@ -5059,10 +5078,10 @@ long wxGenericListCtrl::FindItem( long start, long data ) return m_mainWin->FindItem( start, data ); } -long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), +long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt, int WXUNUSED(direction)) { - return 0; + return m_mainWin->FindItem( pt ); } long wxGenericListCtrl::HitTest( const wxPoint &point, int &flags ) -- 2.45.2