summaryrefslogtreecommitdiff
path: root/Plugins/skins/SkinLib/TextFieldState_v8_wrapper.cpp
blob: 0c3fb3fe3a2ee3af2c8e507cce44be69b1f28823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "globals.h"
#include "TextFieldState_v8_wrapper.h"
#include <v8.h>
#include "TextFieldState.h"
#include <utf8_helpers.h>

using namespace v8;


#ifdef UNICODE
# define V8_TCHAR uint16_t
#else
# define V8_TCHAR char
#endif


static Handle<Value> Get_TextFieldState_text(Local<String> property, const AccessorInfo &info) 
{
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	TextFieldState *tmp = (TextFieldState *) wrap->Value();
	return String::New((const V8_TCHAR *) tmp->getText());
}

static void Set_TextFieldState_text(Local<String> property, Local<Value> value, const AccessorInfo& info) 
{
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	TextFieldState *tmp = (TextFieldState *) wrap->Value();
	String::Utf8Value utf8_value(value);
	tmp->setText(Utf8ToTchar(*utf8_value));
}


static Handle<Value> Get_TextFieldState_hAlign(Local<String> property, const AccessorInfo &info) 
{
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	TextFieldState *tmp = (TextFieldState *) wrap->Value();
	switch(tmp->getHAlign())
	{
		case LEFT: return String::New((const V8_TCHAR *) _T("LEFT"));
		case CENTER: return String::New((const V8_TCHAR *) _T("CENTER"));
		case RIGHT: return String::New((const V8_TCHAR *) _T("RIGHT"));
	}
	return Undefined();
}

static void Set_TextFieldState_hAlign(Local<String> property, Local<Value> value, const AccessorInfo& info) 
{
	Local<Object> self = info.Holder();
	Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
	TextFieldState *tmp = (TextFieldState *) wrap->Value();
	String::Utf8Value utf8_value(value);
	Utf8ToTchar tval(*utf8_value);
	if ( lstrcmpi(_T("LEFT"), tval) == 0)
		tmp->setHAlign(LEFT);
	else if ( lstrcmpi(_T("CENTER"), tval) == 0)
		tmp->setHAlign(CENTER);
	else if ( lstrcmpi(_T("RIGHT"), tval) == 0)
		tmp->setHAlign(RIGHT);
}


void AddTextFieldStateAcessors(Handle<ObjectTemplate> &templ)
{
	templ->SetAccessor(String::New("text"), Get_TextFieldState_text, Set_TextFieldState_text);
	templ->SetAccessor(String::New("hAlign"), Get_TextFieldState_hAlign, Set_TextFieldState_hAlign);
}