From 80150ab3011feeb1fd5ad4c2502f2508ee25dc6f Mon Sep 17 00:00:00 2001 From: HomeWorld Date: Sun, 18 Mar 2012 13:55:40 +0200 Subject: [PATCH] Use a 'fixed' HitTestSubItem in display.py (from ObjectListView) --- gui/display.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gui/display.py b/gui/display.py index 832b84307..17f9bf7a4 100644 --- a/gui/display.py +++ b/gui/display.py @@ -71,6 +71,46 @@ class Display(wx.ListCtrl): self.imageListBase = self.imageList.ImageCount +# Override native HitTestSubItem (doesn't work as it should on GTK) +# Source: ObjectListView + + def HitTestSubItem(self, pt): + """ + Return a tuple indicating which (item, subItem) the given pt (client coordinates) is over. + + This uses the buildin version on Windows, and poor mans replacement on other platforms. + """ + # The buildin version works on Windows + + if wx.Platform == "__WXMSW__": + return wx.ListCtrl.HitTestSubItem(self, pt) + + (rowIndex, flags) = self.HitTest(pt) + + # Did the point hit any item? + if (flags & wx.LIST_HITTEST_ONITEM) == 0: + return (-1, 0, -1) + + # If it did hit an item and we are not in report mode, it must be the primary cell + if not self.InReportView(): + return (rowIndex, wx.LIST_HITTEST_ONITEM, 0) + + # Find which subitem is hit + right = 0 + scrolledX = self.GetScrollPos(wx.HORIZONTAL) + pt.x + for i in range(self.GetColumnCount()): + left = right + right += self.GetColumnWidth(i) + if scrolledX < right: + if (scrolledX - left) < self.smallImageList.GetSize(0)[0]: + flag = wx.LIST_HITTEST_ONITEMICON + else: + flag = wx.LIST_HITTEST_ONITEMLABEL + return (rowIndex, flag, i) + + return (rowIndex, 0, -1) + + def OnEraseBk(self,event): if self.GetItemCount() >0: width, height = self.GetClientSize()