#include "xentry.h"

/*@ 
@class XEntryField
@parent XControl
@type overview
@symbol _
@remarks XEntryField is a single-line text field.
*/


/*@ XEntryField::IsReadOnly(void)
@group misc
@remarks Query if the entryfild is in readonly-mode.
@returns BOOL result
*/
BOOL XEntryField::IsReadOnly(void) const
{
	return (BOOL) WinSendMsg(winhandle, EM_QUERYREADONLY, 0, 0);
}


/*@ XEntryField::SetReadOnly(const BOOL readOnly)
@group misc
@remarks Enable/disable readonly-mode.
@parameters BOOL readOnly  TRUE=enable, FALSE=disable readonly-mose
*/
void XEntryField::SetReadOnly(const BOOL readOnly) const
{
	WinSendMsg(winhandle, EM_SETREADONLY, MPFROMSHORT(readOnly), 0);
}


/*@ XEntryField::GetFirstChar(void)
@group misc
@remarks Query the index of the first visible charakter.
@returns SHORT index
*/
SHORT XEntryField::GetFirstChar(void) const
{
	return SHORT1FROMMR(WinSendMsg(winhandle, EM_QUERYFIRSTCHAR, 0, 0));
}


/*@ XEntryField::GetSelection(SHORT & start, SHORT & end)
@group clipboard functions
@remarks Query the boundarys of the current selection.
@parameters SHORT& start   starting point of selection
           SHORT& end     end point
*/
void XEntryField::GetSelection(SHORT & start, SHORT & end)
{
	MRESULT res = WinSendMsg(winhandle, EM_QUERYSEL, 0, 0);

	start = SHORT1FROMMR(res);
	end = SHORT2FROMMR(res);
}


/*@ XEntryField::SetLimit(const unsigned short len)
@group misc
@remarks Set maximum number of charakters.
@parameters USHORT length  maximum size
*/
void XEntryField::SetLimit(const unsigned short len) const
{
	WinSendMsg(winhandle, EM_SETTEXTLIMIT, MPFROMSHORT(len), 0);
}


/*@ XEntryField::IsChanged(void)
@group misc
@remarks Query if the content has changed.
@returns BOOL result
*/
BOOL XEntryField::IsChanged(void) const
{
	return SHORT1FROMMR(WinSendMsg(winhandle, EM_QUERYCHANGED, 0, 0));
}


/*@ XEntryField::EnableOverWrite(const BOOL overWrite)
@group misc
@remarks Enables/disables overwrite-mode.
@parameters BOOL overwrite    TRUE=overWrite, FALSE=disable overWrite
*/
void XEntryField::EnableOverWrite(const BOOL overWrite) const
{
	WinSendMsg(winhandle, EM_SETINSERTMODE, MPFROMSHORT(overWrite), 0);
}


/*@ XEntryField :: XEntryField(const XWindow * owner, const XRect * rec, const USHORT id, const ULONG style, const char *string, const char *font)
@group constructors/destructors
@remarks Constructs an entryfield.
@parameters <t 'ø' c=2>
				øXWindow * owner      øthe owner of the entryfield
            øXRect * rect         øthe rectangle
            øUSHORT id            øid of the window
            øULONG style          østyle, valid values are:
											<t 'ø' c=2>
                                    øEN_LEFT	ø
                                    øEN_CENTER	ø
                                    øEN_RIGHT	ø
                                    øEN_AUTOSCROLL	ø
                                    øEN_MARGIN	ø
                                    øEN_AUTOTAB	ø
                                    øEN_READONLY	ø
                                    øEN_UNREADABLE	ø
                                    øEN_AUTOSIZE	ø
                                    øEN_BORDER	ø
											</t>
                                 (can be or-ed)
            øconst char * string  øtext to display
				</t>
*/
XEntryField :: XEntryField(const XWindow * owner, const XRect * rec, const USHORT id, const ULONG style, const char *string, const char *font):XControl(rec, style | FS_NOBYTEALIGN, owner, string, WC_ENTRYFIELD, id, font)
{
}


/*@ XEntryField::SelectText(const unsigned short start, const unsigned short end) 
@group clipboard functions
@remarks Select text from startpoint to an endpoint.
@parameters USHORT start   the starting point of selection<BR
            USHORT end     end-point of selection
*/
void XEntryField::SelectText(const unsigned short start, const unsigned short end) const
{
	WinSendMsg(winhandle, EM_SETSEL, MPFROM2SHORT(start, end), 0);
}


/*@ XEntryField::ShowFirstChar(const SHORT firstChar) 
@group misc
@remarks Select the first char to display
@parameters SHORT firstChar   the first char which will be displayed
*/
void XEntryField::ShowFirstChar(const SHORT firstChar) const
{
	WinSendMsg(winhandle, EM_SETFIRSTCHAR, MPFROMSHORT(firstChar), 0);
}


/*@ XEntryField::Clear(void) 
@group clipboard functions
@remarks Delete the marked text.
*/
void XEntryField::Clear(void) const
{
	WinSendMsg(winhandle, EM_CLEAR, 0, 0);
}


/*@ XEntryField::Copy(void) 
@group clipboard functions
@remarks Copy the marked text to the clipboard.
*/
void XEntryField::Copy(void) const
{
	WinSendMsg(winhandle, EM_COPY, 0, 0);
}


/*@ XEntryField::Paste(void) 
@group clipboard functions
@remarks Paste text from the clipboard.
*/
void XEntryField::Paste(void) const
{
	WinSendMsg(winhandle, EM_PASTE, 0, 0);
}


/*@ XEntryField::Cut(void) 
@group clipboard functions
@remarks Cut marked text and put it to the clipboard.
*/
void XEntryField::Cut(void) const
{
	WinSendMsg(winhandle, EM_CUT, 0, 0);
}
