diff options
Diffstat (limited to 'plugins/Skins/SkinLib')
85 files changed, 6461 insertions, 0 deletions
diff --git a/plugins/Skins/SkinLib/BorderState.cpp b/plugins/Skins/SkinLib/BorderState.cpp new file mode 100644 index 0000000000..83dcdbcf11 --- /dev/null +++ b/plugins/Skins/SkinLib/BorderState.cpp @@ -0,0 +1,61 @@ +#include "globals.h"
+#include <windows.h>
+#include "BorderState.h"
+
+BorderState::BorderState(int aLeft, int aRight, int aTop, int aBottom)
+ : left(aLeft), right(aRight), top(aTop), bottom(aBottom)
+{
+}
+
+BorderState::~BorderState()
+{
+}
+
+int BorderState::getLeft() const
+{
+ return left;
+}
+
+void BorderState::setLeft(int left)
+{
+ this->left = max(0, left);
+}
+
+int BorderState::getRight() const
+{
+ return right;
+}
+
+void BorderState::setRight(int right)
+{
+ this->right = max(0, right);
+}
+
+int BorderState::getTop() const
+{
+ return top;
+}
+
+void BorderState::setTop(int top)
+{
+ this->top = max(0, top);
+}
+
+int BorderState::getBottom() const
+{
+ return bottom;
+}
+
+void BorderState::setBottom(int bottom)
+{
+ this->bottom = max(0, bottom);
+}
+
+void BorderState::setAll(int border)
+{
+ border = max(0, border);
+ left = border;
+ right = border;
+ top = border;
+ bottom = border;
+}
diff --git a/plugins/Skins/SkinLib/BorderState.h b/plugins/Skins/SkinLib/BorderState.h new file mode 100644 index 0000000000..2cac3c1aa5 --- /dev/null +++ b/plugins/Skins/SkinLib/BorderState.h @@ -0,0 +1,28 @@ +#pragma once
+
+class BorderState
+{
+public:
+ BorderState(int left, int right, int top, int bottom);
+ ~BorderState();
+
+ int getLeft() const;
+ void setLeft(int left);
+
+ int getRight() const;
+ void setRight(int right);
+
+ int getTop() const;
+ void setTop(int top);
+
+ int getBottom() const;
+ void setBottom(int bottom);
+
+ void setAll(int border);
+
+private:
+ int left;
+ int right;
+ int top;
+ int bottom;
+};
diff --git a/plugins/Skins/SkinLib/BorderState_v8_wrapper.cpp b/plugins/Skins/SkinLib/BorderState_v8_wrapper.cpp new file mode 100644 index 0000000000..71cc057419 --- /dev/null +++ b/plugins/Skins/SkinLib/BorderState_v8_wrapper.cpp @@ -0,0 +1,160 @@ +#include "globals.h"
+#include "BorderState_v8_wrapper.h"
+#include <v8.h>
+#include "BorderState.h"
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+static Handle<Value> Get_BorderState_left(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ BorderState *tmp = (BorderState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getLeft()) );
+}
+
+static void Set_BorderState_left(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ BorderState *tmp = (BorderState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setLeft(value->Int32Value());
+}
+
+
+static Handle<Value> Get_BorderState_right(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ BorderState *tmp = (BorderState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getRight()) );
+}
+
+static void Set_BorderState_right(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ BorderState *tmp = (BorderState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setRight(value->Int32Value());
+}
+
+
+static Handle<Value> Get_BorderState_top(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ BorderState *tmp = (BorderState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getTop()) );
+}
+
+static void Set_BorderState_top(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ BorderState *tmp = (BorderState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setTop(value->Int32Value());
+}
+
+
+static Handle<Value> Get_BorderState_bottom(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ BorderState *tmp = (BorderState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getBottom()) );
+}
+
+static void Set_BorderState_bottom(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ BorderState *tmp = (BorderState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setBottom(value->Int32Value());
+}
+
+
+void AddBorderStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->SetAccessor(String::New("left"), Get_BorderState_left, Set_BorderState_left);
+ templ->SetAccessor(String::New("right"), Get_BorderState_right, Set_BorderState_right);
+ templ->SetAccessor(String::New("top"), Get_BorderState_top, Set_BorderState_top);
+ templ->SetAccessor(String::New("bottom"), Get_BorderState_bottom, Set_BorderState_bottom);
+}
diff --git a/plugins/Skins/SkinLib/BorderState_v8_wrapper.h b/plugins/Skins/SkinLib/BorderState_v8_wrapper.h new file mode 100644 index 0000000000..70af9e41dc --- /dev/null +++ b/plugins/Skins/SkinLib/BorderState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __BORDER_STATE_V8_WRAPPER_H__
+# define __BORDER_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddBorderStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __BORDER_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/ButtonField.cpp b/plugins/Skins/SkinLib/ButtonField.cpp new file mode 100644 index 0000000000..e6c82ba5e3 --- /dev/null +++ b/plugins/Skins/SkinLib/ButtonField.cpp @@ -0,0 +1,22 @@ +#include "globals.h"
+#include "ButtonField.h"
+#include "ButtonFieldState.h"
+
+
+ButtonField::ButtonField(Dialog *dlg, const char *name, HWND hwnd) : ControlField(dlg, name, hwnd)
+{
+}
+
+ButtonField::~ButtonField()
+{
+}
+
+FieldType ButtonField::getType() const
+{
+ return CONTROL_BUTTON;
+}
+
+FieldState * ButtonField::createState(DialogState *dialogState)
+{
+ return new ButtonFieldState(dialogState, this);
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/ButtonField.h b/plugins/Skins/SkinLib/ButtonField.h new file mode 100644 index 0000000000..0d7a1555ca --- /dev/null +++ b/plugins/Skins/SkinLib/ButtonField.h @@ -0,0 +1,19 @@ +#ifndef __BUTTON_FIELD_H__
+# define __BUTTON_FIELD_H__
+
+#include "ControlField.h"
+
+class ButtonField : public ControlField
+{
+public:
+ ButtonField(Dialog *dlg, const char *name, HWND hwnd);
+ virtual ~ButtonField();
+
+ virtual FieldType getType() const;
+
+ virtual FieldState * createState(DialogState *dialogState);
+};
+
+
+
+#endif // __BUTTON_FIELD_H__
diff --git a/plugins/Skins/SkinLib/ButtonFieldState.cpp b/plugins/Skins/SkinLib/ButtonFieldState.cpp new file mode 100644 index 0000000000..986484b20b --- /dev/null +++ b/plugins/Skins/SkinLib/ButtonFieldState.cpp @@ -0,0 +1,30 @@ +#include "globals.h"
+#include "ButtonFieldState.h"
+
+ButtonFieldState::ButtonFieldState(DialogState *dialog, ControlField *field)
+ : ControlFieldState(dialog, field)
+{
+}
+
+ButtonFieldState::~ButtonFieldState()
+{
+}
+
+Size ButtonFieldState::getPreferedSize() const
+{
+ Size ret = getTextPreferedSize(DT_SINGLELINE);
+
+ int border = getField()->getBorderSize();
+ ret.x += 2 * border;
+ ret.y += 2 * border;
+
+ ret.x += 12;
+ ret.y += 10;
+
+ return ret;
+}
+
+bool ButtonFieldState::isEmpty() const
+{
+ return false;
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/ButtonFieldState.h b/plugins/Skins/SkinLib/ButtonFieldState.h new file mode 100644 index 0000000000..12b701035a --- /dev/null +++ b/plugins/Skins/SkinLib/ButtonFieldState.h @@ -0,0 +1,23 @@ +#ifndef __BUTTON_FIELD_STATE_H__
+# define __BUTTON_FIELD_STATE_H__
+
+#include "ControlFieldState.h"
+
+
+class ButtonFieldState : public ControlFieldState
+{
+public:
+ virtual ~ButtonFieldState();
+
+ virtual Size getPreferedSize() const;
+
+ virtual bool isEmpty() const;
+
+private:
+ ButtonFieldState(DialogState *dialog, ControlField *field);
+
+ friend class ButtonField;
+};
+
+
+#endif // __BUTTON_FIELD_STATE_H__
diff --git a/plugins/Skins/SkinLib/ButtonFieldState_v8_wrapper.cpp b/plugins/Skins/SkinLib/ButtonFieldState_v8_wrapper.cpp new file mode 100644 index 0000000000..c5916b284c --- /dev/null +++ b/plugins/Skins/SkinLib/ButtonFieldState_v8_wrapper.cpp @@ -0,0 +1,20 @@ +#include "globals.h"
+#include "ButtonFieldState_v8_wrapper.h"
+#include <v8.h>
+#include "ButtonFieldState.h"
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+void AddButtonFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+}
diff --git a/plugins/Skins/SkinLib/ButtonFieldState_v8_wrapper.h b/plugins/Skins/SkinLib/ButtonFieldState_v8_wrapper.h new file mode 100644 index 0000000000..c69fdc5c87 --- /dev/null +++ b/plugins/Skins/SkinLib/ButtonFieldState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __BUTTON_FIELD_STATE_V8_WRAPPER_H__
+# define __BUTTON_FIELD_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddButtonFieldStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __BUTTON_FIELD_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/ControlField.cpp b/plugins/Skins/SkinLib/ControlField.cpp new file mode 100644 index 0000000000..dd9d7026d9 --- /dev/null +++ b/plugins/Skins/SkinLib/ControlField.cpp @@ -0,0 +1,123 @@ +#include "globals.h"
+#include "ControlField.h"
+#include "ControlFieldState.h"
+
+
+ControlField::ControlField(Dialog *dlg, const char *name, HWND aHwnd)
+ : Field(dlg, name), hwnd(aHwnd), textSet(false), hFont(NULL)
+{
+}
+
+
+ControlField::~ControlField()
+{
+}
+
+
+HWND ControlField::getHWND()
+{
+ return hwnd;
+}
+
+
+
+void ControlField::setText(const TCHAR *text)
+{
+ if (text == NULL)
+ {
+ if (!textSet)
+ return;
+
+ textSet = false;
+ this->text.clear();
+ fireOnChange();
+ }
+ else
+ {
+ textSet = true;
+ if (this->text == text)
+ return;
+
+ this->text = text;
+ // SetWindowText(hwnd, text);
+ fireOnChange();
+ }
+}
+
+
+const TCHAR * ControlField::getText()
+{
+ if (textSet)
+ return text.c_str();
+
+ // Control text is the default value
+ int length = GetWindowTextLength(hwnd);
+ if (length <= 0)
+ {
+ text = _T("");
+ }
+ else
+ {
+ TCHAR *tmp = new TCHAR[length+1];
+
+ if (GetWindowText(hwnd, tmp, length+1) == 0)
+ tmp[0] = 0;
+
+ text = tmp;
+
+ delete[] tmp;
+ }
+
+ return text.c_str();
+}
+
+
+void ControlField::setFont(HFONT hFont)
+{
+ if (this->hFont == hFont)
+ return;
+
+ this->hFont = hFont;
+// SendMessage(hwnd, WM_SETFONT, (WPARAM) hFont, FALSE);
+ fireOnChange();
+}
+
+
+HFONT ControlField::getFont() const
+{
+ if (hFont != NULL)
+ return hFont;
+
+ // Control font is the default value
+ return (HFONT) SendMessage(hwnd, WM_GETFONT, 0, 0);
+}
+
+
+COLORREF ControlField::getFontColor() const
+{
+ return GetSysColor(COLOR_WINDOWTEXT);
+}
+
+
+int ControlField::getBorderSize() const
+{
+ int exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+ if (exstyle & WS_EX_CLIENTEDGE)
+ return GetSystemMetrics(SM_CXEDGE);
+ if (exstyle & WS_EX_STATICEDGE)
+ return GetSystemMetrics(SM_CXBORDER);
+
+ int style = GetWindowLong(hwnd, GWL_STYLE);
+ if (style & WS_BORDER)
+ return GetSystemMetrics(SM_CXBORDER);
+
+ return 0;
+}
+
+bool ControlField::isScrollVisible(bool horizontal) const
+{
+ SCROLLBARINFO sbi = {0};
+ sbi.cbSize = sizeof(SCROLLBARINFO);
+ GetScrollBarInfo(hwnd, horizontal ? OBJID_HSCROLL : OBJID_VSCROLL, &sbi);
+ return (sbi.rgstate[0] & STATE_SYSTEM_INVISIBLE) == 0;
+}
diff --git a/plugins/Skins/SkinLib/ControlField.h b/plugins/Skins/SkinLib/ControlField.h new file mode 100644 index 0000000000..014ee04b9b --- /dev/null +++ b/plugins/Skins/SkinLib/ControlField.h @@ -0,0 +1,37 @@ +#ifndef __LABEL_CONTROL_FIELD_H__
+# define __LABEL_CONTROL_FIELD_H__
+
+#include "Field.h"
+
+class ControlField : public Field
+{
+public:
+ ControlField(Dialog *dlg, const char *name, HWND hwnd);
+ virtual ~ControlField();
+
+ virtual HWND getHWND();
+
+ virtual void setText(const TCHAR *text);
+ virtual const TCHAR * getText();
+
+ virtual void setFont(HFONT hFont);
+ virtual HFONT getFont() const;
+
+ virtual COLORREF getFontColor() const;
+
+ virtual int getBorderSize() const;
+
+ virtual bool isScrollVisible(bool horizontal) const;
+
+private:
+ HWND hwnd;
+
+ bool textSet;
+ std::tstring text;
+
+ HFONT hFont;
+};
+
+
+
+#endif // __LABEL_CONTROL_FIELD_H__
diff --git a/plugins/Skins/SkinLib/ControlFieldState.cpp b/plugins/Skins/SkinLib/ControlFieldState.cpp new file mode 100644 index 0000000000..37c412058a --- /dev/null +++ b/plugins/Skins/SkinLib/ControlFieldState.cpp @@ -0,0 +1,86 @@ +#include "globals.h"
+#include "ControlFieldState.h"
+
+
+ControlFieldState::ControlFieldState(DialogState *dialog, ControlField *field)
+ : FieldState(dialog, field), textSet(false), font(field->getFont(), field->getFontColor())
+{
+}
+
+
+ControlFieldState::~ControlFieldState()
+{
+}
+
+
+ControlField * ControlFieldState::getField() const
+{
+ return (ControlField *) FieldState::getField();
+}
+
+
+Size ControlFieldState::getTextPreferedSize(unsigned int format) const
+{
+ HDC hdc = CreateCompatibleDC(NULL);
+
+ HFONT newFont = getFont()->getHFONT();
+ HFONT oldFont = (HFONT) SelectObject(hdc, newFont);
+
+ int width = 0;
+ int height = 0;
+
+ const TCHAR *text = getText();
+ int len = lstrlen(text);
+ if (len <= 0)
+ {
+ TEXTMETRIC tm = {0};
+ GetTextMetrics(hdc, &tm);
+ height = tm.tmHeight;
+ }
+ else
+ {
+ RECT rc = {0};
+ if ((format & DT_SINGLELINE) == 0 && size.x >= 0)
+ {
+ format |= DT_WORDBREAK;
+ rc.right = size.x;
+ }
+ DrawText(hdc, text, len, &rc, DT_CALCRECT | format);
+ width = rc.right - rc.left;
+ height = rc.bottom - rc.top;
+ }
+
+ SelectObject(hdc, oldFont);
+
+ DeleteDC(hdc);
+
+ return Size(width, height);
+}
+
+
+const TCHAR * ControlFieldState::getText() const
+{
+ if (textSet)
+ return text.c_str();
+
+ return getField()->getText();
+}
+
+
+void ControlFieldState::setText(const TCHAR *text)
+{
+ this->text = text;
+ textSet = true;
+}
+
+
+FontState * ControlFieldState::getFont()
+{
+ return &font;
+}
+
+
+const FontState * ControlFieldState::getFont() const
+{
+ return &font;
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/ControlFieldState.h b/plugins/Skins/SkinLib/ControlFieldState.h new file mode 100644 index 0000000000..85186c304a --- /dev/null +++ b/plugins/Skins/SkinLib/ControlFieldState.h @@ -0,0 +1,39 @@ +#ifndef __LABEL_CONTROL_FIELD_STATE_H__
+# define __LABEL_CONTROL_FIELD_STATE_H__
+
+#include "ControlField.h"
+#include "FieldState.h"
+#include "FontState.h"
+
+
+class ControlFieldState : public FieldState
+{
+public:
+ virtual ~ControlFieldState();
+
+ virtual ControlField * getField() const;
+
+ virtual Size getPreferedSize() const = 0;
+
+ virtual const TCHAR * getText() const;
+ virtual void setText(const TCHAR *text);
+
+ virtual FontState * getFont();
+ virtual const FontState * getFont() const;
+
+protected:
+ ControlFieldState(DialogState *dialog, ControlField *field);
+
+ virtual Size getTextPreferedSize(unsigned int format) const;
+
+private:
+ FontState font;
+
+ bool textSet;
+ std::tstring text;
+
+ friend class ControlField;
+};
+
+
+#endif // __LABEL_CONTROL_FIELD_STATE_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/ControlFieldState_v8_wrapper.cpp b/plugins/Skins/SkinLib/ControlFieldState_v8_wrapper.cpp new file mode 100644 index 0000000000..70d3e06a45 --- /dev/null +++ b/plugins/Skins/SkinLib/ControlFieldState_v8_wrapper.cpp @@ -0,0 +1,59 @@ +#include "globals.h"
+#include "ControlFieldState_v8_wrapper.h"
+#include <v8.h>
+#include "ControlFieldState.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_ControlFieldState_text(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ ControlFieldState *tmp = (ControlFieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( String::New((const V8_TCHAR *) tmp->getText()) );
+}
+
+static void Set_ControlFieldState_text(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ ControlFieldState *tmp = (ControlFieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsString())
+ {
+ String::Utf8Value utf8_value(value);
+ tmp->setText(Utf8ToTchar(*utf8_value));
+ }
+}
+
+
+void AddControlFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->SetAccessor(String::New("text"), Get_ControlFieldState_text, Set_ControlFieldState_text);
+}
diff --git a/plugins/Skins/SkinLib/ControlFieldState_v8_wrapper.h b/plugins/Skins/SkinLib/ControlFieldState_v8_wrapper.h new file mode 100644 index 0000000000..c86964ce30 --- /dev/null +++ b/plugins/Skins/SkinLib/ControlFieldState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __CONTROL_FIELD_STATE_V8_WRAPPER_H__
+# define __CONTROL_FIELD_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddControlFieldStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __CONTROL_FIELD_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/Dialog.cpp b/plugins/Skins/SkinLib/Dialog.cpp new file mode 100644 index 0000000000..edc8437817 --- /dev/null +++ b/plugins/Skins/SkinLib/Dialog.cpp @@ -0,0 +1,100 @@ +#include "globals.h"
+#include "Dialog.h"
+#include "DialogState.h"
+
+
+Dialog::Dialog(const char *aName) : name(aName)
+{
+}
+
+
+Dialog::~Dialog()
+{
+ for(unsigned int i = 0; i < fields.size(); i++)
+ delete fields[i];
+
+ fields.clear();
+}
+
+
+const char * Dialog::getName() const
+{
+ return name.c_str();
+}
+
+
+bool Dialog::addField(Field *field)
+{
+ if (getField(field->getName()) != NULL)
+ return false;
+
+ fields.push_back(field);
+ return true;
+}
+
+
+Field * Dialog::getField(const char *name) const
+{
+ if (name == NULL || name[0] == 0)
+ return NULL;
+
+ for(unsigned int i = 0; i < fields.size(); i++)
+ {
+ Field *field = fields[i];
+ if (strcmp(name, field->getName()) == 0)
+ return field;
+ }
+
+ return NULL;
+}
+
+Field * Dialog::getField(unsigned int pos) const
+{
+ if (pos >= fields.size())
+ return NULL;
+ return fields[pos];
+}
+
+int Dialog::getIndexOf(Field *field) const
+{
+ for(unsigned int i = 0; i < fields.size(); i++)
+ {
+ Field *f = fields[i];
+ if (field == f)
+ return i;
+ }
+
+ return -1;
+}
+
+unsigned int Dialog::getFieldCount() const
+{
+ return fields.size();
+}
+
+DialogInfo * Dialog::getInfo()
+{
+ return &info;
+}
+
+const Size & Dialog::getSize() const
+{
+ return size;
+}
+
+
+void Dialog::setSize(const Size &size)
+{
+ this->size = size;
+}
+
+
+DialogState * Dialog::createState()
+{
+ DialogState *ret = new DialogState(this);
+
+ for(unsigned int i = 0; i < fields.size(); i++)
+ ret->fields.push_back(fields[i]->createState(ret));
+
+ return ret;
+}
diff --git a/plugins/Skins/SkinLib/Dialog.h b/plugins/Skins/SkinLib/Dialog.h new file mode 100644 index 0000000000..0e85b8e340 --- /dev/null +++ b/plugins/Skins/SkinLib/Dialog.h @@ -0,0 +1,41 @@ +#ifndef __DIALOG_H__
+# define __DIALOG_H__
+
+#include <vector>
+#include "Field.h"
+#include "DialogInfo.h"
+
+class DialogState;
+
+
+/// It is responsible for freeing the Fields
+class Dialog
+{
+public:
+ Dialog(const char *name);
+ virtual ~Dialog();
+
+ virtual const char * getName() const;
+
+ virtual bool addField(Field *field);
+ virtual Field * getField(const char *name) const;
+ virtual Field * getField(unsigned int pos) const;
+ virtual int getIndexOf(Field *field) const;
+ virtual unsigned int getFieldCount() const;
+
+ virtual DialogInfo * getInfo();
+
+ virtual const Size & getSize() const;
+ virtual void setSize(const Size &size);
+
+ virtual DialogState * createState();
+
+private:
+ const std::string name;
+ std::vector<Field *> fields;
+ DialogInfo info;
+ Size size;
+};
+
+
+#endif // __DIALOG_H__
diff --git a/plugins/Skins/SkinLib/DialogInfo.cpp b/plugins/Skins/SkinLib/DialogInfo.cpp new file mode 100644 index 0000000000..fd29a37392 --- /dev/null +++ b/plugins/Skins/SkinLib/DialogInfo.cpp @@ -0,0 +1,190 @@ +#include "globals.h"
+#include "DialogInfo.h"
+#include "tstring.h"
+
+class DialogInfoValue
+{
+public:
+ DialogInfoValue(const char *aName) : name(aName), type(UNKNOWN) {}
+
+ const char * getName() { return name.c_str(); }
+
+ void set(const TCHAR *value) { valueString = value; type = TYPE_STRING; }
+ void set(int value) { valueInt = value; type = TYPE_INT; }
+ void set(double value) { valueDouble = value; type = TYPE_DOUBLE; }
+ void set(bool value) { valueBool = value; type = TYPE_BOOL; }
+
+ DialogInfoType getType() { return type; }
+
+ const TCHAR * getAsString() { return valueString.c_str(); }
+ int getAsInt() { return valueInt; }
+ double getAsDouble() { return valueDouble; }
+ bool getAsBool() { return valueBool; }
+
+private:
+ std::string name;
+
+ DialogInfoType type;
+
+ std::tstring valueString;
+ int valueInt;
+ double valueDouble;
+ bool valueBool;
+};
+
+DialogInfo::DialogInfo()
+{
+}
+
+DialogInfo::~DialogInfo()
+{
+ for(size_t i = 0; i < values.size(); ++i)
+ delete values[i];
+}
+
+
+void DialogInfo::set(const char *name, const TCHAR *value)
+{
+ bool isVar;
+ DialogInfoValue * val = findValue(name, true, &isVar);
+
+ if (isVar)
+ return;
+
+ val->set(value);
+}
+
+void DialogInfo::set(const char *name, int value)
+{
+ bool isVar;
+ DialogInfoValue * val = findValue(name, true, &isVar);
+
+ if (isVar)
+ return;
+
+ val->set(value);
+}
+
+void DialogInfo::set(const char *name, double value)
+{
+ bool isVar;
+ DialogInfoValue * val = findValue(name, true, &isVar);
+
+ if (isVar)
+ return;
+
+ val->set(value);
+}
+
+void DialogInfo::set(const char *name, bool value)
+{
+ bool isVar;
+ DialogInfoValue * val = findValue(name, true, &isVar);
+
+ if (isVar)
+ return;
+
+ val->set(value);
+}
+
+void DialogInfo::remove(const char *name)
+{
+ size_t len = strlen(name);
+
+ for(std::vector<DialogInfoValue *>::iterator it = values.begin(); it != values.end(); )
+ {
+ DialogInfoValue *val = *it;
+
+ if (stricmp(name, val->getName()) == 0)
+ it = values.erase(it);
+
+ else if (strnicmp(name, val->getName(), len) == 0 && val->getName()[len] == '.')
+ it = values.erase(it);
+
+ else
+ it++;
+ }
+}
+
+DialogInfoType DialogInfo::getType(const char *name)
+{
+ bool isVar;
+ DialogInfoValue * val = findValue(name, false, &isVar);
+
+ if (isVar)
+ return TYPE_VARIABLE;
+
+ else if (val == NULL)
+ return UNKNOWN;
+
+ else
+ return val->getType();
+}
+
+
+const TCHAR * DialogInfo::getAsString(const char *name)
+{
+ DialogInfoValue * val = findValue(name);
+ if (val == NULL)
+ return NULL;
+
+ return val->getAsString();
+}
+
+int DialogInfo::getAsInt(const char *name)
+{
+ DialogInfoValue * val = findValue(name);
+ if (val == NULL)
+ return 0;
+
+ return val->getAsInt();
+}
+
+double DialogInfo::getAsDouble(const char *name)
+{
+ DialogInfoValue * val = findValue(name);
+ if (val == NULL)
+ return 0;
+
+ return val->getAsDouble();
+}
+
+bool DialogInfo::getAsBool(const char *name)
+{
+ DialogInfoValue * val = findValue(name);
+ if (val == NULL)
+ return false;
+
+ return val->getAsBool();
+}
+
+DialogInfoValue * DialogInfo::findValue(const char *name, bool create, bool *isVar)
+{
+ size_t len = strlen(name);
+
+ if (isVar != NULL) *isVar = false;
+
+ for(size_t i = 0; i < values.size(); ++i)
+ {
+ DialogInfoValue *val = values[i];
+
+ if (stricmp(name, val->getName()) == 0)
+ {
+ return val;
+ }
+ else if (strnicmp(name, val->getName(), len) == 0 && val->getName()[len] == '.')
+ {
+ if (isVar != NULL) *isVar = true;
+ return val;
+ }
+ }
+
+ if (create)
+ {
+ DialogInfoValue *ret = new DialogInfoValue(name);
+ values.push_back(ret);
+ return ret;
+ }
+
+ return NULL;
+}
diff --git a/plugins/Skins/SkinLib/DialogInfo.h b/plugins/Skins/SkinLib/DialogInfo.h new file mode 100644 index 0000000000..02f07310d7 --- /dev/null +++ b/plugins/Skins/SkinLib/DialogInfo.h @@ -0,0 +1,50 @@ +#ifndef __DIALOG_INFO_H__
+# define __DIALOG_INFO_H__
+
+#include <windows.h>
+#include <vector>
+
+
+enum DialogInfoType
+{
+ UNKNOWN = 0,
+ TYPE_VARIABLE,
+ TYPE_INT,
+ TYPE_DOUBLE,
+ TYPE_BOOL,
+ TYPE_STRING
+};
+
+
+class DialogInfoValue;
+
+class DialogInfo
+{
+public:
+ DialogInfo();
+ ~DialogInfo();
+
+ void set(const char *name, const TCHAR *value);
+ void set(const char *name, int value);
+ void set(const char *name, double value);
+ void set(const char *name, bool value);
+
+ void remove(const char *name);
+
+ DialogInfoType getType(const char *name);
+
+ const TCHAR * getAsString(const char *name);
+ int getAsInt(const char *name);
+ double getAsDouble(const char *name);
+ bool getAsBool(const char *name);
+
+private:
+ std::vector<DialogInfoValue *> values;
+
+ DialogInfoValue * findValue(const char *name, bool create = false, bool *isVar = NULL);
+
+};
+
+
+
+#endif // __DIALOG_INFO_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/DialogState.cpp b/plugins/Skins/SkinLib/DialogState.cpp new file mode 100644 index 0000000000..e1e7654930 --- /dev/null +++ b/plugins/Skins/SkinLib/DialogState.cpp @@ -0,0 +1,132 @@ +#include "globals.h"
+#include "DialogState.h"
+
+
+DialogState::DialogState(Dialog *aDialog) : dialog(aDialog), size(-1,-1), borders(0,0,0,0)
+{
+}
+
+DialogState::~DialogState()
+{
+ for(unsigned int i = 0; i < fields.size(); i++)
+ delete fields[i];
+
+ fields.clear();
+}
+
+Dialog * DialogState::getDialog() const
+{
+ return dialog;
+}
+
+FieldState * DialogState::getField(const char *name) const
+{
+ if (name == NULL || name[0] == 0)
+ return NULL;
+
+ for(unsigned int i = 0; i < fields.size(); i++)
+ {
+ FieldState *field = fields[i];
+ if (strcmp(name, field->getField()->getName()) == 0)
+ return field;
+ }
+
+ return NULL;
+}
+
+int DialogState::getX() const
+{
+ return 0;
+}
+
+int DialogState::getY() const
+{
+ return 0;
+}
+
+int DialogState::getLeft() const
+{
+ return getX();
+}
+
+int DialogState::getTop() const
+{
+ return getY();
+}
+
+int DialogState::getRight() const
+{
+ return getX() + getWidth();
+}
+
+int DialogState::getBottom() const
+{
+ return getY() + getHeight();
+}
+
+int DialogState::getWidth() const
+{
+ if (size.x >= 0)
+ return size.x - getHorizontalBorders();
+
+ return dialog->getSize().x - getHorizontalBorders();
+}
+
+void DialogState::setWidth(int width)
+{
+ size.x = max(0, width) + getHorizontalBorders();
+}
+
+int DialogState::getHeight() const
+{
+ if (size.y >= 0)
+ return size.y - getVerticalBorders();
+
+ return dialog->getSize().y - getVerticalBorders();
+}
+
+void DialogState::setHeight(int height)
+{
+ size.y = max(0, height) + getVerticalBorders();
+}
+
+BorderState * DialogState::getBorders()
+{
+ return &borders;
+}
+
+const BorderState * DialogState::getBorders() const
+{
+ return &borders;
+}
+
+int DialogState::getHorizontalBorders() const
+{
+ return borders.getLeft() + borders.getRight();
+}
+
+int DialogState::getVerticalBorders() const
+{
+ return borders.getTop() + borders.getBottom();
+}
+
+RECT DialogState::getInsideRect() const
+{
+ RECT ret;
+ ret.left = borders.getLeft();
+ ret.right = ret.left + getWidth();
+ ret.top = borders.getTop();
+ ret.bottom = ret.top + getHeight();
+ return ret;
+}
+
+RECT DialogState::getRect() const
+{
+ RECT ret;
+ ret.left = 0;
+ ret.right = borders.getLeft() + getWidth() + borders.getRight();
+ ret.top = 0;
+ ret.bottom = borders.getTop() + getHeight() + borders.getBottom();
+ return ret;
+}
+
diff --git a/plugins/Skins/SkinLib/DialogState.h b/plugins/Skins/SkinLib/DialogState.h new file mode 100644 index 0000000000..e27fc929da --- /dev/null +++ b/plugins/Skins/SkinLib/DialogState.h @@ -0,0 +1,59 @@ +#ifndef __DIALOG_STATE_H__
+# define __DIALOG_STATE_H__
+
+#include "Dialog.h"
+#include "FieldState.h"
+#include "BorderState.h"
+
+
+/// This have to be deleted before the owning dialog
+/// It is responsible for freeing the FieldStates
+class DialogState
+{
+public:
+ ~DialogState();
+
+ Dialog * getDialog() const;
+
+ std::vector<FieldState *> fields;
+ FieldState * getField(const char *name) const;
+
+ // Used inside script
+
+ virtual int getX() const;
+ virtual int getY() const;
+ virtual int getLeft() const;
+ virtual int getTop() const;
+ virtual int getRight() const;
+ virtual int getBottom() const;
+
+ int getWidth() const;
+ void setWidth(int width);
+
+ int getHeight() const;
+ void setHeight(int height);
+
+ BorderState * getBorders();
+ const BorderState * getBorders() const;
+
+ // Results
+
+ RECT getInsideRect() const;
+ RECT getRect() const;
+
+private:
+ DialogState(Dialog *dialog);
+
+ Dialog *dialog;
+
+ Size size;
+ BorderState borders;
+
+ int getHorizontalBorders() const;
+ int getVerticalBorders() const;
+
+ friend class Dialog;
+};
+
+
+#endif // __DIALOG_STATE_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/DialogState_v8_wrapper.cpp b/plugins/Skins/SkinLib/DialogState_v8_wrapper.cpp new file mode 100644 index 0000000000..5739414d69 --- /dev/null +++ b/plugins/Skins/SkinLib/DialogState_v8_wrapper.cpp @@ -0,0 +1,233 @@ +#include "globals.h"
+#include "DialogState_v8_wrapper.h"
+#include <v8.h>
+#include "DialogState.h"
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+static Handle<Value> Get_DialogState_width(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getWidth()) );
+}
+
+static void Set_DialogState_width(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setWidth(value->Int32Value());
+}
+
+
+static Handle<Value> Get_DialogState_height(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getHeight()) );
+}
+
+static void Set_DialogState_height(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setHeight(value->Int32Value());
+}
+
+
+static Handle<Value> Get_DialogState_x(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getX()) );
+}
+
+
+static Handle<Value> Get_DialogState_y(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getY()) );
+}
+
+
+static Handle<Value> Get_DialogState_left(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getLeft()) );
+}
+
+
+static Handle<Value> Get_DialogState_top(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getTop()) );
+}
+
+
+static Handle<Value> Get_DialogState_right(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getRight()) );
+}
+
+
+static Handle<Value> Get_DialogState_bottom(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getBottom()) );
+}
+
+
+static Handle<Value> Get_DialogState_borders(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( self->Get(String::New("bordersRaw")) );
+}
+
+static void Set_DialogState_borders(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ DialogState *tmp = (DialogState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsInt32())
+ tmp->getBorders()->setAll(value->Int32Value());
+}
+
+
+void AddDialogStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->SetAccessor(String::New("width"), Get_DialogState_width, Set_DialogState_width);
+ templ->SetAccessor(String::New("height"), Get_DialogState_height, Set_DialogState_height);
+ templ->SetAccessor(String::New("x"), Get_DialogState_x, NULL, Handle<Value>(), DEFAULT, ReadOnly);
+ templ->SetAccessor(String::New("y"), Get_DialogState_y, NULL, Handle<Value>(), DEFAULT, ReadOnly);
+ templ->SetAccessor(String::New("left"), Get_DialogState_left, NULL, Handle<Value>(), DEFAULT, ReadOnly);
+ templ->SetAccessor(String::New("top"), Get_DialogState_top, NULL, Handle<Value>(), DEFAULT, ReadOnly);
+ templ->SetAccessor(String::New("right"), Get_DialogState_right, NULL, Handle<Value>(), DEFAULT, ReadOnly);
+ templ->SetAccessor(String::New("bottom"), Get_DialogState_bottom, NULL, Handle<Value>(), DEFAULT, ReadOnly);
+ templ->SetAccessor(String::New("borders"), Get_DialogState_borders, Set_DialogState_borders);
+}
diff --git a/plugins/Skins/SkinLib/DialogState_v8_wrapper.h b/plugins/Skins/SkinLib/DialogState_v8_wrapper.h new file mode 100644 index 0000000000..709ef2d738 --- /dev/null +++ b/plugins/Skins/SkinLib/DialogState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __DIALOG_STATE_V8_WRAPPER_H__
+# define __DIALOG_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddDialogStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __DIALOG_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/EditField.cpp b/plugins/Skins/SkinLib/EditField.cpp new file mode 100644 index 0000000000..8eb0d5050f --- /dev/null +++ b/plugins/Skins/SkinLib/EditField.cpp @@ -0,0 +1,23 @@ +#include "globals.h"
+#include "EditField.h"
+#include "EditFieldState.h"
+
+
+EditField::EditField(Dialog *dlg, const char *name, HWND hwnd)
+ : ControlField(dlg, name, hwnd)
+{
+}
+
+EditField::~EditField()
+{
+}
+
+FieldType EditField::getType() const
+{
+ return CONTROL_EDIT;
+}
+
+FieldState * EditField::createState(DialogState *dialogState)
+{
+ return new EditFieldState(dialogState, this);
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/EditField.h b/plugins/Skins/SkinLib/EditField.h new file mode 100644 index 0000000000..f69f23576c --- /dev/null +++ b/plugins/Skins/SkinLib/EditField.h @@ -0,0 +1,19 @@ +#ifndef __EDIT_FIELD_H__
+# define __EDIT_FIELD_H__
+
+#include "ControlField.h"
+
+
+class EditField : public ControlField
+{
+public:
+ EditField(Dialog *dlg, const char *name, HWND hwnd);
+ virtual ~EditField();
+
+ virtual FieldType getType() const;
+
+ virtual FieldState * createState(DialogState *dialogState);
+};
+
+
+#endif // __EDIT_FIELD_H__
diff --git a/plugins/Skins/SkinLib/EditFieldState.cpp b/plugins/Skins/SkinLib/EditFieldState.cpp new file mode 100644 index 0000000000..e634be7b55 --- /dev/null +++ b/plugins/Skins/SkinLib/EditFieldState.cpp @@ -0,0 +1,58 @@ +#include "globals.h"
+#include "EditFieldState.h"
+
+
+EditFieldState::EditFieldState(DialogState *dialog, EditField *field)
+ : ControlFieldState(dialog, field)
+{
+}
+
+EditFieldState::~EditFieldState()
+{
+}
+
+Size EditFieldState::getPreferedSize() const
+{
+ ControlField *field = getField();
+ HWND hwnd = field->getHWND();
+
+ int style = GetWindowLong(hwnd, GWL_STYLE);
+ int exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+
+ int format = DT_NOPREFIX | DT_EDITCONTROL;
+ if (!(style & ES_MULTILINE))
+ format |= DT_SINGLELINE;
+ Size ret = getTextPreferedSize(format);
+
+ RECT rc = {0};
+ SetRect(&rc, 0, 0, ret.x, ret.y);
+ AdjustWindowRectEx(&rc, style, false, exstyle);
+
+ bool hasHorScroll = field->isScrollVisible(true);
+ if (hasHorScroll)
+ rc.bottom += GetSystemMetrics(SM_CYHSCROLL);
+ if (field->isScrollVisible(false))
+ rc.right += GetSystemMetrics(SM_CXVSCROLL);
+
+ int margins = SendMessage(hwnd, EM_GETMARGINS, 0, 0);
+ rc.left -= LOWORD(margins);
+ rc.right += HIWORD(margins);
+ if (hasHorScroll || (style & ES_AUTOHSCROLL))
+ rc.right++;
+
+ ret.x = rc.right - rc.left;
+ ret.y = rc.bottom - rc.top;
+
+ if ((exstyle & WS_EX_CLIENTEDGE) || (exstyle & WS_EX_STATICEDGE) || (style & WS_BORDER))
+ {
+ ret.x += 3;
+ ret.y += 3;
+ }
+
+ return ret;
+}
+
+bool EditFieldState::isEmpty() const
+{
+ return false;
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/EditFieldState.h b/plugins/Skins/SkinLib/EditFieldState.h new file mode 100644 index 0000000000..c2372d553d --- /dev/null +++ b/plugins/Skins/SkinLib/EditFieldState.h @@ -0,0 +1,24 @@ +#ifndef __EDIT_FIELD_STATE_H__
+# define __EDIT_FIELD_STATE_H__
+
+#include "ControlFieldState.h"
+#include "EditField.h"
+
+
+class EditFieldState : public ControlFieldState
+{
+public:
+ virtual ~EditFieldState();
+
+ virtual Size getPreferedSize() const;
+
+ virtual bool isEmpty() const;
+
+private:
+ EditFieldState(DialogState *dialog, EditField *field);
+
+ friend class EditField;
+};
+
+
+#endif // __EDIT_FIELD_STATE_H__
diff --git a/plugins/Skins/SkinLib/EditFieldState_v8_wrapper.cpp b/plugins/Skins/SkinLib/EditFieldState_v8_wrapper.cpp new file mode 100644 index 0000000000..86522b87e3 --- /dev/null +++ b/plugins/Skins/SkinLib/EditFieldState_v8_wrapper.cpp @@ -0,0 +1,20 @@ +#include "globals.h"
+#include "EditFieldState_v8_wrapper.h"
+#include <v8.h>
+#include "EditFieldState.h"
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+void AddEditFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+}
diff --git a/plugins/Skins/SkinLib/EditFieldState_v8_wrapper.h b/plugins/Skins/SkinLib/EditFieldState_v8_wrapper.h new file mode 100644 index 0000000000..a58972549f --- /dev/null +++ b/plugins/Skins/SkinLib/EditFieldState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __EDIT_FIELD_STATE_V8_WRAPPER_H__
+# define __EDIT_FIELD_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddEditFieldStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __EDIT_FIELD_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/Field.cpp b/plugins/Skins/SkinLib/Field.cpp new file mode 100644 index 0000000000..24b823bde6 --- /dev/null +++ b/plugins/Skins/SkinLib/Field.cpp @@ -0,0 +1,56 @@ +#include "globals.h"
+#include "Field.h"
+#include "FieldState.h"
+
+
+Field::Field(Dialog *aDlg, const char *aName)
+ : dlg(aDlg), name(aName), onChangeCallback(NULL), onChangeCallbackParam(NULL), enabled(true)
+{
+}
+
+Field::~Field()
+{
+}
+
+Dialog * Field::getDialog() const
+{
+ return dlg;
+}
+
+const char * Field::getName() const
+{
+ return name.c_str();
+}
+
+bool Field::isEnabled() const
+{
+ return enabled;
+}
+
+void Field::setEnabled(bool enabled)
+{
+ this->enabled = enabled;
+ fireOnChange();
+}
+
+const TCHAR * Field::getToolTip() const
+{
+ return tooltip.c_str();
+}
+
+void Field::setToolTip(const TCHAR *tooltip)
+{
+ this->tooltip = tooltip;
+}
+
+void Field::setOnChangeCallback(FieldCallback cb, void *param /*= NULL*/)
+{
+ onChangeCallback = cb;
+ onChangeCallbackParam = param;
+}
+
+void Field::fireOnChange() const
+{
+ if (onChangeCallback != NULL)
+ onChangeCallback(onChangeCallbackParam, this);
+}
diff --git a/plugins/Skins/SkinLib/Field.h b/plugins/Skins/SkinLib/Field.h new file mode 100644 index 0000000000..4cf7faaa51 --- /dev/null +++ b/plugins/Skins/SkinLib/Field.h @@ -0,0 +1,66 @@ +#ifndef __FIELD_H__
+# define __FIELD_H__
+
+#include <windows.h>
+#include <tchar.h>
+#include "tstring.h"
+#include "Size.h"
+#include "Position.h"
+
+
+enum FieldType
+{
+ SIMPLE_TEXT = 1,
+ SIMPLE_IMAGE,
+ SIMPLE_ICON,
+ CONTROL_LABEL,
+ CONTROL_BUTTON,
+ CONTROL_EDIT,
+ USER_DEFINED = 0x100
+};
+
+class Dialog;
+class DialogState;
+class Field;
+class FieldState;
+
+typedef void (*FieldCallback)(void *param, const Field *field);
+
+
+class Field
+{
+public:
+ Field(Dialog *dlg, const char *name);
+ virtual ~Field();
+
+ virtual Dialog * getDialog() const;
+ virtual const char * getName() const;
+ virtual FieldType getType() const = 0;
+
+ virtual bool isEnabled() const;
+ virtual void setEnabled(bool enabled);
+
+ virtual const TCHAR * getToolTip() const;
+ virtual void setToolTip(const TCHAR *tooltip);
+
+ virtual FieldState * createState(DialogState *dialogState) = 0;
+
+ virtual void setOnChangeCallback(FieldCallback cb, void *param = NULL);
+
+protected:
+ void fireOnChange() const;
+
+private:
+ Dialog *dlg;
+ const std::string name;
+ bool enabled;
+ std::tstring tooltip;
+
+ FieldCallback onChangeCallback;
+ void *onChangeCallbackParam;
+};
+
+
+
+
+#endif // __FIELD_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/FieldState.cpp b/plugins/Skins/SkinLib/FieldState.cpp new file mode 100644 index 0000000000..68510051da --- /dev/null +++ b/plugins/Skins/SkinLib/FieldState.cpp @@ -0,0 +1,303 @@ +#include "globals.h"
+#include "FieldState.h"
+#include "DialogState.h"
+#include "BorderState.h"
+
+#define START 1<<0
+#define LEN 1<<1
+#define END 1<<2
+#define USING_MASK 0xFF
+#define LAST_SHIFT 8
+#define SET(_FIELD_, _ITEM_) _FIELD_ = (((_FIELD_ | _ITEM_) & USING_MASK) | (_ITEM_ << LAST_SHIFT))
+#define LAST_SET(_FIELD_) (_FIELD_ >> LAST_SHIFT)
+
+
+FieldState::FieldState(DialogState *aDialog, Field *aField)
+ : field(aField), dialog(aDialog), size(-1, -1), pos(0, 0),
+ usingX(0), usingY(0), visible(aField->isEnabled()), borders(0,0,0,0),
+ tooltipSet(false), halign(HORIZONTAL_ALIGN_LEFT), valign(VERTICAL_ALIGN_TOP)
+{
+}
+
+FieldState::~FieldState()
+{
+}
+
+Field * FieldState::getField() const
+{
+ return field;
+}
+
+DialogState * FieldState::getDialog() const
+{
+ return dialog;
+}
+
+int FieldState::getX() const
+{
+ return pos.x;
+}
+
+void FieldState::setX(int x)
+{
+ if (usingX & END)
+ {
+ int diff = x - getX();
+ size.x = max(0, getWidth() - getHorizontalBorders() - diff);
+ }
+
+ pos.x = x;
+
+ SET(usingX, START);
+}
+
+int FieldState::getY() const
+{
+ return pos.y;
+}
+
+void FieldState::setY(int y)
+{
+ if (usingY & END)
+ {
+ int diff = y - getY();
+ size.y = max(0, getHeight() - getVerticalBorders() - diff);
+ }
+
+ pos.y = y;
+
+ SET(usingY, START);
+}
+
+int FieldState::getWidth() const
+{
+ if (size.x >= 0)
+ return size.x + getHorizontalBorders();
+
+ return getPreferedSize().x + getHorizontalBorders();
+}
+
+void FieldState::setWidth(int width)
+{
+ width = max(0, width - getHorizontalBorders()) + getHorizontalBorders();
+
+ if (LAST_SET(usingX) == END)
+ {
+ int diff = width - getWidth();
+ pos.x = getX() - diff;
+ }
+
+ size.x = width - getHorizontalBorders();
+
+ usingX |= LEN;
+}
+
+int FieldState::getHeight() const
+{
+ if (size.y >= 0)
+ return size.y + getVerticalBorders();
+
+ return getPreferedSize().y + getVerticalBorders();
+}
+
+void FieldState::setHeight(int height)
+{
+ height = max(0, height - getVerticalBorders()) + getVerticalBorders();
+
+ if (LAST_SET(usingY) == END)
+ {
+ int diff = height - getHeight();
+ pos.y = getY() - diff;
+ }
+
+ size.y = height - getVerticalBorders();
+
+ usingY |= LEN;
+}
+
+bool FieldState::isVisible() const
+{
+ if (!visible)
+ return false;
+
+ RECT rc = getRect();
+ if (rc.right <= rc.left || rc.bottom <= rc.top)
+ return false;
+
+ return true;
+}
+
+void FieldState::setVisible(bool visible)
+{
+ this->visible = visible;
+}
+
+bool FieldState::isEnabled() const
+{
+ return field->isEnabled();
+}
+
+int FieldState::getLeft() const
+{
+ return getX();
+}
+
+void FieldState::setLeft(int left)
+{
+ setX(left);
+}
+
+int FieldState::getTop() const
+{
+ return getY();
+}
+
+void FieldState::setTop(int top)
+{
+ setY(top);
+}
+
+int FieldState::getRight() const
+{
+ return getX() + getWidth();
+}
+
+void FieldState::setRight(int right)
+{
+ if (usingX & START)
+ {
+ size.x = max(0, right - getX());
+ }
+ else
+ {
+ pos.x = right - getWidth();
+ }
+
+ SET(usingX, END);
+}
+
+int FieldState::getBottom() const
+{
+ return getY() + getHeight();
+}
+
+void FieldState::setBottom(int botom)
+{
+ if (usingY & START)
+ {
+ size.y = max(0, botom - getY());
+ }
+ else
+ {
+ pos.y = botom - getHeight();
+ }
+
+ SET(usingY, END);
+}
+
+const TCHAR * FieldState::getToolTip() const
+{
+ if (tooltipSet)
+ return tooltip.c_str();
+ else
+ return field->getToolTip();
+}
+
+void FieldState::setToolTip(const TCHAR *tooltip)
+{
+ this->tooltip = tooltip;
+ tooltipSet = true;
+}
+
+BorderState * FieldState::getBorders()
+{
+ return &borders;
+}
+
+const BorderState * FieldState::getBorders() const
+{
+ return &borders;
+}
+
+int FieldState::getHorizontalBorders() const
+{
+ return borders.getLeft() + borders.getRight();
+}
+
+int FieldState::getVerticalBorders() const
+{
+ return borders.getTop() + borders.getBottom();
+}
+
+static inline int beetween(int val, int minVal, int maxVal)
+{
+ return max(minVal, min(maxVal, val));
+}
+
+static inline void intersection(RECT &main, const RECT &other)
+{
+ main.left = beetween(main.left, other.left, other.right);
+ main.right = beetween(main.right, other.left, other.right);
+ main.top = beetween(main.top, other.top, other.bottom);
+ main.bottom = beetween(main.bottom, other.top, other.bottom);
+}
+
+RECT FieldState::getRect(bool raw) const
+{
+ RECT ret = {0};
+
+ if (!visible)
+ return ret;
+
+ RECT inside = dialog->getInsideRect();
+
+ ret.left = getLeft() + inside.left;
+ ret.right = getRight() + inside.left;
+ ret.top = getTop() + inside.top;
+ ret.bottom = getBottom() + inside.top;
+
+ if (!raw)
+ intersection(ret, inside);
+
+ return ret;
+}
+
+RECT FieldState::getInsideRect(bool raw) const
+{
+ RECT ret = {0};
+
+ if (!visible)
+ return ret;
+
+ RECT inside = dialog->getInsideRect();
+
+ ret.left = getLeft() + borders.getLeft() + inside.left;
+ ret.right = getRight() - borders.getRight() + inside.left;
+ ret.top = getTop() + borders.getTop() + inside.top;
+ ret.bottom = getBottom() - borders.getBottom() + inside.top;
+
+ if (!raw)
+ intersection(ret, inside);
+
+ return ret;
+}
+
+HORIZONTAL_ALIGN FieldState::getHAlign() const
+{
+ return halign;
+}
+
+void FieldState::setHAlign(HORIZONTAL_ALIGN halign)
+{
+ this->halign = halign;
+}
+
+VERTICAL_ALIGN FieldState::getVAlign() const
+{
+ return valign;
+}
+
+void FieldState::setVAlign(VERTICAL_ALIGN valign)
+{
+ this->valign = valign;
+}
diff --git a/plugins/Skins/SkinLib/FieldState.h b/plugins/Skins/SkinLib/FieldState.h new file mode 100644 index 0000000000..d7c552105f --- /dev/null +++ b/plugins/Skins/SkinLib/FieldState.h @@ -0,0 +1,108 @@ +#ifndef __FIELD_STATE_H__
+# define __FIELD_STATE_H__
+
+#include "Field.h"
+#include "BorderState.h"
+
+class DialogState;
+
+enum HORIZONTAL_ALIGN
+{
+ HORIZONTAL_ALIGN_LEFT = 1,
+ HORIZONTAL_ALIGN_CENTER,
+ HORIZONTAL_ALIGN_RIGHT
+};
+
+enum VERTICAL_ALIGN
+{
+ VERTICAL_ALIGN_TOP = 1,
+ VERTICAL_ALIGN_CENTER,
+ VERTICAL_ALIGN_BOTTOM
+};
+
+
+class FieldState
+{
+public:
+ virtual ~FieldState();
+
+ virtual Field * getField() const;
+ virtual DialogState * getDialog() const;
+
+ virtual Size getPreferedSize() const = 0;
+
+ // Used inside script
+
+ virtual int getX() const;
+ virtual void setX(int x);
+
+ virtual int getY() const;
+ virtual void setY(int y);
+
+ virtual int getWidth() const;
+ virtual void setWidth(int width);
+
+ virtual int getHeight() const;
+ virtual void setHeight(int height);
+
+ virtual int getLeft() const;
+ virtual void setLeft(int left);
+
+ virtual int getTop() const;
+ virtual void setTop(int top);
+
+ virtual int getRight() const;
+ virtual void setRight(int right);
+
+ virtual int getBottom() const;
+ virtual void setBottom(int bottom);
+
+ virtual bool isVisible() const;
+ virtual void setVisible(bool visible);
+
+ virtual bool isEnabled() const;
+
+ virtual const TCHAR * getToolTip() const;
+ virtual void setToolTip(const TCHAR *tooltip);
+
+ virtual BorderState * getBorders();
+ virtual const BorderState * getBorders() const;
+
+ virtual HORIZONTAL_ALIGN getHAlign() const;
+ virtual void setHAlign(HORIZONTAL_ALIGN halign);
+
+ virtual VERTICAL_ALIGN getVAlign() const;
+ virtual void setVAlign(VERTICAL_ALIGN valign);
+
+ virtual bool isEmpty() const = 0;
+
+ // Results
+
+ virtual RECT getInsideRect(bool raw = false) const;
+ virtual RECT getRect(bool raw = false) const;
+
+protected:
+ FieldState(DialogState *dialog, Field *field);
+
+ Field *field;
+ DialogState *dialog;
+
+ Size size;
+ Position pos;
+ int usingX;
+ int usingY;
+ bool visible;
+ BorderState borders;
+ bool tooltipSet;
+ std::tstring tooltip;
+ HORIZONTAL_ALIGN halign;
+ VERTICAL_ALIGN valign;
+
+ int getHorizontalBorders() const;
+ int getVerticalBorders() const;
+
+ friend class Field;
+};
+
+
+#endif // __FIELD_STATE_H__
diff --git a/plugins/Skins/SkinLib/FieldState.rec b/plugins/Skins/SkinLib/FieldState.rec new file mode 100644 index 0000000000..7b9ffd890d --- /dev/null +++ b/plugins/Skins/SkinLib/FieldState.rec @@ -0,0 +1,89 @@ +struct DialogState
+{
+ Int32 width;
+ Int32 height;
+ const Int32 x;
+ const Int32 y;
+ const Int32 left;
+ const Int32 top;
+ const Int32 right;
+ const Int32 bottom;
+ BorderState borders [setter: if (!value.IsEmpty() && value->IsInt32())\n\ttmp->getBorders()->setAll(value->Int32Value()); ];
+};
+
+struct FieldState
+{
+ Int32 x;
+ Int32 y;
+ Int32 width;
+ Int32 height;
+ Int32 left;
+ Int32 top;
+ Int32 right;
+ Int32 bottom;
+ Boolean visible;
+ const Boolean enabled;
+ Char toolTip[128];
+ Int32 hAlign | HORIZONTAL_ALIGN_LEFT "LEFT" | HORIZONTAL_ALIGN_CENTER "CENTER" | HORIZONTAL_ALIGN_RIGHT "RIGHT";
+ Int32 vAlign | VERTICAL_ALIGN_TOP "TOP" | VERTICAL_ALIGN_CENTER "CENTER" | VERTICAL_ALIGN_BOTTOM "BOTTOM";
+ BorderState borders [setter: if (!value.IsEmpty() && value->IsInt32())\n\ttmp->getBorders()->setAll(value->Int32Value()); ];
+};
+
+struct ControlFieldState : FieldState
+{
+ Char text[1024];
+ FontState font;
+};
+
+struct LabelFieldState : ControlFieldState
+{
+};
+
+struct ButtonFieldState : ControlFieldState
+{
+};
+
+struct EditFieldState : ControlFieldState
+{
+};
+
+struct IconFieldState : FieldState
+{
+};
+
+struct ImageFieldState : FieldState
+{
+};
+
+struct TextFieldState : FieldState
+{
+ Char text[1024];
+ FontState font;
+};
+
+struct FontState
+{
+ Char face[32];
+ Int32 size;
+ Boolean italic;
+ Boolean bold;
+ Boolean underline;
+ Boolean strikeOut;
+ Int32 color;
+};
+
+struct BorderState
+{
+ Int32 left;
+ Int32 right;
+ Int32 top;
+ Int32 bottom;
+};
+
+struct SkinOption
+{
+ Char description[128];
+ Int32 min;
+ Int32 max;
+ Int32 type | CHECKBOX | NUMBER | TEXT;
+};
diff --git a/plugins/Skins/SkinLib/FieldState_v8_wrapper.cpp b/plugins/Skins/SkinLib/FieldState_v8_wrapper.cpp new file mode 100644 index 0000000000..937ad69a58 --- /dev/null +++ b/plugins/Skins/SkinLib/FieldState_v8_wrapper.cpp @@ -0,0 +1,539 @@ +#include "globals.h"
+#include "FieldState_v8_wrapper.h"
+#include <v8.h>
+#include "FieldState.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_FieldState_x(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getX()) );
+}
+
+static void Set_FieldState_x(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setX(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_y(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getY()) );
+}
+
+static void Set_FieldState_y(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setY(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_width(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getWidth()) );
+}
+
+static void Set_FieldState_width(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setWidth(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_height(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getHeight()) );
+}
+
+static void Set_FieldState_height(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setHeight(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_left(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getLeft()) );
+}
+
+static void Set_FieldState_left(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setLeft(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_top(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getTop()) );
+}
+
+static void Set_FieldState_top(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setTop(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_right(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getRight()) );
+}
+
+static void Set_FieldState_right(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setRight(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_bottom(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getBottom()) );
+}
+
+static void Set_FieldState_bottom(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setBottom(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_visible(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Boolean::New(tmp->isVisible()) );
+}
+
+static void Set_FieldState_visible(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsBoolean())
+ tmp->setVisible(value->BooleanValue());
+}
+
+
+static Handle<Value> Get_FieldState_enabled(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Boolean::New(tmp->isEnabled()) );
+}
+
+
+static Handle<Value> Get_FieldState_toolTip(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( String::New((const V8_TCHAR *) tmp->getToolTip()) );
+}
+
+static void Set_FieldState_toolTip(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsString())
+ {
+ String::Utf8Value utf8_value(value);
+ tmp->setToolTip(Utf8ToTchar(*utf8_value));
+ }
+}
+
+
+static Handle<Value> Get_FieldState_hAlign(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ switch(tmp->getHAlign())
+ {
+ case HORIZONTAL_ALIGN_LEFT: return scope.Close( String::New((const V8_TCHAR *) _T("LEFT")) );
+ case HORIZONTAL_ALIGN_CENTER: return scope.Close( String::New((const V8_TCHAR *) _T("CENTER")) );
+ case HORIZONTAL_ALIGN_RIGHT: return scope.Close( String::New((const V8_TCHAR *) _T("RIGHT")) );
+ }
+ return scope.Close( Undefined() );
+}
+
+static void Set_FieldState_hAlign(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsString())
+ {
+ String::Utf8Value utf8_value(value);
+ Utf8ToTchar tval(*utf8_value);
+ if ( lstrcmpi(_T("HORIZONTAL_ALIGN_LEFT"), tval) == 0 )
+ tmp->setHAlign(HORIZONTAL_ALIGN_LEFT);
+ else if ( lstrcmpi(_T("LEFT"), tval) == 0 )
+ tmp->setHAlign(HORIZONTAL_ALIGN_LEFT);
+ else if ( lstrcmpi(_T("HORIZONTAL_ALIGN_CENTER"), tval) == 0 )
+ tmp->setHAlign(HORIZONTAL_ALIGN_CENTER);
+ else if ( lstrcmpi(_T("CENTER"), tval) == 0 )
+ tmp->setHAlign(HORIZONTAL_ALIGN_CENTER);
+ else if ( lstrcmpi(_T("HORIZONTAL_ALIGN_RIGHT"), tval) == 0 )
+ tmp->setHAlign(HORIZONTAL_ALIGN_RIGHT);
+ else if ( lstrcmpi(_T("RIGHT"), tval) == 0 )
+ tmp->setHAlign(HORIZONTAL_ALIGN_RIGHT);
+ }
+}
+
+
+static Handle<Value> Get_FieldState_vAlign(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ switch(tmp->getVAlign())
+ {
+ case VERTICAL_ALIGN_TOP: return scope.Close( String::New((const V8_TCHAR *) _T("TOP")) );
+ case VERTICAL_ALIGN_CENTER: return scope.Close( String::New((const V8_TCHAR *) _T("CENTER")) );
+ case VERTICAL_ALIGN_BOTTOM: return scope.Close( String::New((const V8_TCHAR *) _T("BOTTOM")) );
+ }
+ return scope.Close( Undefined() );
+}
+
+static void Set_FieldState_vAlign(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsString())
+ {
+ String::Utf8Value utf8_value(value);
+ Utf8ToTchar tval(*utf8_value);
+ if ( lstrcmpi(_T("VERTICAL_ALIGN_TOP"), tval) == 0 )
+ tmp->setVAlign(VERTICAL_ALIGN_TOP);
+ else if ( lstrcmpi(_T("TOP"), tval) == 0 )
+ tmp->setVAlign(VERTICAL_ALIGN_TOP);
+ else if ( lstrcmpi(_T("VERTICAL_ALIGN_CENTER"), tval) == 0 )
+ tmp->setVAlign(VERTICAL_ALIGN_CENTER);
+ else if ( lstrcmpi(_T("CENTER"), tval) == 0 )
+ tmp->setVAlign(VERTICAL_ALIGN_CENTER);
+ else if ( lstrcmpi(_T("VERTICAL_ALIGN_BOTTOM"), tval) == 0 )
+ tmp->setVAlign(VERTICAL_ALIGN_BOTTOM);
+ else if ( lstrcmpi(_T("BOTTOM"), tval) == 0 )
+ tmp->setVAlign(VERTICAL_ALIGN_BOTTOM);
+ }
+}
+
+
+static Handle<Value> Get_FieldState_borders(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( self->Get(String::New("bordersRaw")) );
+}
+
+static void Set_FieldState_borders(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FieldState *tmp = (FieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsInt32())
+ tmp->getBorders()->setAll(value->Int32Value());
+}
+
+
+void AddFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->SetAccessor(String::New("x"), Get_FieldState_x, Set_FieldState_x);
+ templ->SetAccessor(String::New("y"), Get_FieldState_y, Set_FieldState_y);
+ templ->SetAccessor(String::New("width"), Get_FieldState_width, Set_FieldState_width);
+ templ->SetAccessor(String::New("height"), Get_FieldState_height, Set_FieldState_height);
+ templ->SetAccessor(String::New("left"), Get_FieldState_left, Set_FieldState_left);
+ templ->SetAccessor(String::New("top"), Get_FieldState_top, Set_FieldState_top);
+ templ->SetAccessor(String::New("right"), Get_FieldState_right, Set_FieldState_right);
+ templ->SetAccessor(String::New("bottom"), Get_FieldState_bottom, Set_FieldState_bottom);
+ templ->SetAccessor(String::New("visible"), Get_FieldState_visible, Set_FieldState_visible);
+ templ->SetAccessor(String::New("enabled"), Get_FieldState_enabled, NULL, Handle<Value>(), DEFAULT, ReadOnly);
+ templ->SetAccessor(String::New("toolTip"), Get_FieldState_toolTip, Set_FieldState_toolTip);
+ templ->SetAccessor(String::New("hAlign"), Get_FieldState_hAlign, Set_FieldState_hAlign);
+ templ->SetAccessor(String::New("vAlign"), Get_FieldState_vAlign, Set_FieldState_vAlign);
+ templ->SetAccessor(String::New("borders"), Get_FieldState_borders, Set_FieldState_borders);
+}
diff --git a/plugins/Skins/SkinLib/FieldState_v8_wrapper.h b/plugins/Skins/SkinLib/FieldState_v8_wrapper.h new file mode 100644 index 0000000000..10c2a854b4 --- /dev/null +++ b/plugins/Skins/SkinLib/FieldState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __FIELD_STATE_V8_WRAPPER_H__
+# define __FIELD_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddFieldStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __FIELD_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/FontState.cpp b/plugins/Skins/SkinLib/FontState.cpp new file mode 100644 index 0000000000..da9b4153d5 --- /dev/null +++ b/plugins/Skins/SkinLib/FontState.cpp @@ -0,0 +1,186 @@ +#include "globals.h"
+#include "FontState.h"
+
+
+FontState::FontState(HFONT hFont, COLORREF aColor) : hFont(NULL), externalFont(false), color(aColor)
+{
+ setHFONT(hFont);
+}
+
+FontState::~FontState()
+{
+ releaseHFONT();
+}
+
+void FontState::rebuildHFONT()
+{
+ releaseHFONT();
+ buildHFONT();
+}
+
+void FontState::buildAttribs()
+{
+ LOGFONT lf = {0};
+ if (hFont == NULL || GetObject(hFont, sizeof(lf), &lf) == 0)
+ {
+ face = _T("Tahoma");
+ size = 9;
+ italic = false;
+ bold = false;
+ underline = false;
+ strikeout = false;
+
+ rebuildHFONT();
+
+ return;
+ }
+
+ face = lf.lfFaceName;
+ italic = (lf.lfItalic != 0);
+ bold = (lf.lfWeight > FW_NORMAL);
+ underline = (lf.lfUnderline != 0);
+ strikeout = (lf.lfStrikeOut != 0);
+
+ HDC hdc = GetDC(NULL);
+ size = -MulDiv(lf.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY));
+ ReleaseDC(NULL, hdc);
+}
+
+void FontState::buildHFONT()
+{
+ if (hFont != NULL)
+ return;
+
+ LOGFONT lf;
+
+ _tcscpy(lf.lfFaceName, getFace());
+
+ lf.lfWidth = lf.lfEscapement = lf.lfOrientation = 0;
+ lf.lfWeight = isBold() ? FW_BOLD : FW_NORMAL;
+ lf.lfItalic = isItalic() ? 1 : 0;
+ lf.lfUnderline = isUnderline() ? 1 : 0;
+ lf.lfStrikeOut = isStrikeOut() ? 1 : 0;
+ lf.lfCharSet = DEFAULT_CHARSET;
+ lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
+ lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
+ lf.lfQuality = DEFAULT_QUALITY;
+ lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
+
+ HDC hdc = GetDC(NULL);
+ lf.lfHeight = -MulDiv(getSize(), GetDeviceCaps(hdc, LOGPIXELSY), 72);
+ ReleaseDC(NULL, hdc);
+
+ hFont = CreateFontIndirect(&lf);
+ externalFont = false;
+}
+
+void FontState::releaseHFONT()
+{
+ if (hFont == NULL)
+ return;
+
+ if (!externalFont)
+ DeleteObject(hFont);
+
+ hFont = NULL;
+}
+
+
+HFONT FontState::getHFONT() const
+{
+ return hFont;
+}
+
+
+HFONT FontState::createHFONT() const
+{
+ LOGFONT lf;
+ if (hFont == NULL || GetObject(hFont, sizeof(lf), &lf) == 0)
+ return NULL;
+ else
+ return CreateFontIndirect(&lf);
+}
+
+void FontState::setHFONT(HFONT hFont)
+{
+ releaseHFONT();
+ this->hFont = hFont;
+ externalFont = true;
+ buildAttribs();
+}
+
+const TCHAR * FontState::getFace() const
+{
+ return face.c_str();
+}
+
+void FontState::setFace(const TCHAR * face)
+{
+ this->face = face;
+ rebuildHFONT();
+}
+
+int FontState::getSize() const
+{
+ return size;
+}
+
+void FontState::setSize(int size)
+{
+ this->size = size;
+ rebuildHFONT();
+}
+
+COLORREF FontState::getColor() const
+{
+ return color;
+}
+
+void FontState::setColor(COLORREF color)
+{
+ this->color = color;
+}
+
+bool FontState::isItalic() const
+{
+ return italic;
+}
+
+void FontState::setItalic(bool italic)
+{
+ this->italic = italic;
+ rebuildHFONT();
+}
+
+bool FontState::isBold() const
+{
+ return bold;
+}
+
+void FontState::setBold(bool bold)
+{
+ this->bold = bold;
+ rebuildHFONT();
+}
+
+bool FontState::isUnderline() const
+{
+ return underline;
+}
+
+void FontState::setUnderline(bool underline)
+{
+ this->underline = underline;
+ rebuildHFONT();
+}
+
+bool FontState::isStrikeOut() const
+{
+ return strikeout;
+}
+
+void FontState::setStrikeOut(bool strikeout)
+{
+ this->strikeout = strikeout;
+ rebuildHFONT();
+}
diff --git a/plugins/Skins/SkinLib/FontState.h b/plugins/Skins/SkinLib/FontState.h new file mode 100644 index 0000000000..de32bcdfb3 --- /dev/null +++ b/plugins/Skins/SkinLib/FontState.h @@ -0,0 +1,57 @@ +#ifndef __FONT_STATE_H__
+# define __FONT_STATE_H__
+
+#include "Field.h"
+
+
+class FontState
+{
+public:
+ FontState(HFONT hFont, COLORREF aColor);
+ ~FontState();
+
+ HFONT getHFONT() const;
+ void setHFONT(HFONT hFont);
+ HFONT createHFONT() const; /// Return a copy of the internal HFONT. The caller must free it
+
+ const TCHAR * getFace() const;
+ void setFace(const TCHAR * face);
+
+ int getSize() const;
+ void setSize(int size);
+
+ COLORREF getColor() const;
+ void setColor(COLORREF color);
+
+ bool isItalic() const;
+ void setItalic(bool italic);
+
+ bool isBold() const;
+ void setBold(bool bold);
+
+ bool isUnderline() const;
+ void setUnderline(bool underline);
+
+ bool isStrikeOut() const;
+ void setStrikeOut(bool strikeout);
+
+private:
+ COLORREF color;
+ HFONT hFont;
+ bool externalFont;
+ std::tstring face;
+ int size;
+ bool italic;
+ bool bold;
+ bool underline;
+ bool strikeout;
+
+ void rebuildHFONT();
+ void buildHFONT();
+ void releaseHFONT();
+ void buildAttribs();
+};
+
+
+
+#endif // __FONT_STATE_H__
diff --git a/plugins/Skins/SkinLib/FontState_v8_wrapper.cpp b/plugins/Skins/SkinLib/FontState_v8_wrapper.cpp new file mode 100644 index 0000000000..5226736b24 --- /dev/null +++ b/plugins/Skins/SkinLib/FontState_v8_wrapper.cpp @@ -0,0 +1,269 @@ +#include "globals.h"
+#include "FontState_v8_wrapper.h"
+#include <v8.h>
+#include "FontState.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_FontState_face(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( String::New((const V8_TCHAR *) tmp->getFace()) );
+}
+
+static void Set_FontState_face(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsString())
+ {
+ String::Utf8Value utf8_value(value);
+ tmp->setFace(Utf8ToTchar(*utf8_value));
+ }
+}
+
+
+static Handle<Value> Get_FontState_size(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getSize()) );
+}
+
+static void Set_FontState_size(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setSize(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FontState_italic(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Boolean::New(tmp->isItalic()) );
+}
+
+static void Set_FontState_italic(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsBoolean())
+ tmp->setItalic(value->BooleanValue());
+}
+
+
+static Handle<Value> Get_FontState_bold(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Boolean::New(tmp->isBold()) );
+}
+
+static void Set_FontState_bold(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsBoolean())
+ tmp->setBold(value->BooleanValue());
+}
+
+
+static Handle<Value> Get_FontState_underline(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Boolean::New(tmp->isUnderline()) );
+}
+
+static void Set_FontState_underline(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsBoolean())
+ tmp->setUnderline(value->BooleanValue());
+}
+
+
+static Handle<Value> Get_FontState_strikeOut(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Boolean::New(tmp->isStrikeOut()) );
+}
+
+static void Set_FontState_strikeOut(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsBoolean())
+ tmp->setStrikeOut(value->BooleanValue());
+}
+
+
+static Handle<Value> Get_FontState_color(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getColor()) );
+}
+
+static void Set_FontState_color(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ FontState *tmp = (FontState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setColor(value->Int32Value());
+}
+
+
+void AddFontStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->SetAccessor(String::New("face"), Get_FontState_face, Set_FontState_face);
+ templ->SetAccessor(String::New("size"), Get_FontState_size, Set_FontState_size);
+ templ->SetAccessor(String::New("italic"), Get_FontState_italic, Set_FontState_italic);
+ templ->SetAccessor(String::New("bold"), Get_FontState_bold, Set_FontState_bold);
+ templ->SetAccessor(String::New("underline"), Get_FontState_underline, Set_FontState_underline);
+ templ->SetAccessor(String::New("strikeOut"), Get_FontState_strikeOut, Set_FontState_strikeOut);
+ templ->SetAccessor(String::New("color"), Get_FontState_color, Set_FontState_color);
+}
diff --git a/plugins/Skins/SkinLib/FontState_v8_wrapper.h b/plugins/Skins/SkinLib/FontState_v8_wrapper.h new file mode 100644 index 0000000000..4b0483ffd9 --- /dev/null +++ b/plugins/Skins/SkinLib/FontState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __FONT_STATE_V8_WRAPPER_H__
+# define __FONT_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddFontStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __FONT_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/IconField.cpp b/plugins/Skins/SkinLib/IconField.cpp new file mode 100644 index 0000000000..4cf1aaf532 --- /dev/null +++ b/plugins/Skins/SkinLib/IconField.cpp @@ -0,0 +1,38 @@ +#include "globals.h"
+#include "IconField.h"
+#include "IconFieldState.h"
+
+
+IconField::IconField(Dialog *dlg, const char *name)
+ : Field(dlg, name), hIcon(NULL)
+{
+
+}
+
+IconField::~IconField()
+{
+}
+
+FieldType IconField::getType() const
+{
+ return SIMPLE_ICON;
+}
+
+HICON IconField::getIcon() const
+{
+ return hIcon;
+}
+
+void IconField::setIcon(HICON hIcon)
+{
+ if (this->hIcon == hIcon)
+ return;
+
+ this->hIcon = hIcon;
+ fireOnChange();
+}
+
+FieldState * IconField::createState(DialogState *dialogState)
+{
+ return new IconFieldState(dialogState, this);
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/IconField.h b/plugins/Skins/SkinLib/IconField.h new file mode 100644 index 0000000000..984b36b984 --- /dev/null +++ b/plugins/Skins/SkinLib/IconField.h @@ -0,0 +1,27 @@ +#ifndef __ICON_FIELD_H__
+# define __ICON_FIELD_H__
+
+#include "Field.h"
+
+
+class IconField : public Field
+{
+public:
+ IconField(Dialog *dlg, const char *name);
+ virtual ~IconField();
+
+ virtual FieldType getType() const;
+
+ virtual HICON getIcon() const;
+ virtual void setIcon(HICON hIcon);
+
+ virtual FieldState * createState(DialogState *dialogState);
+
+private:
+ HICON hIcon;
+
+};
+
+
+
+#endif // __ICON_FIELD_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/IconFieldState.cpp b/plugins/Skins/SkinLib/IconFieldState.cpp new file mode 100644 index 0000000000..fad1d67084 --- /dev/null +++ b/plugins/Skins/SkinLib/IconFieldState.cpp @@ -0,0 +1,37 @@ +#include "globals.h"
+#include "IconFieldState.h"
+
+#define ICON_SIZE 16
+
+
+IconFieldState::IconFieldState(DialogState *dialog, IconField *field)
+ : FieldState(dialog, field)
+{
+}
+
+IconFieldState::~IconFieldState()
+{
+}
+
+IconField * IconFieldState::getField() const
+{
+ return (IconField *) FieldState::getField();
+}
+
+Size IconFieldState::getPreferedSize() const
+{
+ if (getIcon() == NULL)
+ return Size(0, 0);
+
+ return Size(ICON_SIZE, ICON_SIZE);
+}
+
+HICON IconFieldState::getIcon() const
+{
+ return getField()->getIcon();
+}
+
+bool IconFieldState::isEmpty() const
+{
+ return getIcon() == NULL;
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/IconFieldState.h b/plugins/Skins/SkinLib/IconFieldState.h new file mode 100644 index 0000000000..b69e3fe01f --- /dev/null +++ b/plugins/Skins/SkinLib/IconFieldState.h @@ -0,0 +1,28 @@ +#ifndef __ICON_FIELD_STATE_H__
+# define __ICON_FIELD_STATE_H__
+
+#include "IconField.h"
+#include "FieldState.h"
+
+
+class IconFieldState : public FieldState
+{
+public:
+ virtual ~IconFieldState();
+
+ virtual IconField * getField() const;
+
+ virtual Size getPreferedSize() const;
+
+ virtual HICON getIcon() const;
+
+ virtual bool isEmpty() const;
+
+private:
+ IconFieldState(DialogState *dialog, IconField *field);
+
+ friend class IconField;
+};
+
+
+#endif // __ICON_FIELD_STATE_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/IconFieldState_v8_wrapper.cpp b/plugins/Skins/SkinLib/IconFieldState_v8_wrapper.cpp new file mode 100644 index 0000000000..a955653652 --- /dev/null +++ b/plugins/Skins/SkinLib/IconFieldState_v8_wrapper.cpp @@ -0,0 +1,20 @@ +#include "globals.h"
+#include "IconFieldState_v8_wrapper.h"
+#include <v8.h>
+#include "IconFieldState.h"
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+void AddIconFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+}
diff --git a/plugins/Skins/SkinLib/IconFieldState_v8_wrapper.h b/plugins/Skins/SkinLib/IconFieldState_v8_wrapper.h new file mode 100644 index 0000000000..7b63f801bc --- /dev/null +++ b/plugins/Skins/SkinLib/IconFieldState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __ICON_FIELD_STATE_V8_WRAPPER_H__
+# define __ICON_FIELD_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddIconFieldStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __ICON_FIELD_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/ImageField.cpp b/plugins/Skins/SkinLib/ImageField.cpp new file mode 100644 index 0000000000..c65cf99a0f --- /dev/null +++ b/plugins/Skins/SkinLib/ImageField.cpp @@ -0,0 +1,38 @@ +#include "globals.h"
+#include "ImageField.h"
+#include "ImageFieldState.h"
+
+
+ImageField::ImageField(Dialog *dlg, const char *name)
+ : Field(dlg, name), hBmp(NULL)
+{
+
+}
+
+ImageField::~ImageField()
+{
+}
+
+FieldType ImageField::getType() const
+{
+ return SIMPLE_IMAGE;
+}
+
+HBITMAP ImageField::getImage() const
+{
+ return hBmp;
+}
+
+void ImageField::setImage(HBITMAP hBmp)
+{
+ if (this->hBmp == hBmp)
+ return;
+
+ this->hBmp = hBmp;
+ fireOnChange();
+}
+
+FieldState * ImageField::createState(DialogState *dialogState)
+{
+ return new ImageFieldState(dialogState, this);
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/ImageField.h b/plugins/Skins/SkinLib/ImageField.h new file mode 100644 index 0000000000..e2f08665ca --- /dev/null +++ b/plugins/Skins/SkinLib/ImageField.h @@ -0,0 +1,26 @@ +#ifndef __IMAGE_FIELD_H__
+# define __IMAGE_FIELD_H__
+
+#include "Field.h"
+
+class ImageField : public Field
+{
+public:
+ ImageField(Dialog *dlg, const char *name);
+ virtual ~ImageField();
+
+ virtual FieldType getType() const;
+
+ virtual HBITMAP getImage() const;
+ virtual void setImage(HBITMAP hBmp);
+
+ virtual FieldState * createState(DialogState *dialogState);
+
+private:
+ HBITMAP hBmp;
+
+};
+
+
+
+#endif // __IMAGE_FIELD_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/ImageFieldState.cpp b/plugins/Skins/SkinLib/ImageFieldState.cpp new file mode 100644 index 0000000000..f74d77e0f3 --- /dev/null +++ b/plugins/Skins/SkinLib/ImageFieldState.cpp @@ -0,0 +1,37 @@ +#include "globals.h"
+#include "ImageFieldState.h"
+
+
+ImageFieldState::ImageFieldState(DialogState *dialog, ImageField *field)
+ : FieldState(dialog, field)
+{
+}
+
+ImageFieldState::~ImageFieldState()
+{
+}
+
+ImageField * ImageFieldState::getField() const
+{
+ return (ImageField *) FieldState::getField();
+}
+
+Size ImageFieldState::getPreferedSize() const
+{
+ HBITMAP hBmp = getImage();
+ BITMAP bmp;
+ if (hBmp == NULL || GetObject(hBmp, sizeof(bmp), &bmp) == 0)
+ return Size(0, 0);
+
+ return Size(bmp.bmWidth, bmp.bmHeight);
+}
+
+HBITMAP ImageFieldState::getImage() const
+{
+ return getField()->getImage();
+}
+
+bool ImageFieldState::isEmpty() const
+{
+ return getImage() == NULL;
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/ImageFieldState.h b/plugins/Skins/SkinLib/ImageFieldState.h new file mode 100644 index 0000000000..493c4db16d --- /dev/null +++ b/plugins/Skins/SkinLib/ImageFieldState.h @@ -0,0 +1,28 @@ +#ifndef __IMAGE_FIELD_STATE_H__
+# define __IMAGE_FIELD_STATE_H__
+
+#include "ImageField.h"
+#include "FieldState.h"
+
+
+class ImageFieldState : public FieldState
+{
+public:
+ virtual ~ImageFieldState();
+
+ virtual ImageField * getField() const;
+
+ virtual Size getPreferedSize() const;
+
+ virtual HBITMAP getImage() const;
+
+ virtual bool isEmpty() const;
+
+private:
+ ImageFieldState(DialogState *dialog, ImageField *field);
+
+ friend class ImageField;
+};
+
+
+#endif // __IMAGE_FIELD_STATE_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/ImageFieldState_v8_wrapper.cpp b/plugins/Skins/SkinLib/ImageFieldState_v8_wrapper.cpp new file mode 100644 index 0000000000..1e4a9b6a54 --- /dev/null +++ b/plugins/Skins/SkinLib/ImageFieldState_v8_wrapper.cpp @@ -0,0 +1,20 @@ +#include "globals.h"
+#include "ImageFieldState_v8_wrapper.h"
+#include <v8.h>
+#include "ImageFieldState.h"
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+void AddImageFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+}
diff --git a/plugins/Skins/SkinLib/ImageFieldState_v8_wrapper.h b/plugins/Skins/SkinLib/ImageFieldState_v8_wrapper.h new file mode 100644 index 0000000000..ea5f343e03 --- /dev/null +++ b/plugins/Skins/SkinLib/ImageFieldState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __IMAGE_FIELD_STATE_V8_WRAPPER_H__
+# define __IMAGE_FIELD_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddImageFieldStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __IMAGE_FIELD_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/LabelField.cpp b/plugins/Skins/SkinLib/LabelField.cpp new file mode 100644 index 0000000000..154ae2fce5 --- /dev/null +++ b/plugins/Skins/SkinLib/LabelField.cpp @@ -0,0 +1,23 @@ +#include "globals.h"
+#include "LabelField.h"
+#include "LabelFieldState.h"
+
+
+LabelField::LabelField(Dialog *dlg, const char *name, HWND hwnd)
+ : ControlField(dlg, name, hwnd)
+{
+}
+
+LabelField::~LabelField()
+{
+}
+
+FieldType LabelField::getType() const
+{
+ return CONTROL_LABEL;
+}
+
+FieldState * LabelField::createState(DialogState *dialogState)
+{
+ return new LabelFieldState(dialogState, this);
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/LabelField.h b/plugins/Skins/SkinLib/LabelField.h new file mode 100644 index 0000000000..8c4cb04a03 --- /dev/null +++ b/plugins/Skins/SkinLib/LabelField.h @@ -0,0 +1,20 @@ +#ifndef __LABEL_FIELD_H__
+# define __LABEL_FIELD_H__
+
+#include "ControlField.h"
+
+
+class LabelField : public ControlField
+{
+public:
+ LabelField(Dialog *dlg, const char *name, HWND hwnd);
+ virtual ~LabelField();
+
+ virtual FieldType getType() const;
+
+ virtual FieldState * createState(DialogState *dialogState);
+};
+
+
+
+#endif // __LABEL_FIELD_H__
diff --git a/plugins/Skins/SkinLib/LabelFieldState.cpp b/plugins/Skins/SkinLib/LabelFieldState.cpp new file mode 100644 index 0000000000..364611fbf7 --- /dev/null +++ b/plugins/Skins/SkinLib/LabelFieldState.cpp @@ -0,0 +1,35 @@ +#include "globals.h"
+#include "LabelFieldState.h"
+
+
+LabelFieldState::LabelFieldState(DialogState *dialog, LabelField *field)
+ : ControlFieldState(dialog, field)
+{
+}
+
+LabelFieldState::~LabelFieldState()
+{
+}
+
+Size LabelFieldState::getPreferedSize() const
+{
+ int style = GetWindowLong(getField()->getHWND(), GWL_STYLE);
+
+ int format = DT_EXPANDTABS | DT_EDITCONTROL;
+ if ((style & SS_LEFTNOWORDWRAP) || (style & SS_SIMPLE))
+ format |= DT_SINGLELINE;
+ if (style & SS_NOPREFIX)
+ format |= DT_NOPREFIX;
+ Size ret = getTextPreferedSize(format);
+
+ int border = getField()->getBorderSize();
+ ret.x += 2 * border;
+ ret.y += 2 * border;
+
+ return ret;
+}
+
+bool LabelFieldState::isEmpty() const
+{
+ return lstrlen(getText()) <= 0;
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/LabelFieldState.h b/plugins/Skins/SkinLib/LabelFieldState.h new file mode 100644 index 0000000000..dbbb3b04d3 --- /dev/null +++ b/plugins/Skins/SkinLib/LabelFieldState.h @@ -0,0 +1,25 @@ +#ifndef __LABEL_FIELD_STATE_H__
+# define __LABEL_FIELD_STATE_H__
+
+#include "ControlFieldState.h"
+#include "LabelField.h"
+
+
+class LabelFieldState : public ControlFieldState
+{
+public:
+ virtual ~LabelFieldState();
+
+ virtual Size getPreferedSize() const;
+
+ virtual bool isEmpty() const;
+
+private:
+ LabelFieldState(DialogState *dialog, LabelField *field);
+
+ friend class LabelField;
+};
+
+
+
+#endif // __LABEL_FIELD_STATE_H__
diff --git a/plugins/Skins/SkinLib/LabelFieldState_v8_wrapper.cpp b/plugins/Skins/SkinLib/LabelFieldState_v8_wrapper.cpp new file mode 100644 index 0000000000..9105a7d878 --- /dev/null +++ b/plugins/Skins/SkinLib/LabelFieldState_v8_wrapper.cpp @@ -0,0 +1,20 @@ +#include "globals.h"
+#include "LabelFieldState_v8_wrapper.h"
+#include <v8.h>
+#include "LabelFieldState.h"
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+void AddLabelFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+}
diff --git a/plugins/Skins/SkinLib/LabelFieldState_v8_wrapper.h b/plugins/Skins/SkinLib/LabelFieldState_v8_wrapper.h new file mode 100644 index 0000000000..7d40de5bc2 --- /dev/null +++ b/plugins/Skins/SkinLib/LabelFieldState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __LABEL_FIELD_STATE_V8_WRAPPER_H__
+# define __LABEL_FIELD_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddLabelFieldStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __LABEL_FIELD_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/Position.cpp b/plugins/Skins/SkinLib/Position.cpp new file mode 100644 index 0000000000..6c68881fce --- /dev/null +++ b/plugins/Skins/SkinLib/Position.cpp @@ -0,0 +1,9 @@ +#include "Position.h"
+
+Position::Position() : x(0), y(0)
+{
+}
+
+Position::Position(int aX, int aY) : x(aX), y(aY)
+{
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/Position.h b/plugins/Skins/SkinLib/Position.h new file mode 100644 index 0000000000..ed43a1ece3 --- /dev/null +++ b/plugins/Skins/SkinLib/Position.h @@ -0,0 +1,16 @@ +#ifndef __POSITION_H__
+# define __POSITION_H__
+
+
+struct Position
+{
+ int x;
+ int y;
+
+ Position();
+ Position(int x, int y);
+};
+
+
+
+#endif // __POSITION_H__
diff --git a/plugins/Skins/SkinLib/Size.cpp b/plugins/Skins/SkinLib/Size.cpp new file mode 100644 index 0000000000..9c2eef5d5d --- /dev/null +++ b/plugins/Skins/SkinLib/Size.cpp @@ -0,0 +1,84 @@ +#include "globals.h"
+#include "Size.h"
+
+Size::Size() : x(0), y(0)
+{
+}
+
+Size::Size(int aX, int aY) : x(aX), y(aY)
+{
+
+}
+
+int Size::resizeTo(int newX, int newY)
+{
+ if (newX < 0 && newY < 0)
+ return -1;
+
+ if (newY < 0)
+ {
+ if (x < 0 || y < 0)
+ return -2;
+
+ y = (int) (y * (newX / (float) x));
+ x = newX;
+ }
+ else if (newX < 0)
+ {
+ if (x < 0 || y < 0)
+ return -2;
+
+ x = (int) (x * (newY / (float) y));
+ y = newY;
+ }
+ else
+ {
+ x = newX;
+ y = newY;
+ }
+ return 0;
+}
+
+int Size::fitInside(int maxSize)
+{
+ if (x < 0 || y < 0)
+ return -2;
+ if (x <= maxSize && y <= maxSize)
+ return 0;
+
+ if (x >= y)
+ {
+ y = (int) (y * (maxSize / (float) x));
+ x = maxSize;
+ }
+ else
+ {
+ x = (int) (x * (maxSize / (float) y));
+ y = maxSize;
+ }
+ return 0;
+}
+
+int Size::scaleTo(int size)
+{
+ if (x < 0 || y < 0)
+ return -2;
+
+ if (x >= y)
+ {
+ y = (int) (y * (size / (float) x));
+ x = size;
+ }
+ else
+ {
+ x = (int) (x * (size / (float) y));
+ y = size;
+ }
+
+ return 0;
+}
+
+bool Size::operator==(const Size &other) const
+{
+ return x == other.x && y == other.y;
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/Size.h b/plugins/Skins/SkinLib/Size.h new file mode 100644 index 0000000000..8c0a297aee --- /dev/null +++ b/plugins/Skins/SkinLib/Size.h @@ -0,0 +1,27 @@ +#ifndef __SIZE_H__
+# define __SIZE_H__
+
+
+struct Size
+{
+ int x;
+ int y;
+
+ Size();
+ Size(int aX, int aY);
+
+ /// @return 0 on success
+ int resizeTo(int x, int y);
+
+ /// @return 0 on success
+ int fitInside(int maxSize);
+
+ /// @return 0 on success
+ int scaleTo(int size);
+
+ bool operator==(const Size &other) const;
+};
+
+
+
+#endif // __SIZE_H__
diff --git a/plugins/Skins/SkinLib/SkinOption.h b/plugins/Skins/SkinLib/SkinOption.h new file mode 100644 index 0000000000..7812303327 --- /dev/null +++ b/plugins/Skins/SkinLib/SkinOption.h @@ -0,0 +1 @@ +#include "SkinOptions.h"
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/SkinOption_v8_wrapper.cpp b/plugins/Skins/SkinLib/SkinOption_v8_wrapper.cpp new file mode 100644 index 0000000000..11a401ad2e --- /dev/null +++ b/plugins/Skins/SkinLib/SkinOption_v8_wrapper.cpp @@ -0,0 +1,179 @@ +#include "globals.h"
+#include "SkinOption_v8_wrapper.h"
+#include <v8.h>
+#include "SkinOption.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_SkinOption_description(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( String::New((const V8_TCHAR *) tmp->getDescription()) );
+}
+
+static void Set_SkinOption_description(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsString())
+ {
+ String::Utf8Value utf8_value(value);
+ tmp->setDescription(Utf8ToTchar(*utf8_value));
+ }
+}
+
+
+static Handle<Value> Get_SkinOption_min(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getMin()) );
+}
+
+static void Set_SkinOption_min(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setMin(value->Int32Value());
+}
+
+
+static Handle<Value> Get_SkinOption_max(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( Int32::New(tmp->getMax()) );
+}
+
+static void Set_SkinOption_max(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsNumber())
+ tmp->setMax(value->Int32Value());
+}
+
+
+static Handle<Value> Get_SkinOption_type(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ switch(tmp->getType())
+ {
+ case CHECKBOX: return scope.Close( String::New((const V8_TCHAR *) _T("CHECKBOX")) );
+ case NUMBER: return scope.Close( String::New((const V8_TCHAR *) _T("NUMBER")) );
+ case TEXT: return scope.Close( String::New((const V8_TCHAR *) _T("TEXT")) );
+ }
+ return scope.Close( Undefined() );
+}
+
+static void Set_SkinOption_type(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsString())
+ {
+ String::Utf8Value utf8_value(value);
+ Utf8ToTchar tval(*utf8_value);
+ if ( lstrcmpi(_T("CHECKBOX"), tval) == 0 )
+ tmp->setType(CHECKBOX);
+ else if ( lstrcmpi(_T("NUMBER"), tval) == 0 )
+ tmp->setType(NUMBER);
+ else if ( lstrcmpi(_T("TEXT"), tval) == 0 )
+ tmp->setType(TEXT);
+ }
+}
+
+
+void AddSkinOptionAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->SetAccessor(String::New("description"), Get_SkinOption_description, Set_SkinOption_description);
+ templ->SetAccessor(String::New("min"), Get_SkinOption_min, Set_SkinOption_min);
+ templ->SetAccessor(String::New("max"), Get_SkinOption_max, Set_SkinOption_max);
+ templ->SetAccessor(String::New("type"), Get_SkinOption_type, Set_SkinOption_type);
+}
diff --git a/plugins/Skins/SkinLib/SkinOption_v8_wrapper.h b/plugins/Skins/SkinLib/SkinOption_v8_wrapper.h new file mode 100644 index 0000000000..6aa05c2122 --- /dev/null +++ b/plugins/Skins/SkinLib/SkinOption_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __SKIN_OPTION_V8_WRAPPER_H__
+# define __SKIN_OPTION_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddSkinOptionAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __SKIN_OPTION_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/SkinOptions.cpp b/plugins/Skins/SkinLib/SkinOptions.cpp new file mode 100644 index 0000000000..51fb96cbdb --- /dev/null +++ b/plugins/Skins/SkinLib/SkinOptions.cpp @@ -0,0 +1,216 @@ +#include "globals.h"
+#include "SkinOptions.h"
+#include <utf8_helpers.h>
+
+
+SkinOption::SkinOption(const char *aName)
+ : name(aName), type(CHECKBOX), valueCheckbox(false), valueNumber(0),
+ onChangeCallback(NULL), onChangeCallbackParam(NULL),
+ minValue(MININT), maxValue(MAXINT)
+{
+ description = Utf8ToTchar(aName);
+}
+
+SkinOption::~SkinOption()
+{
+}
+
+const char * SkinOption::getName() const
+{
+ return name.c_str();
+}
+
+SkinOptionType SkinOption::getType() const
+{
+ return type;
+}
+
+void SkinOption::setType(SkinOptionType type)
+{
+ if (this->type == type)
+ return;
+
+ this->type = type;
+ fireOnChange();
+}
+
+const TCHAR * SkinOption::getDescription() const
+{
+ return description.c_str();
+}
+
+void SkinOption::setDescription(const TCHAR * description)
+{
+ if (this->description == description)
+ return;
+
+ this->description = description;
+ fireOnChange();
+}
+
+int SkinOption::getMax() const
+{
+ return maxValue;
+}
+
+void SkinOption::setMax(int max)
+{
+ this->maxValue = max;
+ setValueNumber(valueNumber);
+}
+
+int SkinOption::getMin() const
+{
+ return minValue;
+}
+
+void SkinOption::setMin(int min)
+{
+ this->minValue = min;
+ setValueNumber(valueNumber);
+}
+
+bool SkinOption::getValueCheckbox() const
+{
+ return valueCheckbox;
+}
+
+void SkinOption::setValueCheckbox(bool value)
+{
+ if (valueCheckbox == value)
+ return;
+
+ valueCheckbox = value;
+ fireOnChange();
+}
+
+int SkinOption::getValueNumber() const
+{
+ return max(minValue, min(maxValue, valueNumber));
+}
+
+void SkinOption::setValueNumber(int value)
+{
+ value = max(minValue, min(maxValue, value));
+
+ if (value == valueNumber)
+ return;
+
+ valueNumber = value;
+ fireOnChange();
+}
+
+const TCHAR * SkinOption::getValueText() const
+{
+ return valueText.c_str();
+}
+
+void SkinOption::setValueText(const TCHAR * value)
+{
+ if (valueText == value)
+ return;
+
+ valueText = value;
+ fireOnChange();
+}
+
+void SkinOption::setOnChangeCallback(SkinOptionCallback cb, void *param /*= NULL*/)
+{
+ onChangeCallback = cb;
+ onChangeCallbackParam = param;
+}
+
+void SkinOption::fireOnChange()
+{
+ if (onChangeCallback != NULL)
+ onChangeCallback(onChangeCallbackParam, this);
+}
+
+
+
+SkinOptions::SkinOptions()
+ : onAddRemoveCallback(NULL), onAddRemoveCallbackParam(NULL),
+ onChangeCallback(NULL), onChangeCallbackParam(NULL)
+{
+}
+
+SkinOptions::~SkinOptions()
+{
+ for(unsigned int i = 0; i < options.size(); i++)
+ delete options[i];
+ options.clear();
+}
+
+bool SkinOptions::addOption(SkinOption *opt)
+{
+ _ASSERT(opt != NULL);
+ _ASSERT(opt->getName() != NULL);
+
+ if (getOption(opt->getName()) != NULL)
+ return false;
+
+ opt->setOnChangeCallback(onChangeCallback, onChangeCallbackParam);
+ options.push_back(opt);
+
+ fireOnAddRemove(opt);
+ return true;
+}
+
+SkinOption * SkinOptions::getOption(const char *name) const
+{
+ _ASSERT(name != NULL);
+
+ for(unsigned int i = 0; i < options.size(); i++)
+ {
+ SkinOption *opt = options[i];
+ if (strcmp(opt->getName(), name) == 0)
+ return opt;
+ }
+ return NULL;
+}
+
+SkinOption * SkinOptions::getOption(unsigned int pos) const
+{
+ if (pos >= options.size())
+ return NULL;
+ return options[pos];
+}
+
+unsigned int SkinOptions::getNumOptions() const
+{
+ return options.size();
+}
+
+void SkinOptions::clearOptions()
+{
+ if (options.size() <= 0)
+ return;
+
+ for(unsigned int i = 0; i < options.size(); i++)
+ {
+ fireOnAddRemove(options[i]);
+ delete options[i];
+ }
+ options.clear();
+}
+
+void SkinOptions::setOnOptionAddRemoveCallback(SkinOptionCallback cb, void *param /*= NULL*/)
+{
+ onAddRemoveCallback = cb;
+ onAddRemoveCallbackParam = param;
+}
+
+void SkinOptions::setOnOptionChangeCallback(SkinOptionCallback cb, void *param /*= NULL*/)
+{
+ onChangeCallback = cb;
+ onChangeCallbackParam = param;
+
+ for(unsigned int i = 0; i < options.size(); i++)
+ options[i]->setOnChangeCallback(cb, param);
+}
+
+void SkinOptions::fireOnAddRemove(SkinOption *opt)
+{
+ if (onAddRemoveCallback != NULL)
+ onAddRemoveCallback(onAddRemoveCallbackParam, opt);
+}
diff --git a/plugins/Skins/SkinLib/SkinOptions.h b/plugins/Skins/SkinLib/SkinOptions.h new file mode 100644 index 0000000000..41d238a5a1 --- /dev/null +++ b/plugins/Skins/SkinLib/SkinOptions.h @@ -0,0 +1,98 @@ +#ifndef __SKINNED_DIALOG_OPTIONS_H__
+# define __SKINNED_DIALOG_OPTIONS_H__
+
+#include <windows.h>
+#include "tstring.h"
+#include <vector>
+
+
+enum SkinOptionType
+{
+ CHECKBOX,
+ NUMBER,
+ TEXT
+};
+
+class SkinOption;
+
+typedef void (*SkinOptionCallback)(void *param, const SkinOption *opt);
+
+
+class SkinOption
+{
+public:
+ SkinOption(const char *name);
+ ~SkinOption();
+
+ const char * getName() const;
+
+ SkinOptionType getType() const;
+ void setType(SkinOptionType type);
+
+ const TCHAR * getDescription() const;
+ void setDescription(const TCHAR * description);
+
+ int getMax() const;
+ void setMax(int max);
+
+ int getMin() const;
+ void setMin(int min);
+
+ bool getValueCheckbox() const;
+ void setValueCheckbox(bool value);
+
+ int getValueNumber() const;
+ void setValueNumber(int value);
+
+ const TCHAR * getValueText() const;
+ void setValueText(const TCHAR * value);
+
+ void setOnChangeCallback(SkinOptionCallback cb, void *param = NULL);
+
+private:
+ std::string name;
+ SkinOptionType type;
+ std::tstring description;
+ bool valueCheckbox;
+ int valueNumber;
+ int minValue;
+ int maxValue;
+ std::tstring valueText;
+
+ SkinOptionCallback onChangeCallback;
+ void * onChangeCallbackParam;
+
+ void fireOnChange();
+};
+
+
+class SkinOptions
+{
+public:
+ SkinOptions();
+ ~SkinOptions();
+
+ bool addOption(SkinOption *opt);
+ SkinOption * getOption(const char *name) const;
+ SkinOption * getOption(unsigned int pos) const;
+ unsigned int getNumOptions() const;
+ void clearOptions();
+
+ void setOnOptionAddRemoveCallback(SkinOptionCallback cb, void *param = NULL);
+ void setOnOptionChangeCallback(SkinOptionCallback cb, void *param = NULL);
+
+private:
+ std::vector<SkinOption *> options;
+
+ SkinOptionCallback onAddRemoveCallback;
+ void * onAddRemoveCallbackParam;
+
+ SkinOptionCallback onChangeCallback;
+ void * onChangeCallbackParam;
+
+ void fireOnAddRemove(SkinOption *opt);
+};
+
+
+
+#endif // __SKINNED_DIALOG_OPTIONS_H__
diff --git a/plugins/Skins/SkinLib/SkinnedDialog.cpp b/plugins/Skins/SkinLib/SkinnedDialog.cpp new file mode 100644 index 0000000000..917193ad94 --- /dev/null +++ b/plugins/Skins/SkinLib/SkinnedDialog.cpp @@ -0,0 +1,235 @@ +#include "globals.h"
+#include "SkinnedDialog.h"
+
+#include <sys/stat.h>
+#include "V8Script.h"
+#include <utf8_helpers.h>
+#include "SkinOptions.h"
+
+
+SkinnedDialog::SkinnedDialog(const char *name)
+ : Dialog(name), fileChangedTime(0),
+ script(NULL), state(NULL), opts(NULL), defaultState(NULL),
+ errorCallback(NULL), errorCallbackParam(NULL),
+ traceCallback(NULL), traceCallbackParam(NULL)
+{
+ V8Script::initializeEngine();
+}
+
+SkinnedDialog::~SkinnedDialog()
+{
+ releaseState();
+ releaseCompiledScript();
+}
+
+const TCHAR * SkinnedDialog::getFilename() const
+{
+ return filename.c_str();
+}
+
+void SkinnedDialog::setFilename(const TCHAR *filename)
+{
+ if (this->filename == filename)
+ return;
+
+ this->filename = filename;
+ releaseState();
+ releaseCompiledScript();
+}
+
+bool SkinnedDialog::addField(Field *field)
+{
+ if (Dialog::addField(field))
+ {
+ releaseCompiledScript();
+ releaseState();
+ field->setOnChangeCallback(SkinnedDialog::staticOnFieldChange, this);
+ return true;
+ }
+ else
+ return false;
+}
+
+void SkinnedDialog::setSize(const Size &size)
+{
+ if (getSize() == size)
+ return;
+
+ Dialog::setSize(size);
+ releaseState();
+}
+
+int SkinnedDialog::compile()
+{
+ if (!fileChanged())
+ return 1;
+
+ releaseCompiledScript();
+
+ struct _stat st = {0};
+ if (_tstat(filename.c_str(), &st) != 0)
+ return 0;
+
+ std::tstring text;
+ readFile(text);
+ if (text.size() <= 0)
+ return 0;
+
+ script = new V8Script();
+ script->setExceptionCallback(errorCallback, errorCallbackParam);
+
+ if (!script->compile(text.c_str(), this))
+ {
+ releaseCompiledScript();
+ return 0;
+ }
+
+ std::pair<SkinOptions *,DialogState *> pair = script->configure(this);
+ opts = pair.first;
+ defaultState = pair.second;
+ if (opts == NULL)
+ {
+ releaseCompiledScript();
+ return 0;
+ }
+
+ fileChangedTime = st.st_mtime;
+
+ return 2;
+}
+
+DialogState * SkinnedDialog::getState()
+{
+ if (state != NULL && !fileChanged())
+ return state;
+
+ releaseState();
+
+ if (filename.size() <= 0)
+ return NULL;
+
+ if (!compile())
+ return NULL;
+
+ state = Dialog::createState();
+ if (!script->run(state, opts, getInfo()))
+ {
+ releaseState();
+ return NULL;
+ }
+
+ return state;
+}
+
+void SkinnedDialog::releaseCompiledScript()
+{
+ delete script;
+ script = NULL;
+ fileChangedTime = 0;
+
+ delete opts;
+ opts = NULL;
+
+ delete defaultState;
+ defaultState = NULL;
+}
+
+void SkinnedDialog::releaseState()
+{
+ delete state;
+ state = NULL;
+}
+
+bool SkinnedDialog::fileChanged()
+{
+ if (filename.size() <= 0)
+ return false;
+
+ struct _stat st = {0};
+ if (_tstat(filename.c_str(), &st) != 0)
+ return false;
+
+ return st.st_mtime > fileChangedTime;
+}
+
+void SkinnedDialog::readFile(std::tstring &ret)
+{
+ FILE* file = _tfopen(filename.c_str(), _T("rb"));
+ if (file == NULL)
+ return;
+
+ fseek(file, 0, SEEK_END);
+ int size = ftell(file);
+ rewind(file);
+
+ char* chars = new char[size + 1];
+ chars[size] = '\0';
+ for (int i = 0; i < size;)
+ {
+ int read = fread(&chars[i], 1, size - i, file);
+ i += read;
+ }
+ fclose(file);
+
+ ret = Utf8ToTchar(chars);
+
+ delete[] chars;
+}
+
+void SkinnedDialog::onFieldChange(const Field *field)
+{
+ releaseState();
+}
+
+
+void SkinnedDialog::staticOnFieldChange(void *param, const Field *field)
+{
+ _ASSERT(param != NULL);
+ _ASSERT(field != NULL);
+
+ SkinnedDialog *skdlg = (SkinnedDialog *) param;
+ skdlg->onFieldChange(field);
+}
+
+void SkinnedDialog::setErrorCallback(MessageCallback cb, void *param /*= NULL*/)
+{
+ errorCallback = cb;
+ errorCallbackParam = param;
+}
+
+void SkinnedDialog::setTraceCallback(MessageCallback cb, void *param /*= NULL*/)
+{
+ traceCallback = cb;
+ traceCallbackParam = param;
+}
+
+void SkinnedDialog::trace(TCHAR *msg, ...)
+{
+ if (traceCallback == NULL)
+ return;
+
+ TCHAR buff[1024];
+ memset(buff, 0, sizeof(buff));
+
+ va_list args;
+ va_start(args, msg);
+
+ _vsntprintf(buff, MAX_REGS(buff) - 1, msg, args);
+ buff[MAX_REGS(buff) - 1] = 0;
+
+ va_end(args);
+
+ traceCallback(traceCallbackParam, buff);
+}
+
+SkinOptions * SkinnedDialog::getOpts()
+{
+ compile();
+ return opts;
+}
+
+DialogState * SkinnedDialog::getDefaultState()
+{
+ compile();
+ return defaultState;
+}
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/SkinnedDialog.h b/plugins/Skins/SkinLib/SkinnedDialog.h new file mode 100644 index 0000000000..1387082f44 --- /dev/null +++ b/plugins/Skins/SkinLib/SkinnedDialog.h @@ -0,0 +1,89 @@ +#ifndef __SKINNED_DIALOG_H__
+# define __SKINNED_DIALOG_H__
+
+#include <windows.h>
+#include <tchar.h>
+#include "tstring.h"
+
+#include "Dialog.h"
+#include "ButtonField.h"
+#include "EditField.h"
+#include "IconField.h"
+#include "ImageField.h"
+#include "LabelField.h"
+#include "TextField.h"
+
+#include "DialogState.h"
+#include "BorderState.h"
+#include "ButtonFieldState.h"
+#include "EditFieldState.h"
+#include "FontState.h"
+#include "IconFieldState.h"
+#include "ImageFieldState.h"
+#include "LabelFieldState.h"
+#include "TextFieldState.h"
+
+#include "SkinOptions.h"
+
+class V8Script;
+
+
+typedef void (*MessageCallback)(void *param, const TCHAR *err);
+
+
+
+class SkinnedDialog : public Dialog
+{
+public:
+ SkinnedDialog(const char *name);
+ virtual ~SkinnedDialog();
+
+ virtual const TCHAR * getFilename() const;
+ virtual void setFilename(const TCHAR *filename);
+
+ virtual bool addField(Field *field);
+
+ virtual void setSize(const Size &size);
+
+ /// Return the cached state. Do not free the result.
+ /// Each call to this method can potentially create the state, so don't cache it.
+ virtual DialogState * getState();
+
+ virtual void setErrorCallback(MessageCallback cb, void *param = NULL);
+ virtual void setTraceCallback(MessageCallback cb, void *param = NULL);
+
+ virtual SkinOptions * getOpts();
+ virtual DialogState * getDefaultState();
+
+protected:
+ virtual bool fileChanged();
+ virtual int compile(); /// @return 0 error, 1 no change, 2 compiled
+
+ virtual void trace(TCHAR *msg, ...);
+
+ virtual void onFieldChange(const Field *field);
+
+private:
+ std::tstring filename;
+ __time64_t fileChangedTime;
+ V8Script *script;
+ DialogState *state;
+ SkinOptions *opts;
+ DialogState *defaultState;
+
+ MessageCallback errorCallback;
+ void *errorCallbackParam;
+ MessageCallback traceCallback;
+ void *traceCallbackParam;
+
+ void releaseCompiledScript();
+ void releaseState();
+ void readFile(std::tstring &ret);
+
+ static void staticOnFieldChange(void *param, const Field *field);
+};
+
+
+
+
+#endif // __SKINNED_DIALOG_H__
diff --git a/plugins/Skins/SkinLib/TextField.cpp b/plugins/Skins/SkinLib/TextField.cpp new file mode 100644 index 0000000000..d3841b98fd --- /dev/null +++ b/plugins/Skins/SkinLib/TextField.cpp @@ -0,0 +1,78 @@ +#include "globals.h"
+#include "TextField.h"
+#include "TextFieldState.h"
+
+
+TextField::TextField(Dialog *dlg, const char *name)
+ : Field(dlg, name), hFont(NULL), fontColor(RGB(0,0,0))
+{
+}
+
+
+TextField::~TextField()
+{
+}
+
+
+FieldType TextField::getType() const
+{
+ return SIMPLE_TEXT;
+}
+
+
+void TextField::setText(const TCHAR *text)
+{
+ if (this->text == text)
+ return;
+
+ this->text = text;
+ fireOnChange();
+}
+
+
+const TCHAR * TextField::getText() const
+{
+ return text.c_str();
+}
+
+
+void TextField::setFont(HFONT hFont)
+{
+ if (this->hFont == hFont)
+ return;
+
+ this->hFont = hFont;
+ fireOnChange();
+}
+
+
+HFONT TextField::getFont() const
+{
+ if (hFont != NULL)
+ return hFont;
+
+ // The default is the GUI font
+ return (HFONT) GetStockObject(DEFAULT_GUI_FONT);
+}
+
+
+COLORREF TextField::getFontColor() const
+{
+ return fontColor;
+}
+
+
+void TextField::setFontColor(COLORREF color)
+{
+ if (fontColor == color)
+ return;
+
+ fontColor = color;
+ fireOnChange();
+}
+
+
+FieldState * TextField::createState(DialogState *dialogState)
+{
+ return new TextFieldState(dialogState, this);
+}
diff --git a/plugins/Skins/SkinLib/TextField.h b/plugins/Skins/SkinLib/TextField.h new file mode 100644 index 0000000000..8d2291f876 --- /dev/null +++ b/plugins/Skins/SkinLib/TextField.h @@ -0,0 +1,35 @@ +#ifndef __TEXT_FIELD_H__
+# define __TEXT_FIELD_H__
+
+#include "Field.h"
+
+
+class TextField : public Field
+{
+public:
+ TextField(Dialog *dlg, const char *name);
+ virtual ~TextField();
+
+ virtual FieldType getType() const;
+
+ virtual const TCHAR * getText() const;
+ virtual void setText(const TCHAR *text);
+
+ virtual HFONT getFont() const;
+ virtual void setFont(HFONT hFont);
+
+ virtual COLORREF getFontColor() const;
+ virtual void setFontColor(COLORREF color);
+
+ virtual FieldState * createState(DialogState *dialogState);
+
+private:
+ std::tstring text;
+ HFONT hFont;
+ COLORREF fontColor;
+
+};
+
+
+
+#endif // __TEXT_FIELD_H__
diff --git a/plugins/Skins/SkinLib/TextFieldState.cpp b/plugins/Skins/SkinLib/TextFieldState.cpp new file mode 100644 index 0000000000..8e295d01ee --- /dev/null +++ b/plugins/Skins/SkinLib/TextFieldState.cpp @@ -0,0 +1,65 @@ +#include "globals.h"
+#include "TextFieldState.h"
+
+
+TextFieldState::TextFieldState(DialogState *dialog, TextField *field)
+ : FieldState(dialog, field), font(field->getFont(), field->getFontColor()), textSet(false)
+{
+}
+
+TextFieldState::~TextFieldState()
+{
+}
+
+TextField * TextFieldState::getField() const
+{
+ return (TextField *) FieldState::getField();
+}
+
+
+Size TextFieldState::getPreferedSize() const
+{
+ HDC hdc = CreateCompatibleDC(NULL);
+
+ HFONT newFont = getFont()->getHFONT();
+ HFONT oldFont = (HFONT) SelectObject(hdc, newFont);
+
+ RECT rc = {0};
+ const TCHAR *text = getText();
+ DrawText(hdc, text, -1, &rc, DT_CALCRECT | DT_NOPREFIX | DT_EXPANDTABS | DT_SINGLELINE);
+
+ SelectObject(hdc, oldFont);
+
+ DeleteDC(hdc);
+
+ return Size(rc.right - rc.left, rc.bottom - rc.top);
+}
+
+const TCHAR * TextFieldState::getText() const
+{
+ if (textSet)
+ return text.c_str();
+
+ return getField()->getText();
+}
+
+void TextFieldState::setText(const TCHAR *text)
+{
+ this->text = text;
+ textSet = true;
+}
+
+FontState * TextFieldState::getFont()
+{
+ return &font;
+}
+
+const FontState * TextFieldState::getFont() const
+{
+ return &font;
+}
+
+bool TextFieldState::isEmpty() const
+{
+ return lstrlen(getText()) <= 0;
+}
diff --git a/plugins/Skins/SkinLib/TextFieldState.h b/plugins/Skins/SkinLib/TextFieldState.h new file mode 100644 index 0000000000..9779cfa569 --- /dev/null +++ b/plugins/Skins/SkinLib/TextFieldState.h @@ -0,0 +1,38 @@ +#ifndef __TEXT_FIELD_STATE_H__
+# define __TEXT_FIELD_STATE_H__
+
+#include "TextField.h"
+#include "FieldState.h"
+#include "FontState.h"
+
+
+class TextFieldState : public FieldState
+{
+public:
+ virtual ~TextFieldState();
+
+ virtual TextField * getField() const;
+
+ virtual Size getPreferedSize() const;
+
+ virtual const TCHAR * getText() const;
+ virtual void setText(const TCHAR *text);
+
+ virtual FontState * getFont();
+ virtual const FontState * getFont() const;
+
+ virtual bool isEmpty() const;
+
+private:
+ TextFieldState(DialogState *dialog, TextField *field);
+
+ FontState font;
+ BOOL textSet;
+ std::tstring text;
+
+
+ friend class TextField;
+};
+
+
+#endif // __TEXT_FIELD_STATE_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/TextFieldState_v8_wrapper.cpp b/plugins/Skins/SkinLib/TextFieldState_v8_wrapper.cpp new file mode 100644 index 0000000000..cf11fdb01f --- /dev/null +++ b/plugins/Skins/SkinLib/TextFieldState_v8_wrapper.cpp @@ -0,0 +1,59 @@ +#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)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ TextFieldState *tmp = (TextFieldState *) wrap->Value();
+ if (tmp == NULL)
+ return scope.Close( Undefined() );
+
+ return scope.Close( String::New((const V8_TCHAR *) tmp->getText()) );
+}
+
+static void Set_TextFieldState_text(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ TextFieldState *tmp = (TextFieldState *) wrap->Value();
+ if (tmp == NULL)
+ return;
+
+ if (!value.IsEmpty() && value->IsString())
+ {
+ String::Utf8Value utf8_value(value);
+ tmp->setText(Utf8ToTchar(*utf8_value));
+ }
+}
+
+
+void AddTextFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->SetAccessor(String::New("text"), Get_TextFieldState_text, Set_TextFieldState_text);
+}
diff --git a/plugins/Skins/SkinLib/TextFieldState_v8_wrapper.h b/plugins/Skins/SkinLib/TextFieldState_v8_wrapper.h new file mode 100644 index 0000000000..c5d9e48a80 --- /dev/null +++ b/plugins/Skins/SkinLib/TextFieldState_v8_wrapper.h @@ -0,0 +1,10 @@ +#ifndef __TEXT_FIELD_STATE_V8_WRAPPER_H__
+# define __TEXT_FIELD_STATE_V8_WRAPPER_H__
+
+#include <v8.h>
+
+void AddTextFieldStateAcessors(v8::Handle<v8::ObjectTemplate> &templ);
+
+
+
+#endif // __TEXT_FIELD_STATE_V8_WRAPPER_H__
diff --git a/plugins/Skins/SkinLib/V8Script.cpp b/plugins/Skins/SkinLib/V8Script.cpp new file mode 100644 index 0000000000..c7619187a5 --- /dev/null +++ b/plugins/Skins/SkinLib/V8Script.cpp @@ -0,0 +1,236 @@ +#include "globals.h"
+#include "V8Script.h"
+#include "V8Wrappers.h"
+
+#include <utf8_helpers.h>
+
+using namespace v8;
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+V8Wrappers *wrappers = NULL;
+
+
+void V8Script::initializeEngine()
+{
+ if (wrappers != NULL)
+ return;
+
+ wrappers = new V8Wrappers();
+}
+
+
+V8Script::V8Script() : exceptionCallback(NULL), exceptionCallbackParam(NULL)
+{
+}
+
+V8Script::~V8Script()
+{
+ dispose();
+}
+
+bool V8Script::compile(const TCHAR *source, Dialog *dlg)
+{
+ dispose();
+
+ HandleScope handle_scope;
+
+ context = Context::New(NULL, wrappers->getGlobalTemplate());
+
+ Context::Scope context_scope(context);
+
+ context->Global()->Set(String::New("window"), wrappers->newDialogState(), ReadOnly);
+ context->Global()->Set(String::New("opts"), wrappers->newOptions(), ReadOnly);
+ context->Global()->Set(String::New("info"), wrappers->newDialogInfo(), ReadOnly);
+ for(unsigned int i = 0; i < dlg->getFieldCount(); i++)
+ {
+ Field *field = dlg->getField(i);
+ context->Global()->Set(String::New(field->getName()), wrappers->newState(field->getType()), ReadOnly);
+ }
+
+ TryCatch try_catch;
+ Local<Script> script = Script::Compile(String::New((const V8_TCHAR *) source), String::New(dlg->getName()));
+ if (script.IsEmpty())
+ {
+ reportException(&try_catch);
+ dispose();
+ return false;
+ }
+
+ // Run once to get the functions
+ Handle<Value> result = script->Run();
+ if (script.IsEmpty())
+ {
+ reportException(&try_catch);
+ dispose();
+ return false;
+ }
+
+ Handle<Value> configureFunction = context->Global()->Get(String::New("configure"));
+ if (!configureFunction.IsEmpty() && !configureFunction->IsFunction())
+ configureFunction.Clear();
+
+ Handle<Value> drawFunction = context->Global()->Get(String::New("draw"));
+ if (drawFunction.IsEmpty() || !drawFunction->IsFunction())
+ {
+ dispose();
+ return false;
+ }
+
+ this->configureFunction = Persistent<Function>::New(Handle<Function>::Cast(configureFunction));
+ this->drawFunction = Persistent<Function>::New(Handle<Function>::Cast(drawFunction));
+
+ return true;
+}
+
+void V8Script::dispose()
+{
+ context.Dispose();
+ configureFunction.Dispose();
+ drawFunction.Dispose();
+
+ context.Clear();
+ configureFunction.Clear();
+ drawFunction.Clear();
+}
+
+bool V8Script::isValid()
+{
+ return !context.IsEmpty() && !drawFunction.IsEmpty();
+}
+
+static Handle<Object> get(Handle<Object> obj, const char *field)
+{
+ HandleScope scope;
+
+ Local<Value> v = obj->Get(String::New(field));
+ _ASSERT(!v.IsEmpty());
+ _ASSERT(!v->IsUndefined());
+ _ASSERT(v->IsObject());
+
+ return scope.Close( Handle<Object>::Cast(v) );
+}
+
+void V8Script::fillWrappers(DialogState *state, SkinOptions *opts, DialogInfo *info, bool configure)
+{
+ Local<Object> global = context->Global();
+ wrappers->fillOptions(get(global, "opts"), opts, configure);
+ wrappers->fillDialogState(get(global, "window"), state);
+ wrappers->fillDialogInfo(get(global, "info"), info);
+ for(unsigned int i = 0; i < state->fields.size(); i++)
+ {
+ FieldState *field = state->fields[i];
+ wrappers->fillState(get(global, field->getField()->getName()), field);
+ }
+}
+
+std::pair<SkinOptions *,DialogState *> V8Script::configure(Dialog *dlg)
+{
+ if (!isValid())
+ return std::pair<SkinOptions *,DialogState *>(NULL, NULL);
+
+ SkinOptions *opts = new SkinOptions();
+ DialogState *state = dlg->createState();
+
+ if (!configureFunction.IsEmpty())
+ {
+ HandleScope handle_scope;
+
+ Context::Scope context_scope(context);
+
+ fillWrappers(state, opts, dlg->getInfo(), true);
+
+ TryCatch try_catch;
+ Handle<Value> result = configureFunction->Call(context->Global(), 0, NULL);
+ if (result.IsEmpty())
+ {
+ reportException(&try_catch);
+ delete opts;
+ delete state;
+ return std::pair<SkinOptions *,DialogState *>(NULL, NULL);;
+ }
+ }
+
+ return std::pair<SkinOptions *,DialogState *>(opts, state);
+}
+
+bool V8Script::run(DialogState * state, SkinOptions *opts, DialogInfo *info)
+{
+ if (!isValid())
+ return false;
+
+ HandleScope handle_scope;
+
+ Context::Scope context_scope(context);
+
+ fillWrappers(state, opts, info, false);
+
+ TryCatch try_catch;
+ Handle<Value> result = drawFunction->Call(context->Global(), 0, NULL);
+ if (result.IsEmpty())
+ {
+ reportException(&try_catch);
+ return false;
+ }
+
+ return true;
+}
+
+void V8Script::setExceptionCallback(ExceptionCallback cb, void *param)
+{
+ exceptionCallback = cb;
+ exceptionCallbackParam = param;
+}
+
+void V8Script::reportException(v8::TryCatch *try_catch)
+{
+ std::string err;
+ char tmp[1024];
+
+ HandleScope handle_scope;
+ String::Utf8Value exception(try_catch->Exception());
+ Handle<Message> message = try_catch->Message();
+ if (message.IsEmpty())
+ {
+ // V8 didn't provide any extra information about this error; just
+ // print the exception.
+ _snprintf(tmp, 1024, "%s\n", *exception);
+ err += tmp;
+ }
+ else
+ {
+ // Print (filename):(line number): (message).
+ String::Utf8Value filename(message->GetScriptResourceName());
+ int linenum = message->GetLineNumber();
+ _snprintf(tmp, 1024, "%s:%i: %s\n", *filename, linenum, *exception);
+ err += tmp;
+
+ // Print line of source code.
+ String::Utf8Value sourceline(message->GetSourceLine());
+ _snprintf(tmp, 1024, "%s\n", *sourceline);
+ err += tmp;
+
+ // Print wavy underline (GetUnderline is deprecated).
+ int start = message->GetStartColumn();
+ for (int i = 0; i < start; i++) {
+ err += " ";
+ }
+ int end = message->GetEndColumn();
+ for (int i = start; i < end; i++) {
+ err += "^";
+ }
+ err += "\n";
+ }
+
+ Utf8ToTchar tcharErr(err.c_str());
+
+ OutputDebugString(tcharErr);
+
+ if (exceptionCallback != NULL)
+ exceptionCallback(exceptionCallbackParam, tcharErr);
+}
diff --git a/plugins/Skins/SkinLib/V8Script.h b/plugins/Skins/SkinLib/V8Script.h new file mode 100644 index 0000000000..b7e1f3f2a6 --- /dev/null +++ b/plugins/Skins/SkinLib/V8Script.h @@ -0,0 +1,46 @@ +#ifndef __V8_SCRIPT_H__
+# define __V8_SCRIPT_H__
+
+#include <v8.h>
+#include <utility>
+#include "V8Wrappers.h"
+
+
+typedef void (*ExceptionCallback)(void *param, const TCHAR *err);
+
+
+class V8Script
+{
+public:
+ static void initializeEngine();
+
+
+ V8Script();
+ ~V8Script();
+
+ bool compile(const TCHAR *source, Dialog *dlg);
+ void dispose();
+
+ bool isValid();
+
+ std::pair<SkinOptions *,DialogState *> configure(Dialog *dlg);
+
+ bool run(DialogState * state, SkinOptions *opts, DialogInfo *info);
+
+ void setExceptionCallback(ExceptionCallback cb, void *param = NULL);
+
+private:
+ v8::Persistent<v8::Context> context;
+ v8::Persistent<v8::Function> configureFunction;
+ v8::Persistent<v8::Function> drawFunction;
+
+ ExceptionCallback exceptionCallback;
+ void *exceptionCallbackParam;
+
+ void reportException(v8::TryCatch *try_catch);
+ void fillWrappers(DialogState *state, SkinOptions *opts, DialogInfo *info, bool configure);
+};
+
+
+
+#endif // __V8_SCRIPT_H__
diff --git a/plugins/Skins/SkinLib/V8Templates.cpp b/plugins/Skins/SkinLib/V8Templates.cpp new file mode 100644 index 0000000000..4900e13772 --- /dev/null +++ b/plugins/Skins/SkinLib/V8Templates.cpp @@ -0,0 +1,475 @@ +#include "globals.h"
+#include <v8.h>
+#include "V8Templates.h"
+#include "DialogState_v8_wrapper.h"
+#include "FieldState_v8_wrapper.h"
+#include "ControlFieldState_v8_wrapper.h"
+#include "TextFieldState_v8_wrapper.h"
+#include "FontState_v8_wrapper.h"
+#include "BorderState_v8_wrapper.h"
+#include "SkinOption_v8_wrapper.h"
+
+using namespace v8;
+
+
+V8Templates::V8Templates()
+{
+}
+
+V8Templates::~V8Templates()
+{
+ dialogStateTemplate.Dispose();
+ fieldStateTemplate.Dispose();
+ controlFieldStateTemplate.Dispose();
+ textFieldStateTemplate.Dispose();
+ fontStateTemplate.Dispose();
+ borderStateTemplate.Dispose();
+ skinOptionTemplate.Dispose();
+}
+
+
+Handle<ObjectTemplate> V8Templates::getGlobalTemplate()
+{
+ HandleScope scope;
+
+ if (!globalTemplate.IsEmpty())
+ return globalTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->Set(String::New("HORIZONTAL_ALIGN_LEFT"), String::New("HORIZONTAL_ALIGN_LEFT"));
+ templ->Set(String::New("LEFT"), String::New("HORIZONTAL_ALIGN_LEFT"));
+ templ->Set(String::New("HORIZONTAL_ALIGN_CENTER"), String::New("HORIZONTAL_ALIGN_CENTER"));
+ templ->Set(String::New("CENTER"), String::New("HORIZONTAL_ALIGN_CENTER"));
+ templ->Set(String::New("HORIZONTAL_ALIGN_RIGHT"), String::New("HORIZONTAL_ALIGN_RIGHT"));
+ templ->Set(String::New("RIGHT"), String::New("HORIZONTAL_ALIGN_RIGHT"));
+ templ->Set(String::New("VERTICAL_ALIGN_TOP"), String::New("VERTICAL_ALIGN_TOP"));
+ templ->Set(String::New("TOP"), String::New("VERTICAL_ALIGN_TOP"));
+ templ->Set(String::New("VERTICAL_ALIGN_CENTER"), String::New("VERTICAL_ALIGN_CENTER"));
+ templ->Set(String::New("CENTER"), String::New("VERTICAL_ALIGN_CENTER"));
+ templ->Set(String::New("VERTICAL_ALIGN_BOTTOM"), String::New("VERTICAL_ALIGN_BOTTOM"));
+ templ->Set(String::New("BOTTOM"), String::New("VERTICAL_ALIGN_BOTTOM"));
+ templ->Set(String::New("CHECKBOX"), String::New("CHECKBOX"));
+ templ->Set(String::New("NUMBER"), String::New("NUMBER"));
+ templ->Set(String::New("TEXT"), String::New("TEXT"));
+ addGlobalTemplateFields(templ);
+
+ globalTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return globalTemplate;
+}
+
+
+void V8Templates::addGlobalTemplateFields(Handle<ObjectTemplate> &templ)
+{
+}
+
+
+int V8Templates::numOfDialogStateInternalFields()
+{
+ return 1;
+}
+
+Handle<ObjectTemplate> V8Templates::getDialogStateTemplate()
+{
+ HandleScope scope;
+
+ if (!dialogStateTemplate.IsEmpty())
+ return dialogStateTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(numOfDialogStateInternalFields());
+ AddDialogStateAcessors(templ);
+ addDialogStateTemplateFields(templ);
+
+ dialogStateTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return dialogStateTemplate;
+}
+
+void V8Templates::addDialogStateTemplateFields(Handle<ObjectTemplate> &templ)
+{
+}
+
+Handle<Object> V8Templates::newDialogState()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getDialogStateTemplate()->NewInstance();
+ obj->Set(String::New("bordersRaw"), newBorderState(), ReadOnly);
+
+ return scope.Close(obj);
+}
+
+void V8Templates::fillDialogState(Handle<Object> v8Obj, DialogState *obj)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+ fillBorderState(Handle<Object>::Cast(v8Obj->Get(String::New("bordersRaw"))), obj->getBorders());
+}
+
+
+int V8Templates::numOfFieldStateInternalFields()
+{
+ return 1;
+}
+
+Handle<ObjectTemplate> V8Templates::getFieldStateTemplate()
+{
+ HandleScope scope;
+
+ if (!fieldStateTemplate.IsEmpty())
+ return fieldStateTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(numOfFieldStateInternalFields());
+ AddFieldStateAcessors(templ);
+ addFieldStateTemplateFields(templ);
+
+ fieldStateTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return fieldStateTemplate;
+}
+
+void V8Templates::addFieldStateTemplateFields(Handle<ObjectTemplate> &templ)
+{
+}
+
+Handle<Object> V8Templates::newFieldState()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getFieldStateTemplate()->NewInstance();
+ obj->Set(String::New("bordersRaw"), newBorderState(), ReadOnly);
+
+ return scope.Close(obj);
+}
+
+void V8Templates::fillFieldState(Handle<Object> v8Obj, FieldState *obj)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+ fillBorderState(Handle<Object>::Cast(v8Obj->Get(String::New("bordersRaw"))), obj->getBorders());
+}
+
+
+int V8Templates::numOfControlFieldStateInternalFields()
+{
+ return 1;
+}
+
+Handle<ObjectTemplate> V8Templates::getControlFieldStateTemplate()
+{
+ HandleScope scope;
+
+ if (!controlFieldStateTemplate.IsEmpty())
+ return controlFieldStateTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(numOfControlFieldStateInternalFields());
+ AddFieldStateAcessors(templ);
+ AddControlFieldStateAcessors(templ);
+ addControlFieldStateTemplateFields(templ);
+
+ controlFieldStateTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return controlFieldStateTemplate;
+}
+
+void V8Templates::addControlFieldStateTemplateFields(Handle<ObjectTemplate> &templ)
+{
+}
+
+Handle<Object> V8Templates::newControlFieldState()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getControlFieldStateTemplate()->NewInstance();
+ obj->Set(String::New("bordersRaw"), newBorderState(), ReadOnly);
+ obj->Set(String::New("font"), newFontState(), ReadOnly);
+
+ return scope.Close(obj);
+}
+
+void V8Templates::fillControlFieldState(Handle<Object> v8Obj, ControlFieldState *obj)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+ fillBorderState(Handle<Object>::Cast(v8Obj->Get(String::New("bordersRaw"))), obj->getBorders());
+ fillFontState(Handle<Object>::Cast(v8Obj->Get(String::New("font"))), obj->getFont());
+}
+
+
+Handle<ObjectTemplate> V8Templates::getLabelFieldStateTemplate()
+{
+ return getControlFieldStateTemplate();
+}
+
+Handle<Object> V8Templates::newLabelFieldState()
+{
+ return newControlFieldState();
+}
+
+void V8Templates::fillLabelFieldState(Handle<Object> v8Obj, LabelFieldState *obj)
+{
+ fillControlFieldState(v8Obj, obj);
+}
+
+
+Handle<ObjectTemplate> V8Templates::getButtonFieldStateTemplate()
+{
+ return getControlFieldStateTemplate();
+}
+
+Handle<Object> V8Templates::newButtonFieldState()
+{
+ return newControlFieldState();
+}
+
+void V8Templates::fillButtonFieldState(Handle<Object> v8Obj, ButtonFieldState *obj)
+{
+ fillControlFieldState(v8Obj, obj);
+}
+
+
+Handle<ObjectTemplate> V8Templates::getEditFieldStateTemplate()
+{
+ return getControlFieldStateTemplate();
+}
+
+Handle<Object> V8Templates::newEditFieldState()
+{
+ return newControlFieldState();
+}
+
+void V8Templates::fillEditFieldState(Handle<Object> v8Obj, EditFieldState *obj)
+{
+ fillControlFieldState(v8Obj, obj);
+}
+
+
+Handle<ObjectTemplate> V8Templates::getIconFieldStateTemplate()
+{
+ return getFieldStateTemplate();
+}
+
+Handle<Object> V8Templates::newIconFieldState()
+{
+ return newFieldState();
+}
+
+void V8Templates::fillIconFieldState(Handle<Object> v8Obj, IconFieldState *obj)
+{
+ fillFieldState(v8Obj, obj);
+}
+
+
+Handle<ObjectTemplate> V8Templates::getImageFieldStateTemplate()
+{
+ return getFieldStateTemplate();
+}
+
+Handle<Object> V8Templates::newImageFieldState()
+{
+ return newFieldState();
+}
+
+void V8Templates::fillImageFieldState(Handle<Object> v8Obj, ImageFieldState *obj)
+{
+ fillFieldState(v8Obj, obj);
+}
+
+
+int V8Templates::numOfTextFieldStateInternalFields()
+{
+ return 1;
+}
+
+Handle<ObjectTemplate> V8Templates::getTextFieldStateTemplate()
+{
+ HandleScope scope;
+
+ if (!textFieldStateTemplate.IsEmpty())
+ return textFieldStateTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(numOfTextFieldStateInternalFields());
+ AddFieldStateAcessors(templ);
+ AddTextFieldStateAcessors(templ);
+ addTextFieldStateTemplateFields(templ);
+
+ textFieldStateTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return textFieldStateTemplate;
+}
+
+void V8Templates::addTextFieldStateTemplateFields(Handle<ObjectTemplate> &templ)
+{
+}
+
+Handle<Object> V8Templates::newTextFieldState()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getTextFieldStateTemplate()->NewInstance();
+ obj->Set(String::New("bordersRaw"), newBorderState(), ReadOnly);
+ obj->Set(String::New("font"), newFontState(), ReadOnly);
+
+ return scope.Close(obj);
+}
+
+void V8Templates::fillTextFieldState(Handle<Object> v8Obj, TextFieldState *obj)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+ fillBorderState(Handle<Object>::Cast(v8Obj->Get(String::New("bordersRaw"))), obj->getBorders());
+ fillFontState(Handle<Object>::Cast(v8Obj->Get(String::New("font"))), obj->getFont());
+}
+
+
+int V8Templates::numOfFontStateInternalFields()
+{
+ return 1;
+}
+
+Handle<ObjectTemplate> V8Templates::getFontStateTemplate()
+{
+ HandleScope scope;
+
+ if (!fontStateTemplate.IsEmpty())
+ return fontStateTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(numOfFontStateInternalFields());
+ AddFontStateAcessors(templ);
+ addFontStateTemplateFields(templ);
+
+ fontStateTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return fontStateTemplate;
+}
+
+void V8Templates::addFontStateTemplateFields(Handle<ObjectTemplate> &templ)
+{
+}
+
+Handle<Object> V8Templates::newFontState()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getFontStateTemplate()->NewInstance();
+
+ return scope.Close(obj);
+}
+
+void V8Templates::fillFontState(Handle<Object> v8Obj, FontState *obj)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+}
+
+
+int V8Templates::numOfBorderStateInternalFields()
+{
+ return 1;
+}
+
+Handle<ObjectTemplate> V8Templates::getBorderStateTemplate()
+{
+ HandleScope scope;
+
+ if (!borderStateTemplate.IsEmpty())
+ return borderStateTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(numOfBorderStateInternalFields());
+ AddBorderStateAcessors(templ);
+ addBorderStateTemplateFields(templ);
+
+ borderStateTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return borderStateTemplate;
+}
+
+void V8Templates::addBorderStateTemplateFields(Handle<ObjectTemplate> &templ)
+{
+}
+
+Handle<Object> V8Templates::newBorderState()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getBorderStateTemplate()->NewInstance();
+
+ return scope.Close(obj);
+}
+
+void V8Templates::fillBorderState(Handle<Object> v8Obj, BorderState *obj)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+}
+
+
+int V8Templates::numOfSkinOptionInternalFields()
+{
+ return 1;
+}
+
+Handle<ObjectTemplate> V8Templates::getSkinOptionTemplate()
+{
+ HandleScope scope;
+
+ if (!skinOptionTemplate.IsEmpty())
+ return skinOptionTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(numOfSkinOptionInternalFields());
+ AddSkinOptionAcessors(templ);
+ addSkinOptionTemplateFields(templ);
+
+ skinOptionTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return skinOptionTemplate;
+}
+
+void V8Templates::addSkinOptionTemplateFields(Handle<ObjectTemplate> &templ)
+{
+}
+
+Handle<Object> V8Templates::newSkinOption()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getSkinOptionTemplate()->NewInstance();
+
+ return scope.Close(obj);
+}
+
+void V8Templates::fillSkinOption(Handle<Object> v8Obj, SkinOption *obj)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+}
+
+
diff --git a/plugins/Skins/SkinLib/V8Templates.h b/plugins/Skins/SkinLib/V8Templates.h new file mode 100644 index 0000000000..38590fe844 --- /dev/null +++ b/plugins/Skins/SkinLib/V8Templates.h @@ -0,0 +1,114 @@ +#ifndef __V8_TEMPLATES_H__
+# define __V8_TEMPLATES_H__
+
+#include <v8.h>
+#include "DialogState.h"
+#include "FieldState.h"
+#include "ControlFieldState.h"
+#include "LabelFieldState.h"
+#include "ButtonFieldState.h"
+#include "EditFieldState.h"
+#include "IconFieldState.h"
+#include "ImageFieldState.h"
+#include "TextFieldState.h"
+#include "FontState.h"
+#include "BorderState.h"
+#include "SkinOption.h"
+
+
+class V8Templates
+{
+public:
+ V8Templates();
+ virtual ~V8Templates();
+
+ virtual v8::Handle<v8::ObjectTemplate> getGlobalTemplate();
+
+ virtual v8::Handle<v8::ObjectTemplate> getDialogStateTemplate();
+ virtual v8::Handle<v8::Object> newDialogState();
+ virtual void fillDialogState(v8::Handle<v8::Object> v8Obj, DialogState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getFieldStateTemplate();
+ virtual v8::Handle<v8::Object> newFieldState();
+ virtual void fillFieldState(v8::Handle<v8::Object> v8Obj, FieldState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getControlFieldStateTemplate();
+ virtual v8::Handle<v8::Object> newControlFieldState();
+ virtual void fillControlFieldState(v8::Handle<v8::Object> v8Obj, ControlFieldState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getLabelFieldStateTemplate();
+ virtual v8::Handle<v8::Object> newLabelFieldState();
+ virtual void fillLabelFieldState(v8::Handle<v8::Object> v8Obj, LabelFieldState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getButtonFieldStateTemplate();
+ virtual v8::Handle<v8::Object> newButtonFieldState();
+ virtual void fillButtonFieldState(v8::Handle<v8::Object> v8Obj, ButtonFieldState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getEditFieldStateTemplate();
+ virtual v8::Handle<v8::Object> newEditFieldState();
+ virtual void fillEditFieldState(v8::Handle<v8::Object> v8Obj, EditFieldState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getIconFieldStateTemplate();
+ virtual v8::Handle<v8::Object> newIconFieldState();
+ virtual void fillIconFieldState(v8::Handle<v8::Object> v8Obj, IconFieldState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getImageFieldStateTemplate();
+ virtual v8::Handle<v8::Object> newImageFieldState();
+ virtual void fillImageFieldState(v8::Handle<v8::Object> v8Obj, ImageFieldState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getTextFieldStateTemplate();
+ virtual v8::Handle<v8::Object> newTextFieldState();
+ virtual void fillTextFieldState(v8::Handle<v8::Object> v8Obj, TextFieldState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getFontStateTemplate();
+ virtual v8::Handle<v8::Object> newFontState();
+ virtual void fillFontState(v8::Handle<v8::Object> v8Obj, FontState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getBorderStateTemplate();
+ virtual v8::Handle<v8::Object> newBorderState();
+ virtual void fillBorderState(v8::Handle<v8::Object> v8Obj, BorderState *obj);
+
+ virtual v8::Handle<v8::ObjectTemplate> getSkinOptionTemplate();
+ virtual v8::Handle<v8::Object> newSkinOption();
+ virtual void fillSkinOption(v8::Handle<v8::Object> v8Obj, SkinOption *obj);
+
+
+private:
+ v8::Persistent<v8::ObjectTemplate> globalTemplate;
+ v8::Persistent<v8::ObjectTemplate> dialogStateTemplate;
+ v8::Persistent<v8::ObjectTemplate> fieldStateTemplate;
+ v8::Persistent<v8::ObjectTemplate> controlFieldStateTemplate;
+ v8::Persistent<v8::ObjectTemplate> textFieldStateTemplate;
+ v8::Persistent<v8::ObjectTemplate> fontStateTemplate;
+ v8::Persistent<v8::ObjectTemplate> borderStateTemplate;
+ v8::Persistent<v8::ObjectTemplate> skinOptionTemplate;
+
+protected:
+ virtual void addGlobalTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+ virtual int numOfDialogStateInternalFields();
+ virtual void addDialogStateTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+ virtual int numOfFieldStateInternalFields();
+ virtual void addFieldStateTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+ virtual int numOfControlFieldStateInternalFields();
+ virtual void addControlFieldStateTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+ virtual int numOfTextFieldStateInternalFields();
+ virtual void addTextFieldStateTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+ virtual int numOfFontStateInternalFields();
+ virtual void addFontStateTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+ virtual int numOfBorderStateInternalFields();
+ virtual void addBorderStateTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+ virtual int numOfSkinOptionInternalFields();
+ virtual void addSkinOptionTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+};
+
+
+
+#endif // __V8_TEMPLATES_H__
diff --git a/plugins/Skins/SkinLib/V8Wrappers.cpp b/plugins/Skins/SkinLib/V8Wrappers.cpp new file mode 100644 index 0000000000..9384e3c8ad --- /dev/null +++ b/plugins/Skins/SkinLib/V8Wrappers.cpp @@ -0,0 +1,385 @@ +#include "globals.h"
+#include "V8Wrappers.h"
+
+#include <utf8_helpers.h>
+
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+
+static Handle<Value> IsEmptyCallback(const Arguments& args)
+{
+ HandleScope scope;
+
+ if (args.Length() < 1)
+ return scope.Close( Undefined() );
+
+ for(int i = 0; i < args.Length(); i++)
+ {
+ Local<Value> arg = args[0];
+
+ if (arg.IsEmpty() || arg->IsNull() || arg->IsUndefined())
+ {
+ return scope.Close( Boolean::New(true) );
+ }
+ else if (arg->IsObject())
+ {
+ Local<Object> self = Local<Object>::Cast(arg);
+ if (self->InternalFieldCount() < 1)
+ continue;
+
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *field = (FieldState *) wrap->Value();
+ if (field == NULL)
+ continue;
+
+ if (field->isEmpty())
+ return scope.Close( Boolean::New(true) );
+ }
+ else if (arg->IsString())
+ {
+ Local<String> str = Local<String>::Cast(arg);
+ if (str->Length() <= 0)
+ return scope.Close( Boolean::New(true) );
+ }
+ }
+
+ return scope.Close( Boolean::New(false) );
+}
+
+static Handle<Value> RGBCallback(const Arguments& args)
+{
+ HandleScope scope;
+
+ if (args.Length() != 3)
+ return scope.Close( Undefined() );
+
+ COLORREF color = RGB(args[0]->Int32Value(), args[1]->Int32Value(), args[2]->Int32Value());
+ return scope.Close( Int32::New(color) );
+}
+
+static Handle<Value> AlertCallback(const Arguments& args)
+{
+ HandleScope scope;
+
+ if (args.Length() < 1)
+ return scope.Close( Boolean::New(false) );
+
+ Local<Value> arg = args[0];
+ String::Utf8Value utf8_value(arg->ToDetailString());
+
+ char *tmp = *utf8_value;
+// TODO MessageBox(NULL, Utf8ToTchar(*utf8_value), _T("Skin alert"), MB_OK);
+
+ return scope.Close( Boolean::New(true) );
+}
+
+void V8Wrappers::addGlobalTemplateFields(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->Set(String::New("IsEmpty"), FunctionTemplate::New(&IsEmptyCallback));
+ templ->Set(String::New("RGB"), FunctionTemplate::New(&RGBCallback));
+ templ->Set(String::New("alert"), FunctionTemplate::New(&AlertCallback));
+}
+
+
+Handle<Object> V8Wrappers::newState(FieldType type)
+{
+ switch(type)
+ {
+ case SIMPLE_TEXT:
+ return newTextFieldState();
+ case SIMPLE_IMAGE:
+ return newImageFieldState();
+ case SIMPLE_ICON:
+ return newIconFieldState();
+ case CONTROL_LABEL:
+ return newLabelFieldState();
+ case CONTROL_BUTTON:
+ return newButtonFieldState();
+ case CONTROL_EDIT:
+ return newEditFieldState();
+ }
+ throw "Unknown type";
+}
+
+void V8Wrappers::fillState(Handle<Object> obj, FieldState *state)
+{
+ switch(state->getField()->getType())
+ {
+ case SIMPLE_TEXT:
+ fillTextFieldState(obj, (TextFieldState *) state);
+ break;
+ case SIMPLE_IMAGE:
+ fillImageFieldState(obj, (ImageFieldState *) state);
+ break;
+ case SIMPLE_ICON:
+ fillIconFieldState(obj, (IconFieldState *) state);
+ break;
+ case CONTROL_LABEL:
+ fillLabelFieldState(obj, (LabelFieldState *) state);
+ break;
+ case CONTROL_BUTTON:
+ fillButtonFieldState(obj, (ButtonFieldState *) state);
+ break;
+ case CONTROL_EDIT:
+ fillEditFieldState(obj, (EditFieldState *) state);
+ break;
+ default:
+ throw "Unknown type";
+ }
+}
+
+static Handle<Value> Get_SkinOption_value(SkinOption *opt)
+{
+ HandleScope scope;
+
+ if (opt == NULL)
+ return scope.Close( Undefined() );
+
+ switch (opt->getType())
+ {
+ case CHECKBOX: return scope.Close( Boolean::New(opt->getValueCheckbox()) );
+ case NUMBER: return scope.Close( Int32::New(opt->getValueNumber()) );
+ case TEXT: return scope.Close( String::New((const V8_TCHAR *) opt->getValueText()) );
+ }
+
+ return scope.Close( Undefined() );
+}
+
+static Handle<Value> Get_Options_Fields(Local<String> aName, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ SkinOptions *opts = (SkinOptions *) wrap->Value();
+ if (opts == NULL)
+ return scope.Close( Undefined() );
+
+ String::AsciiValue name(aName);
+ if (name.length() <= 0)
+ return scope.Close( Undefined() );
+
+ bool configure = self->GetInternalField(1)->BooleanValue();
+ if (configure)
+ {
+ SkinOption * opt = opts->getOption(*name);
+
+ if (opt == NULL)
+ {
+ opt = new SkinOption(*name);
+ opts->addOption(opt);
+ }
+
+ wrap = Local<External>::Cast(info.Data());
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ V8Wrappers *wrappers = (V8Wrappers *) wrap->Value();
+ if (wrappers == NULL)
+ return scope.Close( Undefined() );
+
+ Handle<Object> ret = wrappers->newSkinOption();
+ wrappers->fillSkinOption(ret, opt);
+ return scope.Close( ret );
+ }
+ else
+ {
+ SkinOption * opt = opts->getOption(*name);
+ return scope.Close( Get_SkinOption_value(opt) );
+ }
+}
+
+Handle<ObjectTemplate> V8Wrappers::getOptionsTemplate()
+{
+ HandleScope scope;
+
+ if (!optionsTemplate.IsEmpty())
+ return optionsTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(2);
+ templ->SetNamedPropertyHandler(&Get_Options_Fields, 0, 0, 0, 0, External::New(this));
+
+ optionsTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return optionsTemplate;
+}
+
+Handle<Object> V8Wrappers::newOptions()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getOptionsTemplate()->NewInstance();
+
+ return scope.Close(obj);
+}
+
+void V8Wrappers::fillOptions(Handle<Object> v8Obj, SkinOptions *obj, bool configure)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+ v8Obj->SetInternalField(1, Boolean::New(configure));
+}
+
+
+static Handle<Value> Get_SkinOption_value(Local<String> property, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ return scope.Close( Get_SkinOption_value((SkinOption *) wrap->Value()) );
+}
+
+static void Set_SkinOption_value(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return;
+
+ SkinOption *opt = (SkinOption *) wrap->Value();
+ if (opt == NULL)
+ return;
+
+ switch (opt->getType())
+ {
+ case CHECKBOX:
+ if (!value.IsEmpty() && value->IsBoolean())
+ opt->setValueCheckbox(value->BooleanValue());
+ break;
+ case NUMBER:
+ if (!value.IsEmpty() && value->IsNumber())
+ opt->setValueNumber(value->Int32Value());
+ break;
+ case TEXT:
+ if (!value.IsEmpty() && value->IsString())
+ opt->setValueText(Utf8ToTchar(*String::Utf8Value(value)));
+ break;
+ }
+}
+
+void V8Wrappers::addSkinOptionTemplateFields(Handle<ObjectTemplate> &templ)
+{
+ HandleScope scope;
+
+ templ->SetAccessor(String::New("value"), Get_SkinOption_value, Set_SkinOption_value);
+}
+
+
+static Handle<Value> Get_DialogInfo_Fields(Local<String> aName, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogInfo *dialogInfo = (DialogInfo *) wrap->Value();
+ if (dialogInfo == NULL)
+ return scope.Close( Undefined() );
+
+ String::AsciiValue name(aName);
+ if (name.length() <= 0)
+ return scope.Close( Undefined() );
+
+ wrap = Local<External>::Cast(info.Data());
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ V8Wrappers *wrappers = (V8Wrappers *) wrap->Value();
+ if (wrappers == NULL)
+ return scope.Close( Undefined() );
+
+ Local<String> aPrefix = Local<String>::Cast(self->GetInternalField(1));
+ if (aPrefix.IsEmpty())
+ return scope.Close( Undefined() );
+
+ String::AsciiValue prefix(aPrefix);
+
+ std::string var;
+ var += *prefix;
+ var += *name;
+
+ switch(dialogInfo->getType(var.c_str()))
+ {
+ case TYPE_VARIABLE:
+ {
+ var += '.';
+
+ Handle<Object> ret = wrappers->newDialogInfo();
+ wrappers->fillDialogInfo(ret, dialogInfo, var.c_str());
+ return scope.Close( ret );
+ }
+ case TYPE_INT:
+ return scope.Close( Int32::New(dialogInfo->getAsInt(var.c_str())) );
+ case TYPE_DOUBLE:
+ return scope.Close( Number::New(dialogInfo->getAsDouble(var.c_str())) );
+ case TYPE_BOOL:
+ return scope.Close( Boolean::New(dialogInfo->getAsBool(var.c_str())) );
+ case TYPE_STRING:
+ return scope.Close( String::New((const V8_TCHAR *) dialogInfo->getAsString(var.c_str())) );
+ case UNKNOWN:
+ default:
+ return scope.Close( Undefined() );
+ }
+}
+
+Handle<ObjectTemplate> V8Wrappers::getDialogInfoTemplate()
+{
+ HandleScope scope;
+
+ if (!dialogInfoTemplate.IsEmpty())
+ return dialogInfoTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(2);
+ templ->SetNamedPropertyHandler(&Get_DialogInfo_Fields, 0, 0, 0, 0, External::New(this));
+
+ dialogInfoTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return dialogInfoTemplate;
+}
+
+Handle<Object> V8Wrappers::newDialogInfo()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getDialogInfoTemplate()->NewInstance();
+
+ return scope.Close(obj);
+}
+
+void V8Wrappers::fillDialogInfo(Handle<Object> v8Obj, DialogInfo *obj, const char *prefix)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+
+ v8Obj->SetInternalField(1, String::New(prefix != NULL ? prefix : ""));
+}
diff --git a/plugins/Skins/SkinLib/V8Wrappers.h b/plugins/Skins/SkinLib/V8Wrappers.h new file mode 100644 index 0000000000..b2c5eb2b92 --- /dev/null +++ b/plugins/Skins/SkinLib/V8Wrappers.h @@ -0,0 +1,35 @@ +#ifndef __V8_WRAPPERS_H__
+# define __V8_WRAPPERS_H__
+
+#include "V8Templates.h"
+#include "SkinOptions.h"
+
+
+class V8Wrappers : public V8Templates
+{
+public:
+ virtual v8::Handle<v8::Object> newState(FieldType type);
+ virtual void fillState(v8::Handle<v8::Object> obj, FieldState *state);
+
+ virtual v8::Handle<v8::ObjectTemplate> getOptionsTemplate();
+ virtual v8::Handle<v8::Object> newOptions();
+ virtual void fillOptions(v8::Handle<v8::Object> v8Obj, SkinOptions *obj, bool configure);
+
+ virtual v8::Handle<v8::ObjectTemplate> getDialogInfoTemplate();
+ virtual v8::Handle<v8::Object> newDialogInfo();
+ virtual void fillDialogInfo(v8::Handle<v8::Object> v8Obj, DialogInfo *obj, const char *prefix = NULL);
+
+private:
+ v8::Persistent<v8::ObjectTemplate> optionsTemplate;
+ v8::Persistent<v8::ObjectTemplate> dialogInfoTemplate;
+
+protected:
+ virtual void addGlobalTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+ virtual void addSkinOptionTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);
+
+};
+
+
+
+#endif // __V8_WRAPPERS_H__
diff --git a/plugins/Skins/SkinLib/globals.h b/plugins/Skins/SkinLib/globals.h new file mode 100644 index 0000000000..18d6ffdcfc --- /dev/null +++ b/plugins/Skins/SkinLib/globals.h @@ -0,0 +1,20 @@ +#ifndef __GLOBALS_H__
+# define __GLOBALS_H__
+
+#ifdef DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
+#endif
+
+#include <windows.h>
+#include <newpluginapi.h>
+#include <m_system.h>
+#include <m_utils.h>
+#include <utf8_helpers.h>
+
+
+#define MAX_REGS(_X_) ( sizeof(_X_) / sizeof(_X_[0]) )
+
+
+#endif // __GLOBALS_H__
\ No newline at end of file diff --git a/plugins/Skins/SkinLib/scope.h b/plugins/Skins/SkinLib/scope.h new file mode 100644 index 0000000000..2fad797b88 --- /dev/null +++ b/plugins/Skins/SkinLib/scope.h @@ -0,0 +1,37 @@ +#ifndef __PTR_H__
+# define __PTR_H__
+
+
+template<class T>
+class scope
+{
+public:
+ scope() : p(NULL) {}
+ scope(T t) : p(t) {}
+ ~scope() { release(); }
+
+ void release()
+ {
+ if (p != NULL)
+ delete p;
+ p = NULL;
+ }
+
+ T operator=(T t) { release(); p = t; return t; }
+ T operator->() const { return p; }
+ operator T() const { return p; }
+
+ T detach()
+ {
+ T ret = p;
+ p = NULL;
+ return ret;
+ }
+
+private:
+ T p;
+};
+
+
+
+#endif // __PTR_H__
diff --git a/plugins/Skins/SkinLib/tstring.h b/plugins/Skins/SkinLib/tstring.h new file mode 100644 index 0000000000..e6017176c5 --- /dev/null +++ b/plugins/Skins/SkinLib/tstring.h @@ -0,0 +1,13 @@ +#ifndef __TSTRING_H__
+# define __TSTRING_H__
+
+#include <tchar.h>
+#include <string>
+
+
+namespace std {
+ typedef basic_string<TCHAR, char_traits<TCHAR>, allocator<TCHAR>> tstring;
+}
+
+
+#endif // __TSTRING_H__
|