Page 1 of 1

EditorGadget() - how to record the cursor's position?

Posted: Tue Jun 13, 2017 3:42 pm
by the.weavster
I want to be able to drag text from a ListIconGadget and drop it into an EditorGadget at the point where the cursor was before I moved it from the EditorGadget to the ListIconGadget.

How do I do that? I can't even seem to get the line number I was editing never mind the cursor position within that line :?

Thanks.

Re: EditorGadget() - how to record the cursor's position?

Posted: Tue Jun 13, 2017 3:53 pm
by Kwai chang caine
Perhaps a start thanks to DANILO :wink:

Code: Select all

; 
; by Danilo, 08.08.2003 - german forum 
; 
Procedure EditorGadgetCursorX(Gadget) 
  ; returns X-Pos of Cursor 
  REG = GadgetID(Gadget) 
  SendMessage_(REG,#EM_EXGETSEL,0,Range.CHARRANGE) 
  ProcedureReturn (Range\cpMax-(SendMessage_(REG,#EM_LINEINDEX,SendMessage_(REG,#EM_EXLINEFROMCHAR,0,Range\cpMin),0))+1) 
EndProcedure 

Procedure EditorGadgetCursorY(Gadget) 
  ; returns Y-Pos of Cursor 
  REG = GadgetID(Gadget) 
  SendMessage_(REG,#EM_EXGETSEL,0,Range.CHARRANGE) 
  ProcedureReturn SendMessage_(REG,#EM_EXLINEFROMCHAR,0,Range\cpMin)+1 
EndProcedure 

Procedure EditorGadgetCursorPos(Gadget) 
  ; returns relative Position of Cursor 
  SendMessage_(GadgetID(Gadget),#EM_EXGETSEL,0,Range.CHARRANGE) 
  ProcedureReturn Range\cpMax 
EndProcedure 

Procedure EditorGadgetLocate(Gadget,x,y) 
  ; Set cursor position 
  REG = GadgetID(Gadget) 
  CharIdx = SendMessage_(REG,#EM_LINEINDEX,y-1,0) 
  LLength = SendMessage_(REG,#EM_LINELENGTH,CharIdx,0) 
  If LLength >= x-1 
    CharIdx + x-1 
  EndIf 
  Range.CHARRANGE 
  Range\cpMin = CharIdx 
  Range\cpMax = CharIdx 
  SendMessage_(REG,#EM_EXSETSEL,0,Range) 
EndProcedure 



OpenWindow(1,200,200,300,200,"EditorGadget",#PB_Window_SystemMenu) 
  CreateGadgetList(WindowID(1)) 
  EditorGadget(1,5,5,290,190) 
  
  AddGadgetItem(1,-1,"Hallo!") 
  AddGadgetItem(1,-1,"") 
  AddGadgetItem(1,-1,"Hier ein paar Proceduren") 
  AddGadgetItem(1,-1,"zur Steuerung des Cursors") 
  AddGadgetItem(1,-1,"im EditorGadget.") 

  EditorGadgetLocate(1,7,2) 


Repeat 
  Select WaitWindowEvent() 
    Case #PB_Event_CloseWindow: End 
  EndSelect 
  SetWindowText_(WindowID(1),"X: "+Str(EditorGadgetCursorX(1))+" Y: "+Str(EditorGadgetCursorY(1))+" -- Position: "+Str(EditorGadgetCursorPos(1))) 
ForEver 

Re: EditorGadget() - how to record the cursor's position?

Posted: Tue Jun 13, 2017 4:09 pm
by the.weavster
Thanks KCC (and Danilo) :)

Unfortunately I think that's only going to work on Windows and I'd really like a way that will work on Linux too.

Re: EditorGadget() - how to record the cursor's position?

Posted: Tue Jun 13, 2017 5:55 pm
by Oma
Hi weavster,

sorry, it's no 1:1 solution in Linux, but
An example (german with Umlauts :wink: ) how to get the cursor position in chars ...
http://www.chabba.de/Linux/EditorGadget ... InChars.pb

and how to insert text @ cursor position ...
http://www.chabba.de/Linux/EditorGadget ... rsorpos.pb

I hope it is helpful.

Regards, Charly

Re: EditorGadget() - how to record the cursor's position?

Posted: Tue Jun 13, 2017 7:18 pm
by the.weavster
Thanks Charly

That is helpful :)