#include Once "window9.bi"

Function Getlinetexteditor(Byval gadget As Long, Byval Number As Integer, Byval Buffer As Integer) As USTRING Export
	#ifdef UNICODE
		Dim As USTRING sRet
		Dim As Wstring Ptr pTmp = Callocate(Buffer*Sizeof(Wstring)+2)
		if pTmp then
			*Cptr(Ushort Ptr,pTmp) = Buffer
			Dim As Long iLen = SendMessage(Gadgetid(gadget),em_GetLine,Number,Cast(LPARAM,pTmp))
			pTmp[iLen-1] = Wchr(0)
			sRet = *pTmp
			Deallocate(pTmp)
		endif
		Function = sRet
	#else	
		Dim As Ubyte Ptr pTmp = Callocate(Buffer+1)
		if pTmp then
			*Cptr(Ushort Ptr,pTmp) = Buffer
			Dim As Long iLen = SendMessage(Gadgetid(gadget),em_GetLine,Number,Cast(LPARAM,pTmp))
			pTmp[iLen-1] = 0
			Function = Peeks(pTmp)
			Deallocate(pTmp)
		endif
	#endif
End Function

Function Getlinecounteditor(Byval gadget As Long) As Integer Export
	Return SendMessage(Gadgetid(gadget),EM_GetLineCount,0,0)
End Function

Function Linefromchareditor(Byval gadget As Long, Byval index As Integer) As Integer Export
	Return SendMessage(Gadgetid(gadget),em_LineFromChar,index,0)
End Function

Function Lineindexeditor(Byval gadget As Long, Byval NumberLine As Integer) As Integer Export
	Return SendMessage(Gadgetid(gadget),em_LineIndex,NumberLine,0)
End Function

Function Linelengtheditor(Byval gadget As Long, Byval index As Integer) As Integer Export
	Return SendMessage(Gadgetid(gadget),em_LineLength,index,0)
End Function

Function Linescrolleditor(Byval gadget As Long, Byval VertPos As Integer) As Integer Export
	Return SendMessage(Gadgetid(gadget),em_LineScroll,0,VertPos)
End Function

Sub Settabstopseditor(Byval gadget As Long, Byval TABWIDTH As Integer) Export
	Dim As Integer tw = TABWIDTH * 4
	SendMessage( Gadgetid(gadget), EM_SETTABSTOPS, 1, Cast(LPARAM,@tw) )
End Sub

Sub Readonlyeditor(Byval gadget As Long, Byval ReadOnly As Integer) Export
	SendMessage(Gadgetid(gadget),EM_SETREADONLY, ReadOnly ,0)
End Sub

Function Getfirstvisiblelineeditor(Byval gadget As Long) As Integer Export
	Return SendMessage(Gadgetid(gadget),EM_GETFIRSTVISIBLELINE,0,0)
End Function

Function Getcurrentindexchareditor(Byval gadget As Long) As Integer Export
	Dim buf As Integer
	SendMessage(Gadgetid(gadget),EM_GETSEL,Cast(wparam,@buf),0)
	Return buf
End Function
