diff options
Diffstat (limited to 'Plugins/skins/SkinLib')
72 files changed, 4504 insertions, 0 deletions
diff --git a/Plugins/skins/SkinLib/BorderState.cpp b/Plugins/skins/SkinLib/BorderState.cpp new file mode 100644 index 0000000..ff5d046 --- /dev/null +++ b/Plugins/skins/SkinLib/BorderState.cpp @@ -0,0 +1,59 @@ +#include "globals.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 = left;
+}
+
+int BorderState::getRight() const
+{
+ return right;
+}
+
+void BorderState::setRight(int right)
+{
+ this->right = right;
+}
+
+int BorderState::getTop() const
+{
+ return top;
+}
+
+void BorderState::setTop(int top)
+{
+ this->top = top;
+}
+
+int BorderState::getBottom() const
+{
+ return bottom;
+}
+
+void BorderState::setBottom(int bottom)
+{
+ this->bottom = bottom;
+}
+
+void BorderState::setAll(int border)
+{
+ left = border;
+ right = border;
+ top = border;
+ bottom = border;
+}
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/BorderState.h b/Plugins/skins/SkinLib/BorderState.h new file mode 100644 index 0000000..2cac3c1 --- /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 0000000..a2e057e --- /dev/null +++ b/Plugins/skins/SkinLib/BorderState_v8_wrapper.cpp @@ -0,0 +1,90 @@ +#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)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ BorderState *tmp = (BorderState *) wrap->Value();
+ return Int32::New(tmp->getLeft());
+}
+
+static void Set_BorderState_left(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ BorderState *tmp = (BorderState *) wrap->Value();
+ tmp->setLeft(value->Int32Value());
+}
+
+
+static Handle<Value> Get_BorderState_right(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ BorderState *tmp = (BorderState *) wrap->Value();
+ return Int32::New(tmp->getRight());
+}
+
+static void Set_BorderState_right(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ BorderState *tmp = (BorderState *) wrap->Value();
+ tmp->setRight(value->Int32Value());
+}
+
+
+static Handle<Value> Get_BorderState_top(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ BorderState *tmp = (BorderState *) wrap->Value();
+ return Int32::New(tmp->getTop());
+}
+
+static void Set_BorderState_top(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ BorderState *tmp = (BorderState *) wrap->Value();
+ tmp->setTop(value->Int32Value());
+}
+
+
+static Handle<Value> Get_BorderState_bottom(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ BorderState *tmp = (BorderState *) wrap->Value();
+ return Int32::New(tmp->getBottom());
+}
+
+static void Set_BorderState_bottom(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ BorderState *tmp = (BorderState *) wrap->Value();
+ tmp->setBottom(value->Int32Value());
+}
+
+
+void AddBorderStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ 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 0000000..70af9e4 --- /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 0000000..267f34f --- /dev/null +++ b/Plugins/skins/SkinLib/ButtonField.cpp @@ -0,0 +1,22 @@ +#include "globals.h"
+#include "ButtonField.h"
+#include "ButtonFieldState.h"
+
+
+ButtonField::ButtonField(const char *name, HWND hwnd) : ControlField(name, hwnd)
+{
+}
+
+ButtonField::~ButtonField()
+{
+}
+
+FieldType ButtonField::getType() const
+{
+ return CONTROL_BUTTON;
+}
+
+FieldState * ButtonField::createState()
+{
+ return new ButtonFieldState(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 0000000..101ab14 --- /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(const char *name, HWND hwnd);
+ virtual ~ButtonField();
+
+ virtual FieldType getType() const;
+
+ virtual FieldState * createState();
+};
+
+
+
+#endif // __BUTTON_FIELD_H__
diff --git a/Plugins/skins/SkinLib/ButtonFieldState.cpp b/Plugins/skins/SkinLib/ButtonFieldState.cpp new file mode 100644 index 0000000..92e7676 --- /dev/null +++ b/Plugins/skins/SkinLib/ButtonFieldState.cpp @@ -0,0 +1,24 @@ +#include "globals.h"
+#include "ButtonFieldState.h"
+
+ButtonFieldState::ButtonFieldState(ControlField *field) : ControlFieldState(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;
+}
\ 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 0000000..405fea2 --- /dev/null +++ b/Plugins/skins/SkinLib/ButtonFieldState.h @@ -0,0 +1,21 @@ +#ifndef __BUTTON_FIELD_STATE_H__
+# define __BUTTON_FIELD_STATE_H__
+
+#include "ControlFieldState.h"
+
+
+class ButtonFieldState : public ControlFieldState
+{
+public:
+ virtual ~ButtonFieldState();
+
+ virtual Size getPreferedSize() const;
+
+private:
+ ButtonFieldState(ControlField *field);
+
+ friend class ButtonField;
+};
+
+
+#endif // __BUTTON_FIELD_STATE_H__
diff --git a/Plugins/skins/SkinLib/ControlField.cpp b/Plugins/skins/SkinLib/ControlField.cpp new file mode 100644 index 0000000..3c9d692 --- /dev/null +++ b/Plugins/skins/SkinLib/ControlField.cpp @@ -0,0 +1,122 @@ +#include "globals.h"
+#include "ControlField.h"
+#include "ControlFieldState.h"
+
+
+ControlField::ControlField(const char *name, HWND aHwnd) : Field(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 0000000..6bf4e91 --- /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(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 0000000..d3b45e3 --- /dev/null +++ b/Plugins/skins/SkinLib/ControlFieldState.cpp @@ -0,0 +1,86 @@ +#include "globals.h"
+#include "ControlFieldState.h"
+
+
+ControlFieldState::ControlFieldState(ControlField *field) : FieldState(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 0000000..f3981eb --- /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(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 0000000..8a42cf5 --- /dev/null +++ b/Plugins/skins/SkinLib/ControlFieldState_v8_wrapper.cpp @@ -0,0 +1,38 @@ +#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)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ ControlFieldState *tmp = (ControlFieldState *) wrap->Value();
+ return String::New((const V8_TCHAR *) tmp->getText());
+}
+
+static void Set_ControlFieldState_text(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ ControlFieldState *tmp = (ControlFieldState *) wrap->Value();
+ String::Utf8Value utf8_value(value);
+ tmp->setText(Utf8ToTchar(*utf8_value));
+}
+
+
+void AddControlFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ 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 0000000..c86964c --- /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 0000000..712b85a --- /dev/null +++ b/Plugins/skins/SkinLib/Dialog.cpp @@ -0,0 +1,72 @@ +#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;
+}
+
+
+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());
+
+ return ret;
+}
diff --git a/Plugins/skins/SkinLib/Dialog.h b/Plugins/skins/SkinLib/Dialog.h new file mode 100644 index 0000000..ae98077 --- /dev/null +++ b/Plugins/skins/SkinLib/Dialog.h @@ -0,0 +1,34 @@ +#ifndef __DIALOG_H__
+# define __DIALOG_H__
+
+#include <vector>
+#include "Field.h"
+
+class DialogState;
+
+
+/// It is responsible for freeing the Fields
+class Dialog
+{
+public:
+ Dialog(const char *name);
+ ~Dialog();
+
+ const char * getName() const;
+
+ std::vector<Field *> fields;
+ bool addField(Field *field);
+ Field * getField(const char *name) const;
+
+ const Size & getSize() const;
+ void setSize(const Size &size);
+
+ DialogState * createState();
+
+private:
+ const std::string name;
+ Size size;
+};
+
+
+#endif // __DIALOG_H__
diff --git a/Plugins/skins/SkinLib/DialogState.cpp b/Plugins/skins/SkinLib/DialogState.cpp new file mode 100644 index 0000000..8643c06 --- /dev/null +++ b/Plugins/skins/SkinLib/DialogState.cpp @@ -0,0 +1,81 @@ +#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::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();
+}
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/DialogState.h b/Plugins/skins/SkinLib/DialogState.h new file mode 100644 index 0000000..08b98d6 --- /dev/null +++ b/Plugins/skins/SkinLib/DialogState.h @@ -0,0 +1,45 @@ +#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;
+
+ int getWidth() const;
+ void setWidth(int width);
+
+ int getHeight() const;
+ void setHeight(int height);
+
+ BorderState * getBorders();
+ const BorderState * getBorders() 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 0000000..23f5d36 --- /dev/null +++ b/Plugins/skins/SkinLib/DialogState_v8_wrapper.cpp @@ -0,0 +1,54 @@ +#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)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ DialogState *tmp = (DialogState *) wrap->Value();
+ return Int32::New(tmp->getWidth());
+}
+
+static void Set_DialogState_width(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ DialogState *tmp = (DialogState *) wrap->Value();
+ tmp->setWidth(value->Int32Value());
+}
+
+
+static Handle<Value> Get_DialogState_height(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ DialogState *tmp = (DialogState *) wrap->Value();
+ return Int32::New(tmp->getHeight());
+}
+
+static void Set_DialogState_height(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ DialogState *tmp = (DialogState *) wrap->Value();
+ tmp->setHeight(value->Int32Value());
+}
+
+
+void AddDialogStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ templ->SetAccessor(String::New("width"), Get_DialogState_width, Set_DialogState_width);
+ templ->SetAccessor(String::New("height"), Get_DialogState_height, Set_DialogState_height);
+}
diff --git a/Plugins/skins/SkinLib/DialogState_v8_wrapper.h b/Plugins/skins/SkinLib/DialogState_v8_wrapper.h new file mode 100644 index 0000000..709ef2d --- /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 0000000..0032b5b --- /dev/null +++ b/Plugins/skins/SkinLib/EditField.cpp @@ -0,0 +1,22 @@ +#include "globals.h"
+#include "EditField.h"
+#include "EditFieldState.h"
+
+
+EditField::EditField(const char *name, HWND hwnd) : ControlField(name, hwnd)
+{
+}
+
+EditField::~EditField()
+{
+}
+
+FieldType EditField::getType() const
+{
+ return CONTROL_EDIT;
+}
+
+FieldState * EditField::createState()
+{
+ return new EditFieldState(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 0000000..912b1c5 --- /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(const char *name, HWND hwnd);
+ virtual ~EditField();
+
+ virtual FieldType getType() const;
+
+ virtual FieldState * createState();
+};
+
+
+#endif // __EDIT_FIELD_H__
diff --git a/Plugins/skins/SkinLib/EditFieldState.cpp b/Plugins/skins/SkinLib/EditFieldState.cpp new file mode 100644 index 0000000..927e788 --- /dev/null +++ b/Plugins/skins/SkinLib/EditFieldState.cpp @@ -0,0 +1,52 @@ +#include "globals.h"
+#include "EditFieldState.h"
+
+
+EditFieldState::EditFieldState(EditField *field) : ControlFieldState(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;
+}
\ 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 0000000..33a0382 --- /dev/null +++ b/Plugins/skins/SkinLib/EditFieldState.h @@ -0,0 +1,22 @@ +#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;
+
+private:
+ EditFieldState(EditField *field);
+
+ friend class EditField;
+};
+
+
+#endif // __EDIT_FIELD_STATE_H__
diff --git a/Plugins/skins/SkinLib/Field.cpp b/Plugins/skins/SkinLib/Field.cpp new file mode 100644 index 0000000..6083a41 --- /dev/null +++ b/Plugins/skins/SkinLib/Field.cpp @@ -0,0 +1,29 @@ +#include "globals.h"
+#include "Field.h"
+#include "FieldState.h"
+
+
+Field::Field(const char *aName) : name(aName), onChangeCallback(NULL), onChangeCallbackParam(NULL)
+{
+}
+
+Field::~Field()
+{
+}
+
+const char * Field::getName() const
+{
+ return name.c_str();
+}
+
+void Field::setOnChangeCallback(FieldCallback cb, void *param /*= NULL*/)
+{
+ onChangeCallback = cb;
+ onChangeCallbackParam = param;
+}
+
+void Field::fireOnChange() const
+{
+ if (onChangeCallback != NULL)
+ onChangeCallback(onChangeCallbackParam, this);
+}
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/Field.h b/Plugins/skins/SkinLib/Field.h new file mode 100644 index 0000000..76fa68d --- /dev/null +++ b/Plugins/skins/SkinLib/Field.h @@ -0,0 +1,55 @@ +#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 Field;
+class FieldState;
+
+typedef void (*FieldCallback)(void *param, const Field *field);
+
+
+class Field
+{
+public:
+ Field(const char *name);
+ virtual ~Field();
+
+ virtual const char * getName() const;
+ virtual FieldType getType() const = 0;
+
+ virtual FieldState * createState() = 0;
+
+ virtual void setOnChangeCallback(FieldCallback cb, void *param = NULL);
+
+protected:
+ void fireOnChange() const;
+
+private:
+ const std::string name;
+
+ 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 0000000..7186b0c --- /dev/null +++ b/Plugins/skins/SkinLib/FieldState.cpp @@ -0,0 +1,175 @@ +#include "globals.h"
+#include "FieldState.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(Field *aField) : field(aField), size(-1, -1), pos(0, 0),
+ usingX(0), usingY(0), visible(true)
+{
+}
+
+FieldState::~FieldState()
+{
+}
+
+Field * FieldState::getField() const
+{
+ return field;
+}
+
+int FieldState::getX() const
+{
+ return pos.x;
+}
+
+void FieldState::setX(int x)
+{
+ if (usingX & END)
+ {
+ int diff = x - getX();
+ size.x = max(0, getWidth() - 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() - diff);
+ }
+
+ pos.y = y;
+
+ SET(usingY, START);
+}
+
+int FieldState::getWidth() const
+{
+ if (size.x >= 0)
+ return size.x;
+
+ return getPreferedSize().x;
+}
+
+void FieldState::setWidth(int width)
+{
+ width = max(0, width);
+
+ if (LAST_SET(usingX) == END)
+ {
+ int diff = width - getWidth();
+ pos.x = getX() - diff;
+ }
+
+ size.x = width;
+
+ usingX |= LEN;
+}
+
+int FieldState::getHeight() const
+{
+ if (size.y >= 0)
+ return size.y;
+
+ return getPreferedSize().y;
+}
+
+void FieldState::setHeight(int height)
+{
+ height = max(0, height);
+
+ if (LAST_SET(usingY) == END)
+ {
+ int diff = height - getHeight();
+ pos.y = getY() - diff;
+ }
+
+ size.y = height;
+
+ usingY |= LEN;
+}
+
+bool FieldState::isVisible() const
+{
+ return visible;
+}
+
+void FieldState::setVisible(bool visible)
+{
+ this->visible = visible;
+}
+
+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);
+}
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/FieldState.h b/Plugins/skins/SkinLib/FieldState.h new file mode 100644 index 0000000..95b2fc5 --- /dev/null +++ b/Plugins/skins/SkinLib/FieldState.h @@ -0,0 +1,58 @@ +#ifndef __FIELD_STATE_H__
+# define __FIELD_STATE_H__
+
+#include "Field.h"
+
+
+class FieldState
+{
+public:
+ virtual ~FieldState();
+
+ virtual Field * getField() const;
+
+ virtual Size getPreferedSize() const = 0;
+
+ 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 botom);
+
+ virtual bool isVisible() const;
+ virtual void setVisible(bool visible);
+
+protected:
+ FieldState(Field *field);
+
+ Field *field;
+
+ Size size;
+ Position pos;
+ int usingX;
+ int usingY;
+ bool visible;
+
+ 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 0000000..202bfc8 --- /dev/null +++ b/Plugins/skins/SkinLib/FieldState.rec @@ -0,0 +1,54 @@ +struct DialogState
+{
+ Int32 width;
+ Int32 height;
+};
+
+struct FieldState
+{
+ Int32 x;
+ Int32 y;
+ Int32 width;
+ Int32 height;
+ Int32 left;
+ Int32 top;
+ Int32 right;
+ Int32 bottom;
+ Boolean visible;
+};
+
+struct ControlFieldState
+{
+ Char text[1024];
+};
+
+struct TextFieldState
+{
+ Char text[1024];
+};
+
+struct FontState
+{
+ Char face[32];
+ Int32 size;
+ Boolean italic;
+ Boolean bold;
+ Boolean underline;
+ Boolean strikeOut;
+};
+
+struct BorderState
+{
+ Int32 left;
+ Int32 right;
+ Int32 top;
+ Int32 bottom;
+};
+
+struct SkinOption
+{
+ Char description[128];
+ Int32 min;
+ Int32 max;
+ Int32 type | CHECKBOX | NUMBER | TEXT;
+};
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/FieldState_v8_wrapper.cpp b/Plugins/skins/SkinLib/FieldState_v8_wrapper.cpp new file mode 100644 index 0000000..e5f754b --- /dev/null +++ b/Plugins/skins/SkinLib/FieldState_v8_wrapper.cpp @@ -0,0 +1,180 @@ +#include "globals.h"
+#include "FieldState_v8_wrapper.h"
+#include <v8.h>
+#include "FieldState.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)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Int32::New(tmp->getX());
+}
+
+static void Set_FieldState_x(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setX(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_y(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Int32::New(tmp->getY());
+}
+
+static void Set_FieldState_y(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setY(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_width(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Int32::New(tmp->getWidth());
+}
+
+static void Set_FieldState_width(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setWidth(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_height(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Int32::New(tmp->getHeight());
+}
+
+static void Set_FieldState_height(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setHeight(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_left(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Int32::New(tmp->getLeft());
+}
+
+static void Set_FieldState_left(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setLeft(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_top(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Int32::New(tmp->getTop());
+}
+
+static void Set_FieldState_top(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setTop(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_right(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Int32::New(tmp->getRight());
+}
+
+static void Set_FieldState_right(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setRight(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_bottom(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Int32::New(tmp->getBottom());
+}
+
+static void Set_FieldState_bottom(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setBottom(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FieldState_visible(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ return Boolean::New(tmp->isVisible());
+}
+
+static void Set_FieldState_visible(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FieldState *tmp = (FieldState *) wrap->Value();
+ tmp->setVisible(value->BooleanValue());
+}
+
+
+void AddFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ 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);
+}
diff --git a/Plugins/skins/SkinLib/FieldState_v8_wrapper.h b/Plugins/skins/SkinLib/FieldState_v8_wrapper.h new file mode 100644 index 0000000..10c2a85 --- /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 0000000..fdf1e09 --- /dev/null +++ b/Plugins/skins/SkinLib/FontState.cpp @@ -0,0 +1,185 @@ +#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;
+ 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 0000000..de32bcd --- /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 0000000..38e3390 --- /dev/null +++ b/Plugins/skins/SkinLib/FontState_v8_wrapper.cpp @@ -0,0 +1,128 @@ +#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)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ return String::New((const V8_TCHAR *) tmp->getFace());
+}
+
+static void Set_FontState_face(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ String::Utf8Value utf8_value(value);
+ tmp->setFace(Utf8ToTchar(*utf8_value));
+}
+
+
+static Handle<Value> Get_FontState_size(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ return Int32::New(tmp->getSize());
+}
+
+static void Set_FontState_size(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ tmp->setSize(value->Int32Value());
+}
+
+
+static Handle<Value> Get_FontState_italic(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ return Boolean::New(tmp->isItalic());
+}
+
+static void Set_FontState_italic(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ tmp->setItalic(value->BooleanValue());
+}
+
+
+static Handle<Value> Get_FontState_bold(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ return Boolean::New(tmp->isBold());
+}
+
+static void Set_FontState_bold(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ tmp->setBold(value->BooleanValue());
+}
+
+
+static Handle<Value> Get_FontState_underline(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ return Boolean::New(tmp->isUnderline());
+}
+
+static void Set_FontState_underline(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ tmp->setUnderline(value->BooleanValue());
+}
+
+
+static Handle<Value> Get_FontState_strikeOut(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ return Boolean::New(tmp->isStrikeOut());
+}
+
+static void Set_FontState_strikeOut(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ FontState *tmp = (FontState *) wrap->Value();
+ tmp->setStrikeOut(value->BooleanValue());
+}
+
+
+void AddFontStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ 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);
+}
diff --git a/Plugins/skins/SkinLib/FontState_v8_wrapper.h b/Plugins/skins/SkinLib/FontState_v8_wrapper.h new file mode 100644 index 0000000..4b0483f --- /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 0000000..2a6054c --- /dev/null +++ b/Plugins/skins/SkinLib/IconField.cpp @@ -0,0 +1,37 @@ +#include "globals.h"
+#include "IconField.h"
+#include "IconFieldState.h"
+
+
+IconField::IconField(const char *name) : Field(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()
+{
+ return new IconFieldState(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 0000000..730f477 --- /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(const char *name);
+ virtual ~IconField();
+
+ virtual FieldType getType() const;
+
+ virtual HICON getIcon() const;
+ virtual void setIcon(HICON hIcon);
+
+ virtual FieldState * createState();
+
+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 0000000..1a89fb8 --- /dev/null +++ b/Plugins/skins/SkinLib/IconFieldState.cpp @@ -0,0 +1,31 @@ +#include "globals.h"
+#include "IconFieldState.h"
+
+#define ICON_SIZE 16
+
+
+IconFieldState::IconFieldState(IconField *field) : FieldState(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();
+}
diff --git a/Plugins/skins/SkinLib/IconFieldState.h b/Plugins/skins/SkinLib/IconFieldState.h new file mode 100644 index 0000000..9519d71 --- /dev/null +++ b/Plugins/skins/SkinLib/IconFieldState.h @@ -0,0 +1,26 @@ +#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;
+
+private:
+ IconFieldState(IconField *field);
+
+ friend class IconField;
+};
+
+
+#endif // __ICON_FIELD_STATE_H__
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/ImageField.cpp b/Plugins/skins/SkinLib/ImageField.cpp new file mode 100644 index 0000000..8e6dd4b --- /dev/null +++ b/Plugins/skins/SkinLib/ImageField.cpp @@ -0,0 +1,37 @@ +#include "globals.h"
+#include "ImageField.h"
+#include "ImageFieldState.h"
+
+
+ImageField::ImageField(const char *name) : Field(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()
+{
+ return new ImageFieldState(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 0000000..486d5c2 --- /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(const char *name);
+ virtual ~ImageField();
+
+ virtual FieldType getType() const;
+
+ virtual HBITMAP getImage() const;
+ virtual void setImage(HBITMAP hBmp);
+
+ virtual FieldState * createState();
+
+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 0000000..95d244c --- /dev/null +++ b/Plugins/skins/SkinLib/ImageFieldState.cpp @@ -0,0 +1,31 @@ +#include "globals.h"
+#include "ImageFieldState.h"
+
+
+ImageFieldState::ImageFieldState(ImageField *field) : FieldState(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();
+}
\ 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 0000000..faba7cc --- /dev/null +++ b/Plugins/skins/SkinLib/ImageFieldState.h @@ -0,0 +1,26 @@ +#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;
+
+private:
+ ImageFieldState(ImageField *field);
+
+ friend class ImageField;
+};
+
+
+#endif // __IMAGE_FIELD_STATE_H__
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/LabelField.cpp b/Plugins/skins/SkinLib/LabelField.cpp new file mode 100644 index 0000000..162ccc2 --- /dev/null +++ b/Plugins/skins/SkinLib/LabelField.cpp @@ -0,0 +1,22 @@ +#include "globals.h"
+#include "LabelField.h"
+#include "LabelFieldState.h"
+
+
+LabelField::LabelField(const char *name, HWND hwnd) : ControlField(name, hwnd)
+{
+}
+
+LabelField::~LabelField()
+{
+}
+
+FieldType LabelField::getType() const
+{
+ return CONTROL_LABEL;
+}
+
+FieldState * LabelField::createState()
+{
+ return new LabelFieldState(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 0000000..b62d1aa --- /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(const char *name, HWND hwnd);
+ virtual ~LabelField();
+
+ virtual FieldType getType() const;
+
+ virtual FieldState * createState();
+};
+
+
+
+#endif // __LABEL_FIELD_H__
diff --git a/Plugins/skins/SkinLib/LabelFieldState.cpp b/Plugins/skins/SkinLib/LabelFieldState.cpp new file mode 100644 index 0000000..dd00ce7 --- /dev/null +++ b/Plugins/skins/SkinLib/LabelFieldState.cpp @@ -0,0 +1,29 @@ +#include "globals.h"
+#include "LabelFieldState.h"
+
+
+LabelFieldState::LabelFieldState(LabelField *field) : ControlFieldState(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;
+}
\ 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 0000000..7596322 --- /dev/null +++ b/Plugins/skins/SkinLib/LabelFieldState.h @@ -0,0 +1,23 @@ +#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;
+
+private:
+ LabelFieldState(LabelField *field);
+
+ friend class LabelField;
+};
+
+
+
+#endif // __LABEL_FIELD_STATE_H__
diff --git a/Plugins/skins/SkinLib/Position.cpp b/Plugins/skins/SkinLib/Position.cpp new file mode 100644 index 0000000..6c68881 --- /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 0000000..ed43a1e --- /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 0000000..9c2eef5 --- /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 0000000..8c0a297 --- /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 0000000..7812303 --- /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 0000000..61e1c14 --- /dev/null +++ b/Plugins/skins/SkinLib/SkinOption_v8_wrapper.cpp @@ -0,0 +1,105 @@ +#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)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ return String::New((const V8_TCHAR *) tmp->getDescription());
+}
+
+static void Set_SkinOption_description(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ String::Utf8Value utf8_value(value);
+ tmp->setDescription(Utf8ToTchar(*utf8_value));
+}
+
+
+static Handle<Value> Get_SkinOption_min(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ return Int32::New(tmp->getMin());
+}
+
+static void Set_SkinOption_min(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ tmp->setMin(value->Int32Value());
+}
+
+
+static Handle<Value> Get_SkinOption_max(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ return Int32::New(tmp->getMax());
+}
+
+static void Set_SkinOption_max(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ tmp->setMax(value->Int32Value());
+}
+
+
+static Handle<Value> Get_SkinOption_type(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ switch(tmp->getType())
+ {
+ case CHECKBOX: return String::New((const V8_TCHAR *) _T("CHECKBOX"));
+ case NUMBER: return String::New((const V8_TCHAR *) _T("NUMBER"));
+ case TEXT: return String::New((const V8_TCHAR *) _T("TEXT"));
+ }
+ return Undefined();
+}
+
+static void Set_SkinOption_type(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *tmp = (SkinOption *) wrap->Value();
+ 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)
+{
+ 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 0000000..6aa05c2 --- /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 0000000..9aa8db4 --- /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()
+{
+ 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 0000000..f6a27da --- /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();
+ 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 0000000..34a4294 --- /dev/null +++ b/Plugins/skins/SkinLib/SkinnedDialog.cpp @@ -0,0 +1,252 @@ +#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)
+ : dlg(name), fileChangedTime(0),
+ script(NULL), state(NULL), opts(NULL),
+ errorCallback(NULL), errorCallbackParam(NULL),
+ traceCallback(NULL), traceCallbackParam(NULL)
+{
+}
+
+SkinnedDialog::~SkinnedDialog()
+{
+ releaseState();
+ releaseCompiledScript();
+}
+
+const TCHAR * SkinnedDialog::getFilename() const
+{
+ return filename.c_str();
+}
+
+void SkinnedDialog::setFilename(const char *skin, const TCHAR *filename)
+{
+ this->skin = skin;
+
+ if (this->filename == filename)
+ return;
+
+ this->filename = filename;
+ releaseState();
+ releaseCompiledScript();
+}
+
+bool SkinnedDialog::addField(Field *field)
+{
+ if (dlg.addField(field))
+ {
+ releaseCompiledScript();
+ releaseState();
+ field->setOnChangeCallback(SkinnedDialog::staticOnFieldChange, this);
+ return true;
+ }
+ else
+ return false;
+}
+
+Field * SkinnedDialog::getField(const char *name) const
+{
+ return dlg.getField(name);
+}
+
+Field * SkinnedDialog::getField(unsigned int pos) const
+{
+ if (pos >= dlg.fields.size())
+ return NULL;
+ return dlg.fields[pos];
+}
+
+int SkinnedDialog::getFieldCount() const
+{
+ return dlg.fields.size();
+}
+
+const Size & SkinnedDialog::getSize() const
+{
+ return dlg.getSize();
+}
+
+void SkinnedDialog::setSize(const Size &size)
+{
+ if (dlg.getSize() == size)
+ return;
+
+ dlg.setSize(size);
+ releaseState();
+}
+
+DialogState * SkinnedDialog::getState()
+{
+ bool changed = fileChanged();
+ if (state != NULL && !changed)
+ return state;
+
+ releaseState();
+
+ if (filename.size() <= 0)
+ return NULL;
+
+ if (changed || script == NULL)
+ {
+ releaseCompiledScript();
+
+ struct _stat st = {0};
+ if (_tstat(filename.c_str(), &st) != 0)
+ return NULL;
+
+ std::tstring text;
+ readFile(text);
+ if (text.size() <= 0)
+ return NULL;
+
+ script = new V8Script();
+ script->setExceptionCallback(errorCallback, errorCallbackParam);
+
+ if (!script->compile(text.c_str(), &dlg))
+ {
+ releaseCompiledScript();
+ return NULL;
+ }
+
+ opts = script->createOptions(&dlg);
+ if (opts == NULL)
+ {
+ releaseCompiledScript();
+ return NULL;
+ }
+
+ fileChangedTime = st.st_mtime;
+ }
+
+ state = dlg.createState();
+ if (!script->run(state, opts))
+ {
+ releaseState();
+ return NULL;
+ }
+
+ return state;
+}
+
+void SkinnedDialog::releaseCompiledScript()
+{
+ delete script;
+ script = NULL;
+
+ delete opts;
+ opts = NULL;
+}
+
+void SkinnedDialog::releaseState()
+{
+ delete state;
+ state = NULL;
+}
+
+DialogState * SkinnedDialog::createState(const TCHAR *text, MessageCallback errorCallback, void *errorCallbackParam)
+{
+ V8Script script;
+ script.setExceptionCallback(errorCallback, errorCallbackParam);
+
+ if (!script.compile(text, &dlg))
+ return NULL;
+
+ DialogState *state = dlg.createState();
+ if (!script.run(state, opts))
+ {
+ delete state;
+ return NULL;
+ }
+
+ return state;
+}
+
+
+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);
+}
\ 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 0000000..54c0887 --- /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"
+
+class V8Script;
+class SkinOptions;
+
+typedef void (*MessageCallback)(void *param, const TCHAR *err);
+
+
+
+class SkinnedDialog
+{
+public:
+ SkinnedDialog(const char *name);
+ ~SkinnedDialog();
+
+ const TCHAR * getFilename() const;
+ void setFilename(const char *skin, const TCHAR *filename);
+
+ bool addField(Field *field);
+ Field * getField(const char *name) const;
+ Field * getField(unsigned int pos) const;
+ int getFieldCount() const;
+
+ const Size & getSize() const;
+ 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.
+ DialogState * getState();
+
+ /// Create a state based on the script passed in text. the caller have to free the DialogState *
+ DialogState * createState(const TCHAR *text, MessageCallback errorCallback = NULL, void *errorCallbackParam = NULL);
+
+ void setErrorCallback(MessageCallback cb, void *param = NULL);
+ void setTraceCallback(MessageCallback cb, void *param = NULL);
+
+private:
+ Dialog dlg;
+ std::string skin;
+ std::tstring filename;
+ __time64_t fileChangedTime;
+ V8Script *script;
+ DialogState *state;
+ SkinOptions *opts;
+
+ MessageCallback errorCallback;
+ void *errorCallbackParam;
+ MessageCallback traceCallback;
+ void *traceCallbackParam;
+
+ void releaseCompiledScript();
+ void releaseState();
+ bool fileChanged();
+ void readFile(std::tstring &ret);
+
+ void trace(TCHAR *msg, ...);
+
+ void onFieldChange(const Field *field);
+
+ 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 0000000..69f9bfe --- /dev/null +++ b/Plugins/skins/SkinLib/TextField.cpp @@ -0,0 +1,77 @@ +#include "globals.h"
+#include "TextField.h"
+#include "TextFieldState.h"
+
+
+TextField::TextField(const char *name) : Field(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()
+{
+ return new TextFieldState(this);
+}
diff --git a/Plugins/skins/SkinLib/TextField.h b/Plugins/skins/SkinLib/TextField.h new file mode 100644 index 0000000..5a4ee8f --- /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(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();
+
+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 0000000..5014a04 --- /dev/null +++ b/Plugins/skins/SkinLib/TextFieldState.cpp @@ -0,0 +1,58 @@ +#include "globals.h"
+#include "TextFieldState.h"
+
+
+TextFieldState::TextFieldState(TextField *field) : FieldState(field), font(field->getFont(), field->getFontColor())
+{
+}
+
+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;
+}
+
+FontState * TextFieldState::getFont()
+{
+ return &font;
+}
+
+const FontState * TextFieldState::getFont() const
+{
+ return &font;
+}
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/TextFieldState.h b/Plugins/skins/SkinLib/TextFieldState.h new file mode 100644 index 0000000..17d0a82 --- /dev/null +++ b/Plugins/skins/SkinLib/TextFieldState.h @@ -0,0 +1,36 @@ +#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;
+
+private:
+ TextFieldState(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 0000000..d8698be --- /dev/null +++ b/Plugins/skins/SkinLib/TextFieldState_v8_wrapper.cpp @@ -0,0 +1,38 @@ +#include "globals.h"
+#include "TextFieldState_v8_wrapper.h"
+#include <v8.h>
+#include "TextFieldState.h"
+#include "utf8_helpers.h"
+
+using namespace v8;
+
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+
+static Handle<Value> Get_TextFieldState_text(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ TextFieldState *tmp = (TextFieldState *) wrap->Value();
+ return String::New((const V8_TCHAR *) tmp->getText());
+}
+
+static void Set_TextFieldState_text(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ TextFieldState *tmp = (TextFieldState *) wrap->Value();
+ String::Utf8Value utf8_value(value);
+ tmp->setText(Utf8ToTchar(*utf8_value));
+}
+
+
+void AddTextFieldStateAcessors(Handle<ObjectTemplate> &templ)
+{
+ 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 0000000..c5d9e48 --- /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 0000000..9fa5767 --- /dev/null +++ b/Plugins/skins/SkinLib/V8Script.cpp @@ -0,0 +1,220 @@ +#include "globals.h"
+#include "V8Script.h"
+
+#include "utf8_helpers.h"
+
+using namespace v8;
+
+
+
+V8Script::V8Script() : exceptionCallback(NULL), exceptionCallbackParam(NULL)
+{
+}
+
+V8Script::~V8Script()
+{
+ dispose();
+}
+
+bool V8Script::compile(const TCHAR *source, Dialog *dlg)
+{
+ dispose();
+
+ HandleScope handle_scope;
+
+ context = Context::New();
+
+ Context::Scope context_scope(context);
+
+ context->Global()->Set(String::New("window"), wrappers.createDialogWrapper(), ReadOnly);
+ context->Global()->Set(String::New("opts"), wrappers.createOptionsWrapper(), ReadOnly);
+ for(unsigned int i = 0; i < dlg->fields.size(); i++)
+ {
+ Field *field = dlg->fields[i];
+ context->Global()->Set(String::New(field->getName()), wrappers.createWrapper(field->getType()), ReadOnly);
+ }
+ wrappers.clearTemplates();
+
+ TryCatch try_catch;
+ Local<Script> tmpScript = Script::Compile(String::New((const V8_TCHAR *) source), String::New(dlg->getName()));
+ if (tmpScript.IsEmpty())
+ {
+ reportException(&try_catch);
+ dispose();
+ return false;
+ }
+
+ script = Persistent<Script>::New(tmpScript);
+
+ return true;
+}
+
+void V8Script::dispose()
+{
+ script.Dispose();
+ script.Clear();
+
+ context.Dispose();
+ context.Clear();
+}
+
+bool V8Script::isValid()
+{
+ return !context.IsEmpty() && !script.IsEmpty();
+}
+
+static Handle<Object> get(Local<Object> obj, const char *field)
+{
+ return Handle<Object>::Cast(obj->Get(String::New(field)));
+}
+
+Handle<Function> V8Script::getOptionsFunction(Dialog *dlg)
+{
+ DialogState *state = dlg->createState();
+
+ HandleScope handle_scope;
+
+ Context::Scope context_scope(context);
+
+ // Run once to get function
+ Local<Object> global = context->Global();
+ wrappers.fillWrapper(get(global, "window"), state);
+ wrappers.fillWrapper(get(global, "opts"), (SkinOptions *) NULL, false);
+ for(unsigned int i = 0; i < state->fields.size(); i++)
+ {
+ FieldState *field = state->fields[i];
+ wrappers.fillWrapper(get(global, field->getField()->getName()), field);
+ }
+
+ // I don't care for the catch here
+ TryCatch try_catch;
+ script->Run();
+
+ delete state;
+
+ Handle<Value> options_val = context->Global()->Get(String::New("options"));
+ if (options_val.IsEmpty() || !options_val->IsFunction())
+ return Handle<Function>();
+
+ Handle<Function> options = Handle<Function>::Cast(options_val);
+
+ return handle_scope.Close(options);
+}
+
+SkinOptions * V8Script::createOptions(Dialog *dlg)
+{
+ if (!isValid())
+ return NULL;
+
+ SkinOptions *opts = new SkinOptions();
+
+ HandleScope handle_scope;
+
+ Context::Scope context_scope(context);
+
+ Handle<Function> options = getOptionsFunction(dlg);
+ if (options.IsEmpty())
+ return opts;
+
+ Local<Object> global = context->Global();
+ wrappers.fillWrapper(get(global, "opts"), opts, true);
+
+ global->Set(String::New("NUMBER"), String::New("NUMBER"));
+ global->Set(String::New("CHECKBOX"), String::New("CHECKBOX"));
+ global->Set(String::New("TEXT"), String::New("TEXT"));
+
+ TryCatch try_catch;
+ Handle<Value> result = options->Call(global, 0, NULL);
+ if (result.IsEmpty())
+ {
+ reportException(&try_catch);
+ delete opts;
+ return NULL;
+ }
+
+ return opts;
+}
+
+bool V8Script::run(DialogState * state, SkinOptions *opts)
+{
+ if (!isValid())
+ return false;
+
+ HandleScope handle_scope;
+
+ Context::Scope context_scope(context);
+
+ Local<Object> global = context->Global();
+
+ wrappers.fillWrapper(get(global, "window"), state);
+ wrappers.fillWrapper(get(global, "opts"), opts, false);
+ for(unsigned int i = 0; i < state->fields.size(); i++)
+ {
+ FieldState *field = state->fields[i];
+ wrappers.fillWrapper(get(global, field->getField()->getName()), field);
+ }
+
+ TryCatch try_catch;
+ Handle<Value> result = script->Run();
+ 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 0000000..2611f47 --- /dev/null +++ b/Plugins/skins/SkinLib/V8Script.h @@ -0,0 +1,41 @@ +#ifndef __V8_SCRIPT_H__
+# define __V8_SCRIPT_H__
+
+#include <v8.h>
+#include "V8Wrappers.h"
+
+typedef void (*ExceptionCallback)(void *param, const TCHAR *err);
+
+
+class V8Script
+{
+public:
+ V8Script();
+ ~V8Script();
+
+ bool compile(const TCHAR *source, Dialog *dlg);
+ void dispose();
+
+ bool isValid();
+
+ SkinOptions * createOptions(Dialog *dlg);
+
+ bool run(DialogState * state, SkinOptions *opts);
+
+ void setExceptionCallback(ExceptionCallback cb, void *param = NULL);
+
+private:
+ V8Wrappers wrappers;
+ v8::Persistent<v8::Context> context;
+ v8::Persistent<v8::Script> script;
+
+ ExceptionCallback exceptionCallback;
+ void *exceptionCallbackParam;
+
+ v8::Handle<v8::Function> getOptionsFunction(Dialog *dlg);
+ void reportException(v8::TryCatch *try_catch);
+};
+
+
+
+#endif // __V8_SCRIPT_H__
diff --git a/Plugins/skins/SkinLib/V8Wrappers.cpp b/Plugins/skins/SkinLib/V8Wrappers.cpp new file mode 100644 index 0000000..79d96bc --- /dev/null +++ b/Plugins/skins/SkinLib/V8Wrappers.cpp @@ -0,0 +1,532 @@ +#include "globals.h"
+#include "V8Wrappers.h"
+
+#include "FieldState_v8_wrapper.h"
+#include "ControlFieldState_v8_wrapper.h"
+#include "TextFieldState_v8_wrapper.h"
+#include "FontState_v8_wrapper.h"
+#include "DialogState_v8_wrapper.h"
+#include "BorderState_v8_wrapper.h"
+#include "SkinOption_v8_wrapper.h"
+#include "utf8_helpers.h"
+
+
+#define OPTION (USER_DEFINED-5)
+#define OPTIONS (USER_DEFINED-4)
+#define BORDER (USER_DEFINED-3)
+#define FONT (USER_DEFINED-2)
+#define DIALOG (USER_DEFINED-1)
+
+
+using namespace v8;
+
+
+void V8Wrappers::createTemplateFor(FieldType type)
+{
+ switch(type)
+ {
+ case SIMPLE_TEXT:
+ createTextTemplate();
+ break;
+ case SIMPLE_IMAGE:
+ createImageTemplate();
+ break;
+ case SIMPLE_ICON:
+ createIconTemplate();
+ break;
+ case CONTROL_LABEL:
+ createLabelTemplate();
+ break;
+ case CONTROL_BUTTON:
+ createButtonTemplate();
+ break;
+ case CONTROL_EDIT:
+ createEditTemplate();
+ break;
+ }
+}
+
+
+static Handle<Value> Get_DialogState_borders(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ return self->GetInternalField(1);
+}
+
+
+static void Set_DialogState_borders(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ DialogState *tmp = (DialogState *) wrap->Value();
+ tmp->getBorders()->setAll(value->Int32Value());
+}
+
+
+void V8Wrappers::createDialogTemplate()
+{
+ if (templs.find(DIALOG) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(2);
+ AddDialogStateAcessors(templ);
+ templ->SetAccessor(String::New("borders"), Get_DialogState_borders, Set_DialogState_borders);
+ templs[DIALOG] = templ;
+
+ createBorderTemplate();
+}
+
+
+void V8Wrappers::createTextTemplate()
+{
+ if (templs.find(SIMPLE_TEXT) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddFieldStateAcessors(templ);
+ AddTextFieldStateAcessors(templ);
+ templs[SIMPLE_TEXT] = templ;
+
+ createFontTemplate();
+}
+
+void V8Wrappers::createImageTemplate()
+{
+ if (templs.find(SIMPLE_IMAGE) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddFieldStateAcessors(templ);
+ templs[SIMPLE_IMAGE] = templ;
+}
+
+void V8Wrappers::createIconTemplate()
+{
+ if (templs.find(SIMPLE_ICON) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddFieldStateAcessors(templ);
+ templs[SIMPLE_ICON] = templ;
+}
+
+void V8Wrappers::createLabelTemplate()
+{
+ if (templs.find(CONTROL_LABEL) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddFieldStateAcessors(templ);
+ AddControlFieldStateAcessors(templ);
+ templs[CONTROL_LABEL] = templ;
+
+ createFontTemplate();
+}
+
+void V8Wrappers::createButtonTemplate()
+{
+ if (templs.find(CONTROL_BUTTON) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddFieldStateAcessors(templ);
+ AddControlFieldStateAcessors(templ);
+ templs[CONTROL_BUTTON] = templ;
+
+ createFontTemplate();
+}
+
+void V8Wrappers::createEditTemplate()
+{
+ if (templs.find(CONTROL_EDIT) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddFieldStateAcessors(templ);
+ AddControlFieldStateAcessors(templ);
+ templs[CONTROL_EDIT] = templ;
+
+ createFontTemplate();
+}
+
+void V8Wrappers::createFontTemplate()
+{
+ if (templs.find(FONT) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddFontStateAcessors(templ);
+ templs[FONT] = templ;
+}
+
+
+void V8Wrappers::createBorderTemplate()
+{
+ if (templs.find(BORDER) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddBorderStateAcessors(templ);
+ templs[BORDER] = templ;
+}
+
+
+Handle<Object> V8Wrappers::createWrapper(FieldType type)
+{
+ createTemplateFor(type);
+
+ switch(type)
+ {
+ case SIMPLE_TEXT:
+ return createTextWrapper();
+ break;
+ case SIMPLE_IMAGE:
+ return createImageWrapper();
+ break;
+ case SIMPLE_ICON:
+ return createIconWrapper();
+ break;
+ case CONTROL_LABEL:
+ return createLabelWrapper();
+ break;
+ case CONTROL_BUTTON:
+ return createButtonWrapper();
+ break;
+ case CONTROL_EDIT:
+ return createEditWrapper();
+ break;
+ }
+ throw "Unknown type";
+}
+
+Handle<Object> V8Wrappers::fillWrapper(Handle<Object> obj, FieldState *state)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ switch(state->getField()->getType())
+ {
+ case SIMPLE_TEXT:
+ return fillTextWrapper(obj, (TextFieldState *) state);
+ break;
+ case SIMPLE_IMAGE:
+ return fillImageWrapper(obj, (ImageFieldState *) state);
+ break;
+ case SIMPLE_ICON:
+ return fillIconWrapper(obj, (IconFieldState *) state);
+ break;
+ case CONTROL_LABEL:
+ return fillLabelWrapper(obj, (LabelFieldState *) state);
+ break;
+ case CONTROL_BUTTON:
+ return fillButtonWrapper(obj, (ButtonFieldState *) state);
+ break;
+ case CONTROL_EDIT:
+ return fillEditWrapper(obj, (EditFieldState *) state);
+ break;
+ }
+ throw "Unknown type";
+}
+
+Handle<Object> V8Wrappers::createDialogWrapper()
+{
+ createDialogTemplate();
+
+ Handle<Object> obj = newInstance(DIALOG);
+ Handle<Object> borders = newInstance(BORDER);
+ obj->SetInternalField(1, borders);
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::fillWrapper(Handle<Object> obj, DialogState *state)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(state));
+
+ Handle<Object> borders = Handle<Object>::Cast(obj->GetInternalField(1));
+ borders->SetInternalField(0, External::New(state->getBorders()));
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::newInstance(int type)
+{
+ if (templs.find(type) == templs.end())
+ throw "Unknown template";
+
+ return templs[type]->NewInstance();
+}
+
+Handle<Object> V8Wrappers::createTextWrapper()
+{
+ Handle<Object> obj = newInstance(SIMPLE_TEXT);
+
+ Handle<Object> font = newInstance(FONT);
+ obj->Set(String::New("font"), font, ReadOnly);
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::fillTextWrapper(Handle<Object> obj, TextFieldState *state)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(state));
+
+ Handle<Object> font = Handle<Object>::Cast(obj->Get(String::New("font")));
+ font->SetInternalField(0, External::New(state->getFont()));
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::createIconWrapper()
+{
+ return newInstance(SIMPLE_ICON);
+}
+
+Handle<Object> V8Wrappers::fillIconWrapper(Handle<Object> obj, IconFieldState *state)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(state));
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::createImageWrapper()
+{
+ return newInstance(SIMPLE_IMAGE);
+}
+
+Handle<Object> V8Wrappers::fillImageWrapper(Handle<Object> obj, ImageFieldState *state)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(state));
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::createLabelWrapper()
+{
+ Handle<Object> obj = newInstance(CONTROL_LABEL);
+
+ Handle<Object> font = newInstance(FONT);
+ obj->Set(String::New("font"), font, ReadOnly);
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::fillLabelWrapper(Handle<Object> obj, LabelFieldState *state)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(state));
+
+ Handle<Object> font = Handle<Object>::Cast(obj->Get(String::New("font")));
+ font->SetInternalField(0, External::New(state->getFont()));
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::createButtonWrapper()
+{
+ Handle<Object> obj = newInstance(CONTROL_BUTTON);
+
+ Handle<Object> font = newInstance(FONT);
+ obj->Set(String::New("font"), font, ReadOnly);
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::fillButtonWrapper(Handle<Object> obj, ButtonFieldState *state)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(state));
+
+ Handle<Object> font = Handle<Object>::Cast(obj->Get(String::New("font")));
+ font->SetInternalField(0, External::New(state->getFont()));
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::createEditWrapper()
+{
+ Handle<Object> obj = newInstance(CONTROL_EDIT);
+
+ Handle<Object> font = newInstance(FONT);
+ obj->Set(String::New("font"), font, ReadOnly);
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::fillEditWrapper(Handle<Object> obj, EditFieldState *state)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(state));
+
+ Handle<Object> font = Handle<Object>::Cast(obj->Get(String::New("font")));
+ font->SetInternalField(0, External::New(state->getFont()));
+
+ return obj;
+}
+
+void V8Wrappers::clearTemplates()
+{
+ templs.clear();
+}
+
+
+static Handle<Value> Get_Options_Fields(Local<String> aName, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOptions *opts = (SkinOptions *) wrap->Value();
+ if (opts == NULL)
+ return Undefined();
+
+ String::AsciiValue name(aName);
+ if (name.length() <= 0)
+ return Undefined();
+
+ bool configure = self->GetInternalField(1)->BooleanValue();
+ if (configure)
+ {
+ SkinOption * opt = opts->getOption(*name);
+
+ if (opt == NULL)
+ {
+ opt = new SkinOption(*name);
+ opts->addOption(opt);
+ }
+
+ V8Wrappers wrappers;
+ return wrappers.fillWrapper(wrappers.createOptionWrapper(), opt);
+ }
+ else
+ {
+ SkinOption * opt = opts->getOption(*name);
+ if (opt == NULL)
+ return Undefined();
+
+ switch (opt->getType())
+ {
+ case CHECKBOX: return Boolean::New(opt->getValueCheckbox());
+ case NUMBER: return Int32::New(opt->getValueNumber());
+ case TEXT: return String::New((const V8_TCHAR *) opt->getValueText());
+ }
+
+ return Undefined();
+ }
+}
+
+void V8Wrappers::createOptionsTemplate()
+{
+ if (templs.find(OPTIONS) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(2);
+ templ->SetNamedPropertyHandler(&Get_Options_Fields);
+ templs[OPTIONS] = templ;
+}
+
+Handle<Object> V8Wrappers::createOptionsWrapper()
+{
+ createOptionsTemplate();
+
+ return newInstance(OPTIONS);
+}
+
+static Handle<Value> Get_SkinOption_value(Local<String> property, const AccessorInfo &info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *opt = (SkinOption *) wrap->Value();
+ switch (opt->getType())
+ {
+ case CHECKBOX: return Boolean::New(opt->getValueCheckbox());
+ case NUMBER: return Int32::New(opt->getValueNumber());
+ case TEXT: return String::New((const V8_TCHAR *) opt->getValueText());
+ }
+ return Undefined();
+}
+
+static void Set_SkinOption_value(Local<String> property, Local<Value> value, const AccessorInfo& info)
+{
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ SkinOption *opt = (SkinOption *) wrap->Value();
+ switch (opt->getType())
+ {
+ case CHECKBOX:
+ opt->setValueCheckbox(value->BooleanValue());
+ break;
+ case NUMBER:
+ opt->setValueNumber(value->Int32Value());
+ break;
+ case TEXT:
+ opt->setValueText(Utf8ToTchar(*String::Utf8Value(value)));
+ break;
+ }
+}
+
+void V8Wrappers::createOptionTemplate()
+{
+ if (templs.find(OPTION) != templs.end())
+ return;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(1);
+ AddSkinOptionAcessors(templ);
+ templ->SetAccessor(String::New("value"), Get_SkinOption_value, Set_SkinOption_value);
+ templs[OPTION] = templ;
+}
+
+Handle<Object> V8Wrappers::createOptionWrapper()
+{
+ createOptionTemplate();
+
+ return newInstance(OPTION);
+}
+
+Handle<Object> V8Wrappers::fillWrapper(Handle<Object> obj, SkinOptions *opts, bool configure)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(opts));
+ obj->SetInternalField(1, Boolean::New(configure));
+
+ return obj;
+}
+
+Handle<Object> V8Wrappers::fillWrapper(Handle<Object> obj, SkinOption *opt)
+{
+ if (obj.IsEmpty())
+ throw "Empty object";
+
+ obj->SetInternalField(0, External::New(opt));
+
+ return obj;
+}
\ No newline at end of file diff --git a/Plugins/skins/SkinLib/V8Wrappers.h b/Plugins/skins/SkinLib/V8Wrappers.h new file mode 100644 index 0000000..01781f7 --- /dev/null +++ b/Plugins/skins/SkinLib/V8Wrappers.h @@ -0,0 +1,73 @@ +#ifndef __V8_WRAPPERS_H__
+# define __V8_WRAPPERS_H__
+
+#include <v8.h>
+#include <map>
+#include "DialogState.h"
+#include "TextFieldState.h"
+#include "ImageFieldState.h"
+#include "IconFieldState.h"
+#include "LabelFieldState.h"
+#include "ButtonFieldState.h"
+#include "EditFieldState.h"
+#include "SkinOptions.h"
+
+#ifdef UNICODE
+# define V8_TCHAR uint16_t
+#else
+# define V8_TCHAR char
+#endif
+
+class V8Wrappers
+{
+public:
+ v8::Handle<v8::Object> createDialogWrapper();
+ v8::Handle<v8::Object> createOptionsWrapper();
+ v8::Handle<v8::Object> createOptionWrapper();
+ v8::Handle<v8::Object> createWrapper(FieldType type);
+
+ v8::Handle<v8::Object> fillWrapper(v8::Handle<v8::Object> obj, FieldState *state);
+ v8::Handle<v8::Object> fillWrapper(v8::Handle<v8::Object> obj, DialogState *state);
+ v8::Handle<v8::Object> fillWrapper(v8::Handle<v8::Object> obj, SkinOptions *opts, bool configure);
+ v8::Handle<v8::Object> fillWrapper(v8::Handle<v8::Object> obj, SkinOption *opt);
+
+ void clearTemplates();
+
+private:
+ std::map<int, v8::Handle<v8::ObjectTemplate>> templs;
+
+ void createDialogTemplate();
+ void createOptionsTemplate();
+ void createOptionTemplate();
+ void createTemplateFor(FieldType type);
+
+ void createTextTemplate();
+ void createImageTemplate();
+ void createIconTemplate();
+ void createLabelTemplate();
+ void createButtonTemplate();
+ void createEditTemplate();
+ void createFontTemplate();
+ void createBorderTemplate();
+
+ v8::Handle<v8::Object> createTextWrapper();
+ v8::Handle<v8::Object> createImageWrapper();
+ v8::Handle<v8::Object> createIconWrapper();
+ v8::Handle<v8::Object> createLabelWrapper();
+ v8::Handle<v8::Object> createButtonWrapper();
+ v8::Handle<v8::Object> createEditWrapper();
+
+ v8::Handle<v8::Object> fillTextWrapper(v8::Handle<v8::Object> obj, TextFieldState *state);
+ v8::Handle<v8::Object> fillImageWrapper(v8::Handle<v8::Object> obj, ImageFieldState *state);
+ v8::Handle<v8::Object> fillIconWrapper(v8::Handle<v8::Object> obj, IconFieldState *state);
+ v8::Handle<v8::Object> fillLabelWrapper(v8::Handle<v8::Object> obj, LabelFieldState *state);
+ v8::Handle<v8::Object> fillButtonWrapper(v8::Handle<v8::Object> obj, ButtonFieldState *state);
+ v8::Handle<v8::Object> fillEditWrapper(v8::Handle<v8::Object> obj, EditFieldState *state);
+
+ v8::Handle<v8::Object> newInstance(int type);
+
+};
+
+
+
+#endif // __V8_WRAPPERS_H__
diff --git a/Plugins/skins/SkinLib/globals.h b/Plugins/skins/SkinLib/globals.h new file mode 100644 index 0000000..efdfb90 --- /dev/null +++ b/Plugins/skins/SkinLib/globals.h @@ -0,0 +1,11 @@ +#ifndef __GLOBALS_H__
+# define __GLOBALS_H__
+
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.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 0000000..2fad797 --- /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 0000000..e601717 --- /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__
diff --git a/Plugins/skins/SkinLib/utf8_helpers.h b/Plugins/skins/SkinLib/utf8_helpers.h new file mode 100644 index 0000000..204cc26 --- /dev/null +++ b/Plugins/skins/SkinLib/utf8_helpers.h @@ -0,0 +1,124 @@ +#ifndef __UTF8_HELPERS_H__
+# define __UTF8_HELPERS_H__
+
+#include <windows.h>
+#include "scope.h"
+
+
+class TcharToUtf8
+{
+public:
+ TcharToUtf8(const char *str) : utf8(NULL)
+ {
+ int size = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+ if (size <= 0)
+ throw _T("Could not convert string to WCHAR");
+
+ scope<WCHAR *> tmp = (WCHAR *) malloc(size * sizeof(WCHAR));
+ if (tmp == NULL)
+ throw _T("malloc returned NULL");
+
+ MultiByteToWideChar(CP_ACP, 0, str, -1, tmp, size);
+
+ init(tmp);
+ }
+
+
+ TcharToUtf8(const WCHAR *str) : utf8(NULL)
+ {
+ init(str);
+ }
+
+
+ ~TcharToUtf8()
+ {
+ if (utf8 != NULL)
+ free(utf8);
+ }
+
+ operator char *()
+ {
+ return utf8;
+ }
+
+private:
+ char *utf8;
+
+ void init(const WCHAR *str)
+ {
+ int size = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL);
+ if (size <= 0)
+ throw _T("Could not convert string to UTF8");
+
+ utf8 = (char *) malloc(size);
+ if (utf8 == NULL)
+ throw _T("malloc returned NULL");
+
+ WideCharToMultiByte(CP_UTF8, 0, str, -1, utf8, size, NULL, NULL);
+ }
+};
+
+
+
+class Utf8ToTchar
+{
+public:
+ Utf8ToTchar(const char *str) : tchar(NULL)
+ {
+ if (str == NULL)
+ return;
+
+ int size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
+ if (size <= 0)
+ throw _T("Could not convert string to WCHAR");
+
+ scope<WCHAR *> tmp = (WCHAR *) malloc(size * sizeof(WCHAR));
+ if (tmp == NULL)
+ throw _T("malloc returned NULL");
+
+ MultiByteToWideChar(CP_UTF8, 0, str, -1, tmp, size);
+
+#ifdef UNICODE
+
+ tchar = tmp.detach();
+
+#else
+
+ size = WideCharToMultiByte(CP_ACP, 0, tmp, -1, NULL, 0, NULL, NULL);
+ if (size <= 0)
+ throw _T("Could not convert string to ACP");
+
+ tchar = (TCHAR *) malloc(size);
+ if (tchar == NULL)
+ throw _T("malloc returned NULL");
+
+ WideCharToMultiByte(CP_ACP, 0, tmp, -1, tchar, size, NULL, NULL);
+
+#endif
+ }
+
+
+ ~Utf8ToTchar()
+ {
+ if (tchar != NULL)
+ free(tchar);
+ }
+
+ TCHAR *detach()
+ {
+ TCHAR *ret = tchar;
+ tchar = NULL;
+ return ret;
+ }
+
+ operator TCHAR *()
+ {
+ return tchar;
+ }
+
+private:
+ TCHAR *tchar;
+};
+
+
+#endif // __UTF8_HELPERS_H__
\ No newline at end of file |