Page 1 of 1
					
				Cursor in  StringGadget
				Posted: Sat Nov 27, 2010 8:39 pm
				by hth
				How can I put the cursor at the end of the string?
Code: Select all
If OpenWindow(0, 100, 200,400,200, "", #PB_Window_MinimizeGadget)
  StringGadget(0,50,50, 200,20, "")
  SetGadgetText(0,"example")
  SetActiveGadget(0)
  
  ;I need the Cursor at the end of the string
 
  Repeat
    EventID = WaitWindowEvent()    
   
  Until EventID = #PB_Event_CloseWindow
EndIf
End 
 
			
					
				Re: Cursor in  StringGadget
				Posted: Sat Nov 27, 2010 8:57 pm
				by RASHAD
				Code: Select all
If OpenWindow(0, 100, 200,400,200, "", #PB_Window_MinimizeGadget)
  
  StringGadget(0,50,50, 200,20, "example")
  Text$ = GetGadgetText(0)
  SetActiveGadget(0)
  SendMessage_(GadgetID(0), #EM_SETSEL,Len(Text$),Len(Text$))  
 
  ;I need the Cursor at the end of the string
  Repeat
    EventID = WaitWindowEvent()   
   
  Until EventID = #PB_Event_CloseWindow
EndIf
End 
 
			
					
				Re: Cursor in  StringGadget
				Posted: Wed Dec 08, 2010 1:49 pm
				by hth
				Thank you very much!
hth
			 
			
					
				Re: Cursor in  StringGadget
				Posted: Wed Dec 08, 2010 5:10 pm
				by Ulix
				Thank you
And the same code on linux ?
Is this possible?  

 
			
					
				Re: Cursor in  StringGadget
				Posted: Thu Dec 09, 2010 9:58 am
				by Shardik
				Ulix wrote:Thank you
And the same code on linux ?
Is this possible?  

 
I have modified RASHAD's code example to work in Windows and Linux:
Code: Select all
OpenWindow(0, 100, 200, 400, 200, "", #PB_Window_MinimizeGadget)
StringGadget(0, 50, 50, 200, 20, "example")
Text$ = GetGadgetText(0)
SetActiveGadget(0)
CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    gtk_editable_set_position_(GadgetID(0), -1)
  CompilerCase #PB_OS_Windows
    SendMessage_(GadgetID(0), #EM_SETSEL, Len(Text$), Len(Text$)) 
CompilerEndSelect
Repeat
  EventID = WaitWindowEvent()   
Until EventID = #PB_Event_CloseWindow
 
			
					
				Re: Cursor in  StringGadget
				Posted: Thu Dec 09, 2010 2:18 pm
				by Ulix
				again thank you very much!  
 
 
A+ Ulix
 
			
					
				Re: Cursor in  StringGadget
				Posted: Thu Dec 09, 2010 6:40 pm
				by WilliamL
				Hey, Shardik!  What about the Mac?
Code: Select all
gtk_editable_set_position_(GadgetID(0), -1)
..and does the -1 indicate the position?  If so then do other values put the cursor somewhere else within the string?
TESetSelect(selStart.l,selEnd.l,TEHandle.i)
I came across this code (in the Mac API) and if could be made to work then the cursor position could be easily changed (even to end)
Now all we have to do is convince Fred to add 'SetSelect' to the pb commands!  

 
			
					
				Re: Cursor in  StringGadget
				Posted: Thu Dec 09, 2010 7:55 pm
				by Shardik
				WilliamL wrote:Hey, Shardik!  What about the Mac?
Dear William,
unfortunately the only machine I don't have at work is a Mac... 
 
 
But Windows (NT, XP, 7), AIX, z/OS (Mainframe), Linux (SLES, OpenSuse, Debian, Ubuntu,
Kubuntu, Xubuntu) and a VMWare 4.1 ESX cluster I would have available for testing purposes... 
 
 
At home I have expanded my above example for MacOS X support:
Code: Select all
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
  ImportC ""
    SetControlData(Control, ControlPartCode, TagName, BufferSize, *Buffer)
  EndImport
  #kControlEditTextPart = 5
  #kControlEditTextSelectionTag = 'sele'
  Structure ControlEditTextSelectionRec
    selStart.W
    selEnd.W
  EndStructure
CompilerEndIf
OpenWindow(0, 100, 200, 400, 200, "", #PB_Window_MinimizeGadget)
StringGadget(0, 50, 50, 200, 20, "example")
Text$ = GetGadgetText(0)
SetActiveGadget(0)
CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_MacOS
    TextSelection.ControlEditTextSelectionRec
    TextSelection\selStart = Len(Text$)
    TextSelection\selEnd = Len(Text$)
    SetControlData(GadgetID(0), #kControlEditTextPart, #kControlEditTextSelectionTag, SizeOf(ControlEditTextSelectionRec), @TextSelection)
  CompilerCase #PB_OS_Linux
    gtk_editable_set_position_(GadgetID(0), -1)
  CompilerCase #PB_OS_Windows
    SendMessage_(GadgetID(0), #EM_SETSEL, Len(Text$), Len(Text$))
CompilerEndSelect
Repeat
  EventID = WaitWindowEvent()   
Until EventID = #PB_Event_CloseWindow
 
			
					
				Re: Cursor in  StringGadget
				Posted: Thu Dec 09, 2010 8:27 pm
				by Shardik
				WilliamL wrote:Code: Select all
gtk_editable_set_position_(GadgetID(0), -1)
..and does the -1 indicate the position?  If so then do other values put the cursor somewhere else within the string?
 
Yes, but you can use gtk_editable_set_position() only in Linux because it is a Linux API function:
(
http://library.gnome.org/devel/gtk/stab ... t-position)
GTK+ Reference Manual wrote:Sets the cursor position in the editable to the given value.
The cursor is displayed before the character with the given (base 0) index in the contents of the editable. The value must be less than or equal to the number of characters in the editable. A value of -1 indicates that the position should be set after the last character of the editable. Note that position is in characters, not in bytes. 
 
			
					
				Re: Cursor in  StringGadget
				Posted: Thu Dec 09, 2010 8:51 pm
				by WilliamL
				Thanks Shardik,
It works perfectly!  And like the Linux example the same command can be used to select part or all of the text.  This is a work-around for SetSelect for the Mac and I will add it to my list.