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

Just starting out? Need help? Post your questions and find answers here.
User avatar
the.weavster
Addict
Addict
Posts: 1581
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

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

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5522
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

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

Post 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 
ImageThe happiness is a road...
Not a destination
User avatar
the.weavster
Addict
Addict
Posts: 1581
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

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

Post 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.
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

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

Post 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
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
User avatar
the.weavster
Addict
Addict
Posts: 1581
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

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

Post by the.weavster »

Thanks Charly

That is helpful :)
Post Reply