Page 1 of 1
Add SelectGadgetText() function
Posted: Fri Feb 21, 2025 11:17 pm
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

Re: Add SelectGadgetText() function
Posted: Sat Feb 22, 2025 2:31 am
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
Re: Add SelectGadgetText() function
Posted: Sat Feb 22, 2025 2:52 am
by BarryG
+1
Re: Add SelectGadgetText() function
Posted: Sat Feb 22, 2025 1:29 pm
by mk-soft
Re: Add SelectGadgetText() function
Posted: Mon Feb 24, 2025 12:44 am
by nsstudios
+1
I think having essential funcs like these is important.