Select text / get selection for StringGadget/EditorGadget

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Select text / get selection for StringGadget/EditorGadget

Post by Danilo »

Example using WinAPI:

Code: Select all

  ; Shows possible flags of StringGadget in action...
  If OpenWindow(0, 0, 0, 322, 205, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    StringGadget(0, 8,  10, 306, 20, "Normal StringGadget...")
    StringGadget(1, 8,  35, 306, 20, "1234567", #PB_String_Numeric)
    StringGadget(2, 8,  60, 306, 20, "Readonly StringGadget", #PB_String_ReadOnly)
    StringGadget(3, 8,  85, 306, 20, "lowercase...", #PB_String_LowerCase)
    StringGadget(4, 8, 110, 306, 20, "uppercase...", #PB_String_UpperCase)
    StringGadget(5, 8, 140, 306, 20, "Borderless StringGadget", #PB_String_BorderLess)
    StringGadget(6, 8, 170, 306, 20, "Password", #PB_String_Password)
    Repeat
        Select WaitWindowEvent()
            Case #PB_Event_CloseWindow
                Break
            Case #PB_Event_Gadget
                If EventType() = #PB_EventType_Focus And GadgetType(EventGadget())=#PB_GadgetType_String
                    SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
                EndIf
         EndSelect
    ForEver
  EndIf
Set and get the selection for both, StringGadget and EditorGadget on all platforms.

Code: Select all

GetGadgetAttribute(#Gadget,#PB_Editor_SelectionStart)
GetGadgetAttribute(#Gadget,#PB_Editor_SelectionEnd)
GetGadgetAttribute(#Gadget,#PB_Editor_SelectedText)

SetGadgetAttribute(#Gadget,#PB_Editor_SelectionStart, startSelectionPosition)
SetGadgetAttribute(#Gadget,#PB_Editor_SelectionEnd, endSelectionPosition)
User avatar
pcfreak
User
User
Posts: 75
Joined: Sat May 22, 2004 1:38 am

Re: Select text / get selection for StringGadget/EditorGadge

Post by pcfreak »

+1

Definitely a need feature in my opinion.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Select text / get selection for StringGadget/EditorGadge

Post by IdeasVacuum »

Would be very useful to have this feature - certainly Windows Users expect to:

Select some text; Right mouse -click copy to clipboard.

Windows API:

Code: Select all

Procedure.s GetSelectedEditorText(iEdId.i)
;-----------------------------------------
Protected sSelected.s, Range.CHARRANGE, iSize.i 

               SendMessage_(GadgetID(iEdId), #EM_EXGETSEL, 0, Range)

                      iSize = (Range\cpMax - Range\cpMin)
                  sSelected = Space((iSize * 2) + 1)
          
               SendMessage_(GadgetID(iEdId),#EM_GETSELTEXT, 0, sSelected)

               ProcedureReturn(sSelected)
EndProcedure
Edit: Related to that would be to add/insert text too, à la Windows API:

Code: Select all

SendMessage_(GadgetID(#MyEditor), #WM_PASTE,0,0)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2056
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Select text / get selection for StringGadget/EditorGadge

Post by Andre »

+1
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Select text / get selection for StringGadget/EditorGadge

Post by davido »

+1
DE AA EB
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Select text / get selection for StringGadget/EditorGadge

Post by Shardik »

To select text or obtain selected text in a StringGadget you may use this cross-platform solution.

+1 for implementing this feature natively in PB...
paulr
User
User
Posts: 68
Joined: Sat Sep 27, 2003 2:53 pm

Re: Select text / get selection for StringGadget/EditorGadge

Post by paulr »

+1 from me.

Can I also suggest:

Code: Select all

GetGadgetAttribute(#Gadget,#PB_Editor_TextLength)
...to retrieve the number of characters in the text box?

I know this can currently be achieved with Len(GetGadgetText(#Gadget)), but the above would hopefully avoid processing the whole string every time it's called.
Maitre_Kanter
User
User
Posts: 84
Joined: Mon Sep 06, 2010 3:05 pm

Re: Select text / get selection for StringGadget/EditorGadge

Post by Maitre_Kanter »

+1 for adding this feature natively in PureBasic
Topilno
New User
New User
Posts: 6
Joined: Mon Sep 22, 2008 8:41 pm

Re: Select text / get selection for StringGadget/EditorGadge

Post by Topilno »

Danilo wrote: Set and get the selection for both, StringGadget and EditorGadget on all platforms.

Code: Select all

GetGadgetAttribute(#Gadget,#PB_Editor_SelectionStart)
GetGadgetAttribute(#Gadget,#PB_Editor_SelectionEnd)
GetGadgetAttribute(#Gadget,#PB_Editor_SelectedText)

SetGadgetAttribute(#Gadget,#PB_Editor_SelectionStart, startSelectionPosition)
SetGadgetAttribute(#Gadget,#PB_Editor_SelectionEnd, endSelectionPosition)
I'm trying this with PB 5.40/5.41b2 (EditorGadget) but it's not working.
Can't find #PB_Editor_SelectionStart and #PB_Editor_SelectionEnd.
Are they still supported, perhaps with a new name, or are they gone?
Thanks
paulr
User
User
Posts: 68
Joined: Sat Sep 27, 2003 2:53 pm

Re: Select text / get selection for StringGadget/EditorGadge

Post by paulr »

This thread is a wish list, this feature doesn't exist yet. We can only hope it will one day!

In the meantime, Shardik's link above is helpful.
Topilno
New User
New User
Posts: 6
Joined: Mon Sep 22, 2008 8:41 pm

Re: Select text / get selection for StringGadget/EditorGadge

Post by Topilno »

paulr wrote:This thread is a wish list, this feature doesn't exist yet. We can only hope it will one day!

In the meantime, Shardik's link above is helpful.
Thank you very much. Googled the code, and it looked so real i didn't realize it was from a wishlist.
Torp
User
User
Posts: 82
Joined: Fri Apr 01, 2005 11:29 am

Re: Select text / get selection for StringGadget/EditorGadge

Post by Torp »

+1
Mesa
Enthusiast
Enthusiast
Posts: 345
Joined: Fri Feb 24, 2012 10:19 am

Re: Select text / get selection for StringGadget/EditorGadge

Post by Mesa »

+1
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Select text / get selection for StringGadget/EditorGadge

Post by collectordave »

Has this been implemented?

Just been trying the code from shardik and have it working on an editor gadget.

just need to check end of line stuff.

regards

CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Select text / get selection for StringGadget/EditorGadge

Post by BarryG »

+1. Please add them. And thanks, IdeasVacuum, for making it possible in the meantime.

But how do I replace selected text without putting it in the clipboard with #WM_PASTE?

[Edit] Just found it in another post:

Code: Select all

SendMessage_(GadgetID(gadget),#EM_REPLACESEL,0,@text$)
But this doesn't let me press Ctrl+Z to undo the replace, like pasting does. What to do?
Post Reply