PxPlus User Forum

Main Board => Discussions => Programming => Topic started by: steezware on December 04, 2023, 06:21:57 PM

Title: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
Post by: steezware on December 04, 2023, 06:21:57 PM
In a multi-line control I want to grab the portion of the text that the user has selected.

For example...
This is in Nomads, under *Nomads object control, and I do not have any OnFocus or OnSelect logic tied to the multiline control either in the Nomads panel definition or in my UI class (although I have tried using them and signal-all-changes and signal-on-exit and everything else I could think of).

I can, of course, do a ML'SelectOffset=6 and ML'SelectLength=5 and manually highlight "World", so that works...

...but how to I grab "World" when the user selects it and leaves the multiline control?

Help? Thx!
Title: Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
Post by: Arno de Greef on December 06, 2023, 10:46:41 AM
I see the same thing happen, however if I change the multi-line height to 2 (a multi-line multi-line  :D), the problem seems to disappear.
Title: Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
Post by: steezware on December 06, 2023, 12:45:40 PM
Turns out that fetching 'SelectOffset and 'SelectLenght does work just fine, but the problem I am having turns out to be that the multiline control as it loses focus clears out the selection. So I need to figure out how to grab the offset/length when Nomads moves off the multiline before it loses focus?

I have tried 'Change and 'OnFocus and even thought maybe 'Validator or 'Formatter Nomads class functions would fire allow me to jump in and get the select offset/length, but no luck.

Or is there some multiline option/attribute that needs to be set to preserve the text selection when the multiline loses focus?
Title: Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
Post by: steezware on December 06, 2023, 02:22:21 PM
Okay, putting this question/issue to rest. Arno was correct when he mentioned that making the multiline 2 rows high allowed for fetching 'SelectOffset, 'SelectLength and 'SelectText$.

So, I faked out my panel by making the multiline borderless and 2 lines high. I also messed around with making the font double-sized, which had an affect on fetching the offset and length.

Question to PxPlus is - why is it so difficult to fetch the offset and length of selected text in a multiline without work-arounds like making the control 2 rows high?
Title: Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
Post by: Len Vassos on December 10, 2023, 12:58:39 PM
Thanks for the info, Scott.  We will review.
Title: Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
Post by: Mike King on December 11, 2023, 09:58:51 AM
What you are seeing is normal Windows behavior. 

For example if you run any windows application and ask it to open a file, then in the file name field (a single line entry field) enter your text "Hello World Canada", select the second word and press tab to exit the field, you will see that the selected text get automatically unselected.

Only multiple line inputs preserve the selected text in Windows.
Title: Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
Post by: Mike King on December 11, 2023, 11:00:52 AM
Oh and if you really want to use a single line input and have access to 'SelectOffset, 'SelectLength, etc., use a POPUP menu on the control.

Windows will NOT clear the selection if you right click to invoke the popup menu for the control so in your popup menu logic you can access the selection information.

This is how Windows handles this -- Anything looking to access the selected text generally does so from a Right click popup especially when dealing with single line input fields.
Title: Re: Multi-Line SELECTOFFSET, SELECTLENGTH, SELECTTEXT$
Post by: steezware on December 11, 2023, 12:15:58 PM
Thank you, Mike!