I need to find where the mouse has been clicked in a TextCtrl. To do
this I’ve been using “@lastPixelPt = evt.get_position” in my
evt_left_down method but have discovered that this gives me a physical
position in the visible window. It looks like I could probably use
get_logical_position(dc) to get a position relative to the text in the
control, that is adjusted for scrolling, but I haven’t found how to set
up dc (device context). I would greatly appreciate an example of how to
set up dc so that “@lastPixelPt = evt.get_logical_position(dc)” will
work or any advice I can get about getting a position relative to the
text in the control.
Thank you,
Ross Goodell
Ross Goodell wrote:
I need to find where the mouse has been clicked in a TextCtrl.
Do you want the character position, or the unscrolled pixel position? If
it’s just the character position, use TextCtrl#hit_test plus possibly
#xy_to_position.
For some reason, wxWidgets doesn’t provide TextCtrl#hit_test on Mac, but
it’s not hard to do your own implementation. I have one kicking around
somewhere if that’s what you need.
To do
this I’ve been using “@lastPixelPt = evt.get_position” in my
evt_left_down method but have discovered that this gives me a physical
position in the visible window. It looks like I could probably use
get_logical_position(dc) to get a position relative to the text in the
control, that is adjusted for scrolling,
If you want the pixel position taking into account scrolling, then
TextCtrl may not work for you. There isn’t a way to get the scroll
position in pixels - get_scroll_pos doesn’t work for TextCtrl in
wxWidgets. As I understand it, this is down to limitations of the
underlying OSes - the native controls don’t all support getting the
scroll position in pixels.
You might try using RichTextCtrl, which has a get_view_start method to
return the x, y scrolling offset.
alex
Alex F. wrote:
Do you want the character position, or the unscrolled pixel position? If
it’s just the character position, use TextCtrl#hit_test plus possibly
#xy_to_position.
Yes, I think the character position is all that I really need, and
hit_test does the job for me
For some reason, wxWidgets doesn’t provide TextCtrl#hit_test on Mac, but
it’s not hard to do your own implementation. I have one kicking around
somewhere if that’s what you need.
Thanks. That’s good to know. For now I’m concentrating on getting my
program working on MS Windows.
If you want the pixel position taking into account scrolling, then
TextCtrl may not work for you. There isn’t a way to get the scroll
position in pixels - get_scroll_pos doesn’t work for TextCtrl in
wxWidgets. As I understand it, this is down to limitations of the
underlying OSes - the native controls don’t all support getting the
scroll position in pixels.
You might try using RichTextCtrl, which has a get_view_start method to
return the x, y scrolling offset.
alex
You’ve gotten me out of a jam again. Thank you very much. And thanks
for the tip on RichTextCtrl, which I might want to use in a later
version.
Ross