Page 1 of 1

Editor Gadget - which column is cursor in?

Posted: Sun Aug 29, 2010 3:49 am
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?

Re: Editor Gadget - which column is cursor in?

Posted: Sun Aug 29, 2010 8:26 am
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. :)

Re: Editor Gadget - which column is cursor in?

Posted: Sun Aug 29, 2010 10:12 am
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

Re: Editor Gadget - which column is cursor in?

Posted: Mon Aug 30, 2010 3:48 pm
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.

Re: Editor Gadget - which column is cursor in?

Posted: Mon Aug 30, 2010 5:08 pm
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