I have a window (wx.lib.scrolledpanel.ScrolledPanel) that displays some data.
I want to let the user double-click on a line, which would trigger an event which will open another window (that will display some additional data related to the line that was double-clicked).
Is there an easy way to know on which line in the window I am, regardless of which font I use ?
Namely, is there a way to know the location the mouse is in the window in terms of lines and characters from the beginning of line ?
How is the data display managed? Do you have a big statictext ctrl in there or lots of little controls – or an OnPaint handler that is printing into the ScrolledPanel?
I’m doing a Grand Experiment (ahem) of a sorta hyper-customized listctrl that’s entirely owner-drawn, and I ran into an issue which is similar: needing to hit test vs specific lines and cells in displayed records. Since I’m doing all of the display on an OnPaint handler, I store the location of each discrete line as an (x, y, width, height) tuple as I draw it.
So as I’m drawing, I calculate the current lines (x, y, width, height) – because I need to do a dc.DrawRectangle anyways, and I just store it after I draw it. Later, I get the Y coordinates of the click and iterate over my cached box rects to find which line I’m in… then I iterate over the lines columns/cells to determine which the X click-coordinate it fits in. It actually seems to perform pretty well. I’m sure there’s a better way but I haven’t been able to come up with it yet (primarily because in my scenario, the row heights are variable)
In your scenario, if you’re painting all the “lines and characters” at the time of painting you can use dc.GetTextExtent and store the coordinates/rects of individual items for scanning in your hit test code later.
Don’t know if that’s any use as its slightly vague, and there might be some Grand Better Way To Do It, but HTH
–Stephen