It is currently Tue Nov 12, 2019 1:17 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Select text / get selection for StringGadget/EditorGadget
PostPosted: Sat Oct 01, 2011 12:58 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2926
Location: Planet Earth
Example using WinAPI:
Code:
  ; 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:
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Thu Dec 22, 2011 10:13 pm 
Offline
User
User
User avatar

Joined: Sat May 22, 2004 1:38 am
Posts: 75
+1

Definitely a need feature in my opinion.


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Mon Dec 30, 2013 11:35 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5845
Location: Wales, UK
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:
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:
SendMessage_(GadgetID(#MyEditor), #WM_PASTE,0,0)

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Tue Dec 31, 2013 12:25 am 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1704
Location: Germany (Saxony, Deutscheinsiedel)
+1

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Tue Dec 31, 2013 8:12 am 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1685
Location: Uttoxeter, UK
+1

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Tue Dec 31, 2013 11:28 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1651
Location: Germany
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...


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Fri Mar 28, 2014 7:15 pm 
Offline
User
User

Joined: Sat Sep 27, 2003 2:53 pm
Posts: 62
+1 from me.

Can I also suggest:

Code:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Sun Apr 13, 2014 7:57 am 
Offline
User
User

Joined: Mon Sep 06, 2010 3:05 pm
Posts: 72
+1 for adding this feature natively in PureBasic


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Mon Dec 07, 2015 11:49 pm 
Offline
New User
New User

Joined: Mon Sep 22, 2008 8:41 pm
Posts: 6
Danilo wrote:
Set and get the selection for both, StringGadget and EditorGadget on all platforms.
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Mon Dec 07, 2015 11:58 pm 
Offline
User
User

Joined: Sat Sep 27, 2003 2:53 pm
Posts: 62
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Tue Dec 08, 2015 12:20 am 
Offline
New User
New User

Joined: Mon Sep 22, 2008 8:41 pm
Posts: 6
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Tue Dec 08, 2015 9:25 am 
Offline
User
User

Joined: Fri Apr 01, 2005 11:29 am
Posts: 76
+1


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Tue Dec 08, 2015 11:13 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 24, 2012 10:19 am
Posts: 115
+1


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Fri Feb 22, 2019 10:16 am 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1032
Location: Portugal
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Select text / get selection for StringGadget/EditorGadge
PostPosted: Sun Sep 22, 2019 3:04 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 379
+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:
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?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye