diff --git a/gui/builtinAdditionPanes/droneView.py b/gui/builtinAdditionPanes/droneView.py index 9afa30190..dfd5b5ba4 100644 --- a/gui/builtinAdditionPanes/droneView.py +++ b/gui/builtinAdditionPanes/droneView.py @@ -296,7 +296,7 @@ class DroneView(Display): def spawnMenu(self, event): selection = self.getSelectedDrones() - clickedPos = self.getRow(event.Position) + clickedPos = self.getRowByAbs(event.Position) mainDrone = None if clickedPos != -1: try: diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index 5ba353793..d54febe0a 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -653,7 +653,7 @@ class FittingView(d.Display): fit = sFit.getFit(self.activeFitID) contexts.append(("fittingShip", "Ship" if not fit.isStructure else "Citadel")) - clickedPos = self.getRow(event.Position) + clickedPos = self.getRowByAbs(event.Position) mainMod = None if clickedPos != -1: try: diff --git a/gui/display.py b/gui/display.py index 5a77dd3cb..94c3e0462 100644 --- a/gui/display.py +++ b/gui/display.py @@ -272,19 +272,28 @@ class Display(wx.ListCtrl): def columnBackground(self, colItem, item): return colItem.GetBackgroundColour() - def getRow(self, pointAbs, fallback=None): + def getRowByAbs(self, pointAbs): if pointAbs == wx.Point(-1, -1): return -1 pointRel = self.ScreenToClient(pointAbs) - # HitTest seems to ignore header row, do some workarounds here - # https://github.com/wxWidgets/Phoenix/issues/1213 - row = self.HitTest(pointRel)[0] - if row != -1: - return row - 1 - if fallback is not None: - return fallback + row, flags = self.HitTest(pointRel) return row + def ScreenToClient(self, ptScreen): + """ + Wx' ScreenToClient implementation seems to not consider header row height when + converting to screen position: https://github.com/wxWidgets/Phoenix/issues/1213 + Do it ourselves here. + """ + if ptScreen == wx.Point(-1, -1): + return wx.Point(-1, -1) + for window in self.GetChildren(): + if window.GetName() == 'panel': + ptCorrection = window.GetPosition() + ptScreen = ptScreen - ptCorrection + ptClient = wx.ListCtrl.ScreenToClient(self, ptScreen) + return ptClient + def getSelectedRows(self): rows = [] row = self.GetFirstSelected()