Add SelectGadgetText() function

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Add SelectGadgetText() function

Post by Quin »

I propose:

Code: Select all

Result = SelectGadgetText(#Gadget, SelectionStart.i, SelectionEnd.i)
to select/deselect the text (or portion of the text) in a gadget such as StringGadget() or EditorGadget().
If SelectionStart = 0 and SelectionEnd = -1, all text is selected. If both parameters are -1, the selection is cleared. Otherwise, the text is selected between the two points.
On Windows, I do this with:

Code: Select all

SendMessage(GadgetID(#Gadget), #EM_SETSEL, SelectionStart, SelectionEnd)
But a native command would really improve the gadget library and cross-platform-ness of PB :wink:
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Add SelectGadgetText() function

Post by Piero »

+1

and Set/Get SelectedText too!

Select:
Cross Platform: https://www.purebasic.fr/english/viewto ... 50&start=3
All/Deselect Cross Platform: https://www.purebasic.fr/english/viewto ... 46#p448546

Get Selected Text:
Mac: https://www.purebasic.fr/english/viewto ... 16#p450216
Win: https://www.purebasic.fr/english/viewto ... 10#p565110

Insert (Set Selected) Text:
Win:

Code: Select all

SendMessage_(GadgetID(0), #EM_REPLACESEL, 1, "Insert")
Linux: https://www.purebasic.fr/english/viewto ... 94#p507994
Mac:

Code: Select all

Macro InsertText(editorGadget,s)
   CocoaMessage(0,GadgetID(editorGadget),"insertText:$",@s)
EndMacro

OpenWindow(0, 270, 100, 200, 130, "EditorGadget")
EditorGadget(0, 10, 10, 180, 80, #PB_Editor_WordWrap)
SetGadgetText(0, "The quick brown fox jumps over the lazy dog.")
ButtonGadget(1, 5, 100, 95, 25, "Insert Text")
Repeat
   Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
         Break
      Case #PB_Event_Gadget
         Select EventGadget()
            Case 1
               insertText(0,"Insert")
         EndSelect
   EndSelect
ForEver
Last edited by Piero on Sat Feb 22, 2025 3:35 am, edited 2 times in total.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Add SelectGadgetText() function

Post by BarryG »

+1
User avatar
mk-soft
Always Here
Always Here
Posts: 6245
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Add SelectGadgetText() function

Post by mk-soft »

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
nsstudios
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: Add SelectGadgetText() function

Post by nsstudios »

+1
I think having essential funcs like these is important.
Post Reply