Editor Gadget - which column is cursor in?

Just starting out? Need help? Post your questions and find answers here.
johnfinch
User
User
Posts: 45
Joined: Thu May 11, 2006 1:45 am
Location: florida
Contact:

Editor Gadget - which column is cursor in?

Post by johnfinch »

I am interrogating the editor gadget to find the line number and column of the cursor. I can get the line number ok... but getting the column that the cursor has moved to (with the cursor keys) has stumped me. The lines are of differing lengths so that doesn't help.

Does anyone have any ideas?
Leopard-parallels-XP-Vista
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: Editor Gadget - which column is cursor in?

Post by electrochrisso »

Got these from the CodeArchive.chm a handy thing to have, you should be able to find it through the search.

Code: Select all

Procedure Editor_GetCursorX(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 Editor_GetCursorY(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 
I hope its what you need. :)
PureBasic! Purely the best 8)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Editor Gadget - which column is cursor in?

Post by blueznl »

Edit: duh, double :-)

Code: Select all

Procedure x_editorgadget_cursorcolumn(gadgetnr.i)           
  Protected range.CHARRANGE, id.i
  ;
  range.CHARRANGE
  id = GadgetID(gadgetnr)
  SendMessage_(id,#EM_EXGETSEL,0,range.CHARRANGE)
  ProcedureReturn (range\cpMax-(SendMessage_(id,#EM_LINEINDEX,SendMessage_(id,#EM_EXLINEFROMCHAR,0,range\cpMin),0)))
  ;
EndProcedure

Procedure x_editorgadget_cursorrow(gadgetnr)                
  Protected range.CHARRANGE, id.i
  ;
  range.CHARRANGE
  id = GadgetID(gadgetnr)
  SendMessage_(id,#EM_EXGETSEL,0,@range)
  ProcedureReturn SendMessage_(id,#EM_EXLINEFROMCHAR,0,range\cpMin)
  ;
EndProcedure
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
johnfinch
User
User
Posts: 45
Joined: Thu May 11, 2006 1:45 am
Location: florida
Contact:

Re: Editor Gadget - which column is cursor in?

Post by johnfinch »

Thanks so much. But both procedures only return the maximum number of either columns or lines, not where the cursor is in those lines. At least, that is the result I'm getting with the editor gadget after loading up an RTF and then moving around within it. Again, thank you both for your response though.
Leopard-parallels-XP-Vista
johnfinch
User
User
Posts: 45
Joined: Thu May 11, 2006 1:45 am
Location: florida
Contact:

Re: Editor Gadget - which column is cursor in?

Post by johnfinch »

Ok... I got it working... and you were both absolutely right. I needed to use variables to hold the returned values instead of trying to convert them immediately to strings.... :oops:

Thanks! Very helpful forum indeed.

John
Leopard-parallels-XP-Vista
Post Reply