#include once "window9.bi"

Function GetLineTextEditor(ByVal gadget As Integer, ByVal Number As Integer, ByVal Buffer As Integer=512) As String Export
  dim as ubyte ptr pTmp = allocate(Buffer)
  *cptr(ushort ptr,ptmp) = Buffer
  SendMessage(GadgetID(gadget),em_GetLine,Number,Cast(LPARAM,pTmp))
  Function=PeekS(pTmp)
  DeAllocate(ptmp)
End Function

Function GetLineCountEditor(ByVal gadget As Integer) As Integer Export
  Return SendMessage(GadgetID(gadget),EM_GetLineCount,0,0)
End Function

Function LineFromCharEditor(ByVal gadget As Integer, ByVal index As Integer=-1) As integer Export
  Return SendMessage(GadgetID(gadget),em_LineFromChar,index,0)
End Function

Function LineIndexEditor(ByVal gadget As Integer, ByVal NumberLine As Integer=-1) As integer Export
  Return SendMessage(GadgetID(gadget),em_LineIndex,NumberLine,0)
End Function

Function LineLengthEditor(ByVal gadget As Integer, ByVal index As Integer=-1) As integer Export
  Return SendMessage(GadgetID(gadget),em_LineLength,index,0)
End Function

Function LineScrollEditor(ByVal gadget As Integer, ByVal VertPos As Integer) As integer Export
  Return SendMessage(GadgetID(gadget),em_LineScroll,0,VertPos)
End Function

Function SetTabStopsEditor(ByVal gadget As Integer, ByVal TABWIDTH As Integer=0) As integer Export
  Dim As Integer tw = TABWIDTH * 4
  Return SendMessage( GadgetID(gadget), EM_SETTABSTOPS, 1, cast(LPARAM,@tw) )
End Function

Function ReadOnlyEditor(ByVal gadget As Integer, ByVal ReadOnly As Integer=0) As integer Export
  Return SendMessage(GadgetID(gadget),EM_SETREADONLY,ReadOnly ,0)
End Function

Function GetFirstVisibleLineEditor(ByVal gadget As Integer) As integer Export
  Return SendMessage(GadgetID(gadget),EM_GETFIRSTVISIBLELINE,0,0)
End Function

Function GetCurrentIndexCharEditor(ByVal gadget As Integer) As integer Export
  Dim buf As Integer
  SendMessage(GadgetID(gadget),EM_GETSEL,Cast(wparam,@buf),0)
  Return buf
End Function
