diff options
75 files changed, 7464 insertions, 8 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 diff --git a/Plugins/skins/libs/v8-debug.h b/Plugins/skins/libs/v8-debug.h new file mode 100644 index 0000000..68f84c4 --- /dev/null +++ b/Plugins/skins/libs/v8-debug.h @@ -0,0 +1,164 @@ +// Copyright 2008 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_DEBUG_H_
+#define V8_DEBUG_H_
+
+#define _CRTDBG_MAP_ALLOC
+#include <stdlib.h>
+#include <crtdbg.h>
+
+#include "v8.h"
+
+#ifdef _WIN32
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef unsigned short uint16_t; // NOLINT
+typedef long long int64_t; // NOLINT
+
+// Setup for Windows DLL export/import. See v8.h in this directory for
+// information on how to build/use V8 as a DLL.
+#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
+#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
+ build configuration to ensure that at most one of these is set
+#endif
+
+#ifdef BUILDING_V8_SHARED
+#define EXPORT __declspec(dllexport)
+#elif USING_V8_SHARED
+#define EXPORT __declspec(dllimport)
+#else
+#define EXPORT
+#endif
+
+#else // _WIN32
+
+// Setup for Linux shared library export. See v8.h in this directory for
+// information on how to build/use V8 as shared library.
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#define EXPORT __attribute__ ((visibility("default")))
+#else // defined(__GNUC__) && (__GNUC__ >= 4)
+#define EXPORT
+#endif // defined(__GNUC__) && (__GNUC__ >= 4)
+
+#endif // _WIN32
+
+
+/**
+ * Debugger support for the V8 JavaScript engine.
+ */
+namespace v8 {
+
+// Debug events which can occur in the V8 JavaScript engine.
+enum DebugEvent {
+ Break = 1,
+ Exception = 2,
+ NewFunction = 3,
+ BeforeCompile = 4,
+ AfterCompile = 5
+};
+
+
+/**
+ * Debug event callback function.
+ *
+ * \param event the type of the debug event that triggered the callback
+ * (enum DebugEvent)
+ * \param exec_state execution state (JavaScript object)
+ * \param event_data event specific data (JavaScript object)
+ * \param data value passed by the user to AddDebugEventListener
+ */
+typedef void (*DebugEventCallback)(DebugEvent event,
+ Handle<Object> exec_state,
+ Handle<Object> event_data,
+ Handle<Value> data);
+
+
+/**
+ * Debug message callback function.
+ *
+ * \param message the debug message
+ * \param length length of the message
+ * A DebugMessageHandler does not take posession of the message string,
+ * and must not rely on the data persisting after the handler returns.
+ */
+typedef void (*DebugMessageHandler)(const uint16_t* message, int length,
+ void* data);
+
+
+class EXPORT Debug {
+ public:
+ // Add a C debug event listener.
+ static bool AddDebugEventListener(DebugEventCallback that,
+ Handle<Value> data = Handle<Value>());
+
+ // Add a JavaScript debug event listener.
+ static bool AddDebugEventListener(v8::Handle<v8::Function> that,
+ Handle<Value> data = Handle<Value>());
+
+ // Remove a C debug event listener.
+ static void RemoveDebugEventListener(DebugEventCallback that);
+
+ // Remove a JavaScript debug event listener.
+ static void RemoveDebugEventListener(v8::Handle<v8::Function> that);
+
+ // Break execution of JavaScript.
+ static void DebugBreak();
+
+ // Message based interface. The message protocol is JSON.
+ static void SetMessageHandler(DebugMessageHandler handler, void* data = NULL);
+ static void SendCommand(const uint16_t* command, int length);
+
+ /**
+ * Run a JavaScript function in the debugger.
+ * \param fun the function to call
+ * \param data passed as second argument to the function
+ * With this call the debugger is entered and the function specified is called
+ * with the execution state as the first argument. This makes it possible to
+ * get access to information otherwise not available during normal JavaScript
+ * execution e.g. details on stack frames. The following example show a
+ * JavaScript function which when passed to v8::Debug::Call will return the
+ * current line of JavaScript execution.
+ *
+ * \code
+ * function frame_source_line(exec_state) {
+ * return exec_state.frame(0).sourceLine();
+ * }
+ * \endcode
+ */
+ static Handle<Value> Call(v8::Handle<v8::Function> fun,
+ Handle<Value> data = Handle<Value>());
+};
+
+
+} // namespace v8
+
+
+#undef EXPORT
+
+
+#endif // V8_DEBUG_H_
diff --git a/Plugins/skins/libs/v8.h b/Plugins/skins/libs/v8.h new file mode 100644 index 0000000..01d31d4 --- /dev/null +++ b/Plugins/skins/libs/v8.h @@ -0,0 +1,2472 @@ +// Copyright 2007-2008 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+/** \mainpage V8 API Reference Guide
+ *
+ * V8 is Google's open source JavaScript engine.
+ *
+ * This set of documents provides reference material generated from the
+ * V8 header file, include/v8.h.
+ *
+ * For other documentation see http://code.google.com/apis/v8/
+ */
+
+#ifndef V8_H_
+#define V8_H_
+
+#include <stdio.h>
+
+#ifdef _WIN32
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef unsigned short uint16_t; // NOLINT
+typedef long long int64_t; // NOLINT
+
+// Setup for Windows DLL export/import. When building the V8 DLL the
+// BUILDING_V8_SHARED needs to be defined. When building a program which uses
+// the V8 DLL USING_V8_SHARED needs to be defined. When either building the V8
+// static library or building a program which uses the V8 static library neither
+// BUILDING_V8_SHARED nor USING_V8_SHARED should be defined.
+// The reason for having both EXPORT and EXPORT_INLINE is that classes which
+// have their code inside this header file needs to have __declspec(dllexport)
+// when building the DLL but cannot have __declspec(dllimport) when building
+// a program which uses the DLL.
+#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
+#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
+ build configuration to ensure that at most one of these is set
+#endif
+
+#ifdef BUILDING_V8_SHARED
+#define EXPORT __declspec(dllexport)
+#define EXPORT_INLINE __declspec(dllexport)
+#elif USING_V8_SHARED
+#define EXPORT __declspec(dllimport)
+#define EXPORT_INLINE
+#else
+#define EXPORT
+#define EXPORT_INLINE
+#endif // BUILDING_V8_SHARED
+
+#else // _WIN32
+
+#include <stdint.h>
+
+// Setup for Linux shared library export. There is no need to destinguish
+// neither between building or using the V8 shared library nor between using
+// the shared or static V8 library as there is on Windows. Therefore there is
+// no checking of BUILDING_V8_SHARED and USING_V8_SHARED.
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#define EXPORT __attribute__ ((visibility("default")))
+#define EXPORT_INLINE __attribute__ ((visibility("default")))
+#else // defined(__GNUC__) && (__GNUC__ >= 4)
+#define EXPORT
+#define EXPORT_INLINE
+#endif // defined(__GNUC__) && (__GNUC__ >= 4)
+
+#endif // _WIN32
+
+/**
+ * The v8 JavaScript engine.
+ */
+namespace v8 {
+
+class Context;
+class String;
+class Value;
+class Utils;
+class Number;
+class Object;
+class Array;
+class Int32;
+class Uint32;
+class External;
+class Primitive;
+class Boolean;
+class Integer;
+class Function;
+class Date;
+class ImplementationUtilities;
+class Signature;
+template <class T> class Handle;
+template <class T> class Local;
+template <class T> class Persistent;
+class FunctionTemplate;
+class ObjectTemplate;
+class Data;
+
+
+// --- W e a k H a n d l e s
+
+
+/**
+ * A weak reference callback function.
+ *
+ * \param object the weak global object to be reclaimed by the garbage collector
+ * \param parameter the value passed in when making the weak global object
+ */
+typedef void (*WeakReferenceCallback)(Persistent<Value> object,
+ void* parameter);
+
+
+// --- H a n d l e s ---
+
+#define TYPE_CHECK(T, S) \
+ while (false) { \
+ *(static_cast<T**>(0)) = static_cast<S*>(0); \
+ }
+
+/**
+ * An object reference managed by the v8 garbage collector.
+ *
+ * All objects returned from v8 have to be tracked by the garbage
+ * collector so that it knows that the objects are still alive. Also,
+ * because the garbage collector may move objects, it is unsafe to
+ * point directly to an object. Instead, all objects are stored in
+ * handles which are known by the garbage collector and updated
+ * whenever an object moves. Handles should always be passed by value
+ * (except in cases like out-parameters) and they should never be
+ * allocated on the heap.
+ *
+ * There are two types of handles: local and persistent handles.
+ * Local handles are light-weight and transient and typically used in
+ * local operations. They are managed by HandleScopes. Persistent
+ * handles can be used when storing objects across several independent
+ * operations and have to be explicitly deallocated when they're no
+ * longer used.
+ *
+ * It is safe to extract the object stored in the handle by
+ * dereferencing the handle (for instance, to extract the Object* from
+ * an Handle<Object>); the value will still be governed by a handle
+ * behind the scenes and the same rules apply to these values as to
+ * their handles.
+ */
+template <class T> class EXPORT_INLINE Handle {
+ public:
+
+ /**
+ * Creates an empty handle.
+ */
+ Handle();
+
+ /**
+ * Creates a new handle for the specified value.
+ */
+ explicit Handle(T* val) : val_(val) { }
+
+ /**
+ * Creates a handle for the contents of the specified handle. This
+ * constructor allows you to pass handles as arguments by value and
+ * to assign between handles. However, if you try to assign between
+ * incompatible handles, for instance from a Handle<String> to a
+ * Handle<Number> it will cause a compiletime error. Assigning
+ * between compatible handles, for instance assigning a
+ * Handle<String> to a variable declared as Handle<Value>, is legal
+ * because String is a subclass of Value.
+ */
+ template <class S> inline Handle(Handle<S> that)
+ : val_(reinterpret_cast<T*>(*that)) {
+ /**
+ * This check fails when trying to convert between incompatible
+ * handles. For example, converting from a Handle<String> to a
+ * Handle<Number>.
+ */
+ TYPE_CHECK(T, S);
+ }
+
+ /**
+ * Returns true if the handle is empty.
+ */
+ bool IsEmpty() { return val_ == 0; }
+
+ T* operator->();
+
+ T* operator*();
+
+ /**
+ * Sets the handle to be empty. IsEmpty() will then return true.
+ */
+ void Clear() { this->val_ = 0; }
+
+ /**
+ * Checks whether two handles are the same.
+ * Returns true if both are empty, or if the objects
+ * to which they refer are identical.
+ * The handles' references are not checked.
+ */
+ template <class S> bool operator==(Handle<S> that) {
+ void** a = reinterpret_cast<void**>(**this);
+ void** b = reinterpret_cast<void**>(*that);
+ if (a == 0) return b == 0;
+ if (b == 0) return false;
+ return *a == *b;
+ }
+
+ /**
+ * Checks whether two handles are different.
+ * Returns true if only one of the handles is empty, or if
+ * the objects to which they refer are different.
+ * The handles' references are not checked.
+ */
+ template <class S> bool operator!=(Handle<S> that) {
+ return !operator==(that);
+ }
+
+ template <class S> static inline Handle<T> Cast(Handle<S> that) {
+ if (that.IsEmpty()) return Handle<T>();
+ return Handle<T>(T::Cast(*that));
+ }
+
+ private:
+ T* val_;
+};
+
+
+/**
+ * A light-weight stack-allocated object handle. All operations
+ * that return objects from within v8 return them in local handles. They
+ * are created within HandleScopes, and all local handles allocated within a
+ * handle scope are destroyed when the handle scope is destroyed. Hence it
+ * is not necessary to explicitly deallocate local handles.
+ */
+template <class T> class EXPORT_INLINE Local : public Handle<T> {
+ public:
+ Local();
+ template <class S> inline Local(Local<S> that)
+ : Handle<T>(reinterpret_cast<T*>(*that)) {
+ /**
+ * This check fails when trying to convert between incompatible
+ * handles. For example, converting from a Handle<String> to a
+ * Handle<Number>.
+ */
+ TYPE_CHECK(T, S);
+ }
+ template <class S> inline Local(S* that) : Handle<T>(that) { }
+ template <class S> static inline Local<T> Cast(Local<S> that) {
+ if (that.IsEmpty()) return Local<T>();
+ return Local<T>(T::Cast(*that));
+ }
+
+ /** Create a local handle for the content of another handle.
+ * The referee is kept alive by the local handle even when
+ * the original handle is destroyed/disposed.
+ */
+ static Local<T> New(Handle<T> that);
+};
+
+
+/**
+ * An object reference that is independent of any handle scope. Where
+ * a Local handle only lives as long as the HandleScope in which it was
+ * allocated, a Persistent handle remains valid until it is explicitly
+ * disposed.
+ *
+ * A persistent handle contains a reference to a storage cell within
+ * the v8 engine which holds an object value and which is updated by
+ * the garbage collector whenever the object is moved. A new storage
+ * cell can be created using Persistent::New and existing handles can
+ * be disposed using Persistent::Dispose. Since persistent handles
+ * are passed by value you may have many persistent handle objects
+ * that point to the same storage cell. For instance, if you pass a
+ * persistent handle as an argument to a function you will not get two
+ * different storage cells but rather two references to the same
+ * storage cell.
+ */
+template <class T> class EXPORT_INLINE Persistent : public Handle<T> {
+ public:
+
+ /**
+ * Creates an empty persistent handle that doesn't point to any
+ * storage cell.
+ */
+ Persistent();
+
+ /**
+ * Creates a persistent handle for the same storage cell as the
+ * specified handle. This constructor allows you to pass persistent
+ * handles as arguments by value and to assign between persistent
+ * handles. However, attempting to assign between incompatible
+ * persistent handles, for instance from a Persistent<String> to a
+ * Persistent<Number> will cause a compiletime error. Assigning
+ * between compatible persistent handles, for instance assigning a
+ * Persistent<String> to a variable declared as Persistent<Value>,
+ * is allowed as String is a subclass of Value.
+ */
+ template <class S> inline Persistent(Persistent<S> that)
+ : Handle<T>(reinterpret_cast<T*>(*that)) {
+ /**
+ * This check fails when trying to convert between incompatible
+ * handles. For example, converting from a Handle<String> to a
+ * Handle<Number>.
+ */
+ TYPE_CHECK(T, S);
+ }
+
+ template <class S> inline Persistent(S* that) : Handle<T>(that) { }
+
+ /**
+ * "Casts" a plain handle which is known to be a persistent handle
+ * to a persistent handle.
+ */
+ template <class S> explicit inline Persistent(Handle<S> that)
+ : Handle<T>(*that) { }
+
+ template <class S> static inline Persistent<T> Cast(Persistent<S> that) {
+ if (that.IsEmpty()) return Persistent<T>();
+ return Persistent<T>(T::Cast(*that));
+ }
+
+ /**
+ * Creates a new persistent handle for an existing local or
+ * persistent handle.
+ */
+ static Persistent<T> New(Handle<T> that);
+
+ /**
+ * Releases the storage cell referenced by this persistent handle.
+ * Does not remove the reference to the cell from any handles.
+ * This handle's reference, and any any other references to the storage
+ * cell remain and IsEmpty will still return false.
+ */
+ void Dispose();
+
+ /**
+ * Make the reference to this object weak. When only weak handles
+ * refer to the object, the garbage collector will perform a
+ * callback to the given V8::WeakReferenceCallback function, passing
+ * it the object reference and the given parameters.
+ */
+ void MakeWeak(void* parameters, WeakReferenceCallback callback);
+
+ /** Clears the weak reference to this object.*/
+ void ClearWeak();
+
+ /**
+ *Checks if the handle holds the only reference to an object.
+ */
+ bool IsNearDeath();
+
+ /**
+ * Returns true if the handle's reference is weak.
+ */
+ bool IsWeak();
+
+ private:
+ friend class ImplementationUtilities;
+ friend class ObjectTemplate;
+};
+
+
+ /**
+ * A stack-allocated class that governs a number of local handles.
+ * After a handle scope has been created, all local handles will be
+ * allocated within that handle scope until either the handle scope is
+ * deleted or another handle scope is created. If there is already a
+ * handle scope and a new one is created, all allocations will take
+ * place in the new handle scope until it is deleted. After that,
+ * new handles will again be allocated in the original handle scope.
+ *
+ * After the handle scope of a local handle has been deleted the
+ * garbage collector will no longer track the object stored in the
+ * handle and may deallocate it. The behavior of accessing a handle
+ * for which the handle scope has been deleted is undefined.
+ */
+class EXPORT HandleScope {
+ public:
+ HandleScope() : previous_(current_), is_closed_(false) {
+ current_.extensions = 0;
+ }
+
+ ~HandleScope() {
+ // TODO(1245391): In a perfect world, there would be a way of not
+ // having to check for explicitly closed scopes maybe through
+ // subclassing HandleScope?
+ if (!is_closed_) RestorePreviousState();
+ }
+
+ /**
+ * TODO(1245391): Consider introducing a subclass for this.
+ * Closes the handle scope and returns the value as a handle in the
+ * previous scope, which is the new current scope after the call.
+ */
+ template <class T> Local<T> Close(Handle<T> value);
+
+ /**
+ * Counts the number of allocated handles.
+ */
+ static int NumberOfHandles();
+
+ /**
+ * Creates a new handle with the given value.
+ */
+ static void** CreateHandle(void* value);
+
+ private:
+ // Make it impossible to create heap-allocated or illegal handle
+ // scopes by disallowing certain operations.
+ HandleScope(const HandleScope&);
+ void operator=(const HandleScope&);
+ void* operator new(size_t size);
+ void operator delete(void*, size_t);
+
+ class EXPORT Data {
+ public:
+ int extensions;
+ void** next;
+ void** limit;
+ inline void Initialize() {
+ extensions = -1;
+ next = limit = NULL;
+ }
+ };
+
+ static Data current_;
+ const Data previous_;
+
+ /**
+ * Re-establishes the previous scope state. Should be called only
+ * once, and only for the current scope.
+ */
+ void RestorePreviousState() {
+ if (current_.extensions > 0) DeleteExtensions();
+ current_ = previous_;
+#ifdef DEBUG
+ ZapRange(current_.next, current_.limit);
+#endif
+ }
+
+ // TODO(1245391): Consider creating a subclass for this.
+ bool is_closed_;
+ void** RawClose(void** value);
+
+ /** Deallocates any extensions used by the current scope.*/
+ static void DeleteExtensions();
+
+ // Zaps the handles in the half-open interval [start, end).
+ static void ZapRange(void** start, void** end);
+
+ friend class ImplementationUtilities;
+};
+
+
+// --- S p e c i a l o b j e c t s ---
+
+
+/**
+ * The superclass of values and API object templates.
+ */
+class EXPORT Data {
+ private:
+ Data();
+};
+
+
+/**
+ * Pre-compilation data that can be associated with a script. This
+ * data can be calculated for a script in advance of actually
+ * compiling it, and can be stored between compilations. When script
+ * data is given to the compile method compilation will be faster.
+ */
+class EXPORT ScriptData { // NOLINT
+ public:
+ virtual ~ScriptData() { }
+ static ScriptData* PreCompile(const char* input, int length);
+ static ScriptData* New(unsigned* data, int length);
+
+ virtual int Length() = 0;
+ virtual unsigned* Data() = 0;
+};
+
+
+/**
+ * The origin, within a file, of a script.
+ */
+class EXPORT ScriptOrigin {
+ public:
+ ScriptOrigin(Handle<Value> resource_name,
+ Handle<Integer> resource_line_offset = Handle<Integer>(),
+ Handle<Integer> resource_column_offset = Handle<Integer>())
+ : resource_name_(resource_name),
+ resource_line_offset_(resource_line_offset),
+ resource_column_offset_(resource_column_offset) { }
+ inline Handle<Value> ResourceName() const;
+ inline Handle<Integer> ResourceLineOffset() const;
+ inline Handle<Integer> ResourceColumnOffset() const;
+ private:
+ Handle<Value> resource_name_;
+ Handle<Integer> resource_line_offset_;
+ Handle<Integer> resource_column_offset_;
+};
+
+
+/**
+ * A compiled JavaScript script.
+ */
+class EXPORT Script {
+ public:
+
+ /**
+ * Compiles the specified script. The ScriptOrigin* and ScriptData*
+ * parameters are owned by the caller of Script::Compile. No
+ * references to these objects are kept after compilation finishes.
+ */
+ static Local<Script> Compile(Handle<String> source,
+ ScriptOrigin* origin = NULL,
+ ScriptData* pre_data = NULL);
+
+ /**
+ * Compiles the specified script using the specified file name
+ * object (typically a string) as the script's origin.
+ */
+ static Local<Script> Compile(Handle<String> source,
+ Handle<Value> file_name);
+
+ /**
+ * Runs the script returning the resulting value.
+ */
+ Local<Value> Run();
+};
+
+
+/**
+ * An error message.
+ */
+class EXPORT Message {
+ public:
+ Local<String> Get();
+ Local<String> GetSourceLine();
+
+ Handle<Value> GetScriptResourceName();
+
+ /**
+ * Returns the number, 1-based, of the line where the error occurred.
+ */
+ int GetLineNumber();
+
+ /**
+ * Returns the index within the script of the first character where
+ * the error occurred.
+ */
+ int GetStartPosition();
+
+ /**
+ * Returns the index within the script of the last character where
+ * the error occurred.
+ */
+ int GetEndPosition();
+
+ /**
+ * Returns the index within the line of the first character where
+ * the error occurred.
+ */
+ int GetStartColumn();
+
+ /**
+ * Returns the index within the line of the last character where
+ * the error occurred.
+ */
+ int GetEndColumn();
+
+ // TODO(1245381): Print to a string instead of on a FILE.
+ static void PrintCurrentStackTrace(FILE* out);
+};
+
+
+// --- V a l u e ---
+
+
+/**
+ * The superclass of all JavaScript values and objects.
+ */
+class EXPORT Value : public Data {
+ public:
+
+ /**
+ * Returns true if this value is the undefined value. See ECMA-262
+ * 4.3.10.
+ */
+ bool IsUndefined();
+
+ /**
+ * Returns true if this value is the null value. See ECMA-262
+ * 4.3.11.
+ */
+ bool IsNull();
+
+ /**
+ * Returns true if this value is true.
+ */
+ bool IsTrue();
+
+ /**
+ * Returns true if this value is false.
+ */
+ bool IsFalse();
+
+ /**
+ * Returns true if this value is an instance of the String type.
+ * See ECMA-262 8.4.
+ */
+ bool IsString();
+
+ /**
+ * Returns true if this value is a function.
+ */
+ bool IsFunction();
+
+ /**
+ * Returns true if this value is an array.
+ */
+ bool IsArray();
+
+ /**
+ * Returns true if this value is an object.
+ */
+ bool IsObject();
+
+ /**
+ * Returns true if this value is boolean.
+ */
+ bool IsBoolean();
+
+ /**
+ * Returns true if this value is a number.
+ */
+ bool IsNumber();
+
+ /**
+ * Returns true if this value is external.
+ */
+ bool IsExternal();
+
+ /**
+ * Returns true if this value is a 32-bit signed integer.
+ */
+ bool IsInt32();
+
+ /**
+ * Returns true if this value is a Date.
+ */
+ bool IsDate();
+
+ Local<Boolean> ToBoolean();
+ Local<Number> ToNumber();
+ Local<String> ToString();
+ Local<String> ToDetailString();
+ Local<Object> ToObject();
+ Local<Integer> ToInteger();
+ Local<Uint32> ToUint32();
+ Local<Int32> ToInt32();
+
+ /**
+ * Attempts to convert a string to an array index.
+ * Returns an empty handle if the conversion fails.
+ */
+ Local<Uint32> ToArrayIndex();
+
+ bool BooleanValue();
+ double NumberValue();
+ int64_t IntegerValue();
+ uint32_t Uint32Value();
+ int32_t Int32Value();
+
+ /** JS == */
+ bool Equals(Handle<Value> that);
+ bool StrictEquals(Handle<Value> that);
+};
+
+
+/**
+ * The superclass of primitive values. See ECMA-262 4.3.2.
+ */
+class EXPORT Primitive : public Value { };
+
+
+/**
+ * A primitive boolean value (ECMA-262, 4.3.14). Either the true
+ * or false value.
+ */
+class EXPORT Boolean : public Primitive {
+ public:
+ bool Value();
+ static inline Handle<Boolean> New(bool value);
+};
+
+
+/**
+ * A JavaScript string value (ECMA-262, 4.3.17).
+ */
+class EXPORT String : public Primitive {
+ public:
+
+ /**
+ * Returns the number of characters in this string.
+ */
+ int Length();
+
+ /**
+ * Returns the number of bytes in the UTF-8 encoded
+ * representation of this string.
+ */
+ int Utf8Length();
+
+ /**
+ * Write the contents of the string to an external buffer.
+ * If no arguments are given, expects the buffer to be large
+ * enough to hold the entire string and NULL terminator. Copies
+ * the contents of the string and the NULL terminator into the
+ * buffer.
+ *
+ * Copies up to length characters into the output buffer.
+ * Only null-terminates if there is enough space in the buffer.
+ *
+ * \param buffer The buffer into which the string will be copied.
+ * \param start The starting position within the string at which
+ * copying begins.
+ * \param length The number of bytes to copy from the string.
+ * \return The number of characters copied to the buffer
+ * excluding the NULL terminator.
+ */
+ int Write(uint16_t* buffer, int start = 0, int length = -1); // UTF-16
+ int WriteAscii(char* buffer, int start = 0, int length = -1); // ASCII
+ int WriteUtf8(char* buffer, int length = -1); // UTF-8
+
+ /**
+ * Returns true if the string is external
+ */
+ bool IsExternal();
+
+ /**
+ * Returns true if the string is both external and ascii
+ */
+ bool IsExternalAscii();
+ /**
+ * An ExternalStringResource is a wrapper around a two-byte string
+ * buffer that resides outside V8's heap. Implement an
+ * ExternalStringResource to manage the life cycle of the underlying
+ * buffer. Note that the string data must be immutable.
+ */
+ class EXPORT ExternalStringResource { // NOLINT
+ public:
+ /**
+ * Override the destructor to manage the life cycle of the underlying
+ * buffer.
+ */
+ virtual ~ExternalStringResource() {}
+ /** The string data from the underlying buffer.*/
+ virtual const uint16_t* data() const = 0;
+ /** The length of the string. That is, the number of two-byte characters.*/
+ virtual size_t length() const = 0;
+ protected:
+ ExternalStringResource() {}
+ private:
+ // Disallow copying and assigning.
+ ExternalStringResource(const ExternalStringResource&);
+ void operator=(const ExternalStringResource&);
+ };
+
+ /**
+ * An ExternalAsciiStringResource is a wrapper around an ascii
+ * string buffer that resides outside V8's heap. Implement an
+ * ExternalAsciiStringResource to manage the life cycle of the
+ * underlying buffer. Note that the string data must be immutable
+ * and that the data must be strict 7-bit ASCII, not Latin1 or
+ * UTF-8, which would require special treatment internally in the
+ * engine and, in the case of UTF-8, do not allow efficient indexing.
+ * Use String::New or convert to 16 bit data for non-ASCII.
+ */
+
+ class EXPORT ExternalAsciiStringResource { // NOLINT
+ public:
+ /**
+ * Override the destructor to manage the life cycle of the underlying
+ * buffer.
+ */
+ virtual ~ExternalAsciiStringResource() {}
+ /** The string data from the underlying buffer.*/
+ virtual const char* data() const = 0;
+ /** The number of ascii characters in the string.*/
+ virtual size_t length() const = 0;
+ protected:
+ ExternalAsciiStringResource() {}
+ private:
+ // Disallow copying and assigning.
+ ExternalAsciiStringResource(const ExternalAsciiStringResource&);
+ void operator=(const ExternalAsciiStringResource&);
+ };
+
+ /**
+ * Get the ExternalStringResource for an external string. Only
+ * valid if IsExternal() returns true.
+ */
+ ExternalStringResource* GetExternalStringResource();
+
+ /**
+ * Get the ExternalAsciiStringResource for an external ascii string.
+ * Only valid if IsExternalAscii() returns true.
+ */
+ ExternalAsciiStringResource* GetExternalAsciiStringResource();
+
+ static String* Cast(v8::Value* obj);
+
+ /**
+ * Allocates a new string from either utf-8 encoded or ascii data.
+ * The second parameter 'length' gives the buffer length.
+ * If the data is utf-8 encoded, the caller must
+ * be careful to supply the length parameter.
+ * If it is not given, the function calls
+ * 'strlen' to determine the buffer length, it might be
+ * wrong if 'data' contains a null character.
+ */
+ static Local<String> New(const char* data, int length = -1);
+
+ /** Allocates a new string from utf16 data.*/
+ static Local<String> New(const uint16_t* data, int length = -1);
+
+ /** Creates a symbol. Returns one if it exists already.*/
+ static Local<String> NewSymbol(const char* data, int length = -1);
+
+ /**
+ * Creates a new external string using the data defined in the given
+ * resource. The resource is deleted when the external string is no
+ * longer live on V8's heap. The caller of this function should not
+ * delete or modify the resource. Neither should the underlying buffer be
+ * deallocated or modified except through the destructor of the
+ * external string resource.
+ */
+ static Local<String> NewExternal(ExternalStringResource* resource);
+
+ /**
+ * Creates a new external string using the ascii data defined in the given
+ * resource. The resource is deleted when the external string is no
+ * longer live on V8's heap. The caller of this function should not
+ * delete or modify the resource. Neither should the underlying buffer be
+ * deallocated or modified except through the destructor of the
+ * external string resource.
+ */
+ static Local<String> NewExternal(ExternalAsciiStringResource* resource);
+
+ /** Creates an undetectable string from the supplied ascii or utf-8 data.*/
+ static Local<String> NewUndetectable(const char* data, int length = -1);
+
+ /** Creates an undetectable string from the supplied utf-16 data.*/
+ static Local<String> NewUndetectable(const uint16_t* data, int length = -1);
+
+ /**
+ * Converts an object to a utf8-encoded character array. Useful if
+ * you want to print the object.
+ */
+ class EXPORT Utf8Value {
+ public:
+ explicit Utf8Value(Handle<v8::Value> obj);
+ ~Utf8Value();
+ char* operator*() { return str_; }
+ int length() { return length_; }
+ private:
+ char* str_;
+ int length_;
+
+ // Disallow copying and assigning.
+ Utf8Value(const Utf8Value&);
+ void operator=(const Utf8Value&);
+ };
+
+ /**
+ * Converts an object to an ascii string.
+ * Useful if you want to print the object.
+ */
+ class EXPORT AsciiValue {
+ public:
+ explicit AsciiValue(Handle<v8::Value> obj);
+ ~AsciiValue();
+ char* operator*() { return str_; }
+ int length() { return length_; }
+ private:
+ char* str_;
+ int length_;
+
+ // Disallow copying and assigning.
+ AsciiValue(const AsciiValue&);
+ void operator=(const AsciiValue&);
+ };
+
+ /**
+ * Converts an object to a two-byte string.
+ */
+ class EXPORT Value {
+ public:
+ explicit Value(Handle<v8::Value> obj);
+ ~Value();
+ uint16_t* operator*() { return str_; }
+ int length() { return length_; }
+ private:
+ uint16_t* str_;
+ int length_;
+
+ // Disallow copying and assigning.
+ Value(const Value&);
+ void operator=(const Value&);
+ };
+};
+
+
+/**
+ * A JavaScript number value (ECMA-262, 4.3.20)
+ */
+class EXPORT Number : public Primitive {
+ public:
+ double Value();
+ static Local<Number> New(double value);
+ static Number* Cast(v8::Value* obj);
+ private:
+ Number();
+};
+
+
+/**
+ * A JavaScript value representing a signed integer.
+ */
+class EXPORT Integer : public Number {
+ public:
+ static Local<Integer> New(int32_t value);
+ int64_t Value();
+ static Integer* Cast(v8::Value* obj);
+ private:
+ Integer();
+};
+
+
+/**
+ * A JavaScript value representing a 32-bit signed integer.
+ */
+class EXPORT Int32 : public Integer {
+ public:
+ int32_t Value();
+ private:
+ Int32();
+};
+
+
+/**
+ * A JavaScript value representing a 32-bit unsigned integer.
+ */
+class EXPORT Uint32 : public Integer {
+ public:
+ uint32_t Value();
+ private:
+ Uint32();
+};
+
+
+/**
+ * An instance of the built-in Date constructor (ECMA-262, 15.9).
+ */
+class EXPORT Date : public Value {
+ public:
+ static Local<Value> New(double time);
+
+ /**
+ * A specialization of Value::NumberValue that is more efficient
+ * because we know the structure of this object.
+ */
+ double NumberValue();
+
+ static Date* Cast(v8::Value* obj);
+};
+
+
+enum PropertyAttribute {
+ None = 0,
+ ReadOnly = 1 << 0,
+ DontEnum = 1 << 1,
+ DontDelete = 1 << 2
+};
+
+/**
+ * A JavaScript object (ECMA-262, 4.3.3)
+ */
+class EXPORT Object : public Value {
+ public:
+ bool Set(Handle<Value> key,
+ Handle<Value> value,
+ PropertyAttribute attribs = None);
+ Local<Value> Get(Handle<Value> key);
+
+ // TODO(1245389): Replace the type-specific versions of these
+ // functions with generic ones that accept a Handle<Value> key.
+ bool Has(Handle<String> key);
+ bool Delete(Handle<String> key);
+ bool Has(uint32_t index);
+ bool Delete(uint32_t index);
+
+ /**
+ * Returns an array containing the names of the enumerable properties
+ * of this object, including properties from prototype objects. The
+ * array returned by this method contains the same values as would
+ * be enumerated by a for-in statement over this object.
+ */
+ Local<Array> GetPropertyNames();
+
+ /**
+ * Get the prototype object. This does not skip objects marked to
+ * be skipped by __proto__ and it does not consult the security
+ * handler.
+ */
+ Local<Value> GetPrototype();
+
+ /**
+ * Call builtin Object.prototype.toString on this object.
+ * This is different from Value::ToString() that may call
+ * user-defined toString function. This one does not.
+ */
+ Local<String> ObjectProtoToString();
+
+ /** Gets the number of internal fields for this Object. */
+ int InternalFieldCount();
+ /** Gets the value in an internal field. */
+ Local<Value> GetInternalField(int index);
+ /** Sets the value in an internal field. */
+ void SetInternalField(int index, Handle<Value> value);
+
+ // Testers for local properties.
+ bool HasRealNamedProperty(Handle<String> key);
+ bool HasRealIndexedProperty(uint32_t index);
+ bool HasRealNamedCallbackProperty(Handle<String> key);
+
+ /**
+ * If result.IsEmpty() no real property was located in the prototype chain.
+ * This means interceptors in the prototype chain are not called.
+ */
+ Handle<Value> GetRealNamedPropertyInPrototypeChain(Handle<String> key);
+
+ /** Tests for a named lookup interceptor.*/
+ bool HasNamedLookupInterceptor();
+
+ /** Tests for an index lookup interceptor.*/
+ bool HasIndexedLookupInterceptor();
+
+ /**
+ * Turns on access check on the object if the object is an instance of
+ * a template that has access check callbacks. If an object has no
+ * access check info, the object cannot be accessed by anyone.
+ */
+ void TurnOnAccessCheck();
+
+ static Local<Object> New();
+ static Object* Cast(Value* obj);
+ private:
+ Object();
+};
+
+
+/**
+ * An instance of the built-in array constructor (ECMA-262, 15.4.2).
+ */
+class EXPORT Array : public Object {
+ public:
+ uint32_t Length();
+
+ static Local<Array> New(int length = 0);
+ static Array* Cast(Value* obj);
+ private:
+ Array();
+};
+
+
+/**
+ * A JavaScript function object (ECMA-262, 15.3).
+ */
+class EXPORT Function : public Object {
+ public:
+ Local<Object> NewInstance();
+ Local<Object> NewInstance(int argc, Handle<Value> argv[]);
+ Local<Value> Call(Handle<Object> recv, int argc, Handle<Value> argv[]);
+ void SetName(Handle<String> name);
+ Handle<Value> GetName();
+ static Function* Cast(Value* obj);
+ private:
+ Function();
+};
+
+
+/**
+ * A JavaScript value that wraps a c++ void*. This type of value is
+ * mainly used to associate c++ data structures with JavaScript
+ * objects.
+ */
+class EXPORT External : public Value {
+ public:
+ static Local<External> New(void* value);
+ static External* Cast(Value* obj);
+ void* Value();
+ private:
+ External();
+};
+
+
+// --- T e m p l a t e s ---
+
+
+/**
+ * The superclass of object and function templates.
+ */
+class EXPORT Template : public Data {
+ public:
+ /** Adds a property to each instance created by this template.*/
+ void Set(Handle<String> name, Handle<Data> value,
+ PropertyAttribute attributes = None);
+ inline void Set(const char* name, Handle<Data> value);
+ private:
+ Template();
+
+ friend class ObjectTemplate;
+ friend class FunctionTemplate;
+};
+
+
+/**
+ * The argument information given to function call callbacks. This
+ * class provides access to information about the context of the call,
+ * including the receiver, the number and values of arguments, and
+ * the holder of the function.
+ */
+class EXPORT Arguments {
+ public:
+ inline int Length() const;
+ inline Local<Value> operator[](int i) const;
+ inline Local<Function> Callee() const;
+ inline Local<Object> This() const;
+ inline Local<Object> Holder() const;
+ inline bool IsConstructCall() const;
+ inline Local<Value> Data() const;
+ private:
+ Arguments();
+ friend class ImplementationUtilities;
+ inline Arguments(Local<Value> data,
+ Local<Object> holder,
+ Local<Function> callee,
+ bool is_construct_call,
+ void** values, int length);
+ Local<Value> data_;
+ Local<Object> holder_;
+ Local<Function> callee_;
+ bool is_construct_call_;
+ void** values_;
+ int length_;
+};
+
+
+/**
+ * The information passed to an accessor callback about the context
+ * of the property access.
+ */
+class EXPORT AccessorInfo {
+ public:
+ inline AccessorInfo(Local<Object> self,
+ Local<Value> data,
+ Local<Object> holder)
+ : self_(self), data_(data), holder_(holder) { }
+ inline Local<Value> Data() const;
+ inline Local<Object> This() const;
+ inline Local<Object> Holder() const;
+ private:
+ Local<Object> self_;
+ Local<Value> data_;
+ Local<Object> holder_;
+};
+
+
+typedef Handle<Value> (*InvocationCallback)(const Arguments& args);
+
+typedef int (*LookupCallback)(Local<Object> self, Local<String> name);
+
+/**
+ * Accessor[Getter|Setter] are used as callback functions when
+ * setting|getting a particular property. See objectTemplate::SetAccessor.
+ */
+typedef Handle<Value> (*AccessorGetter)(Local<String> property,
+ const AccessorInfo& info);
+
+
+typedef void (*AccessorSetter)(Local<String> property,
+ Local<Value> value,
+ const AccessorInfo& info);
+
+
+/**
+ * NamedProperty[Getter|Setter] are used as interceptors on object.
+ * See ObjectTemplate::SetNamedPropertyHandler.
+ */
+typedef Handle<Value> (*NamedPropertyGetter)(Local<String> property,
+ const AccessorInfo& info);
+
+
+/**
+ * Returns the value if the setter intercepts the request.
+ * Otherwise, returns an empty handle.
+ */
+typedef Handle<Value> (*NamedPropertySetter)(Local<String> property,
+ Local<Value> value,
+ const AccessorInfo& info);
+
+
+/**
+ * Returns a non-empty handle if the interceptor intercepts the request.
+ * The result is true if the property exists and false otherwise.
+ */
+typedef Handle<Boolean> (*NamedPropertyQuery)(Local<String> property,
+ const AccessorInfo& info);
+
+
+/**
+ * Returns a non-empty handle if the deleter intercepts the request.
+ * The return value is true if the property could be deleted and false
+ * otherwise.
+ */
+typedef Handle<Boolean> (*NamedPropertyDeleter)(Local<String> property,
+ const AccessorInfo& info);
+
+/**
+ * Returns an array containing the names of the properties the named
+ * property getter intercepts.
+ */
+typedef Handle<Array> (*NamedPropertyEnumerator)(const AccessorInfo& info);
+
+
+/**
+ * Returns the value of the property if the getter intercepts the
+ * request. Otherwise, returns an empty handle.
+ */
+typedef Handle<Value> (*IndexedPropertyGetter)(uint32_t index,
+ const AccessorInfo& info);
+
+
+/**
+ * Returns the value if the setter intercepts the request.
+ * Otherwise, returns an empty handle.
+ */
+typedef Handle<Value> (*IndexedPropertySetter)(uint32_t index,
+ Local<Value> value,
+ const AccessorInfo& info);
+
+
+/**
+ * Returns a non-empty handle if the interceptor intercepts the request.
+ * The result is true if the property exists and false otherwise.
+ */
+typedef Handle<Boolean> (*IndexedPropertyQuery)(uint32_t index,
+ const AccessorInfo& info);
+
+/**
+ * Returns a non-empty handle if the deleter intercepts the request.
+ * The return value is true if the property could be deleted and false
+ * otherwise.
+ */
+typedef Handle<Boolean> (*IndexedPropertyDeleter)(uint32_t index,
+ const AccessorInfo& info);
+
+/**
+ * Returns an array containing the indices of the properties the
+ * indexed property getter intercepts.
+ */
+typedef Handle<Array> (*IndexedPropertyEnumerator)(const AccessorInfo& info);
+
+
+/**
+ * Access control specifications.
+ *
+ * Some accessors should be accessible across contexts. These
+ * accessors have an explicit access control parameter which specifies
+ * the kind of cross-context access that should be allowed.
+ *
+ * Additionally, for security, accessors can prohibit overwriting by
+ * accessors defined in JavaScript. For objects that have such
+ * accessors either locally or in their prototype chain it is not
+ * possible to overwrite the accessor by using __defineGetter__ or
+ * __defineSetter__ from JavaScript code.
+ */
+enum AccessControl {
+ DEFAULT = 0,
+ ALL_CAN_READ = 1,
+ ALL_CAN_WRITE = 1 << 1,
+ PROHIBITS_OVERWRITING = 1 << 2
+};
+
+
+/**
+ * Access type specification.
+ */
+enum AccessType {
+ ACCESS_GET,
+ ACCESS_SET,
+ ACCESS_HAS,
+ ACCESS_DELETE,
+ ACCESS_KEYS
+};
+
+
+/**
+ * Returns true if cross-context access should be allowed to the named
+ * property with the given key on the global object.
+ */
+typedef bool (*NamedSecurityCallback)(Local<Object> global,
+ Local<Value> key,
+ AccessType type,
+ Local<Value> data);
+
+
+/**
+ * Returns true if cross-context access should be allowed to the indexed
+ * property with the given index on the global object.
+ */
+typedef bool (*IndexedSecurityCallback)(Local<Object> global,
+ uint32_t index,
+ AccessType type,
+ Local<Value> data);
+
+
+/**
+ * A FunctionTemplate is used to create functions at runtime. There
+ * can only be one function created from a FunctionTemplate in a
+ * context.
+ *
+ * A FunctionTemplate can have properties, these properties are added to the
+ * function object when it is created.
+ *
+ * A FunctionTemplate has a corresponding instance template which is
+ * used to create object instances when the function is used as a
+ * constructor. Properties added to the instance template are added to
+ * each object instance.
+ *
+ * A FunctionTemplate can have a prototype template. The prototype template
+ * is used to create the prototype object of the function.
+ *
+ * The following example shows how to use a FunctionTemplate:
+ *
+ * \code
+ * v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
+ * t->Set("func_property", v8::Number::New(1));
+ *
+ * v8::Local<v8::Template> proto_t = t->PrototypeTemplate();
+ * proto_t->Set("proto_method", v8::FunctionTemplate::New(InvokeCallback));
+ * proto_t->Set("proto_const", v8::Number::New(2));
+ *
+ * v8::Local<v8::ObjectTemplate> instance_t = t->InstanceTemplate();
+ * instance_t->SetAccessor("instance_accessor", InstanceAccessorCallback);
+ * instance_t->SetNamedPropertyHandler(PropertyHandlerCallback, ...);
+ * instance_t->Set("instance_property", Number::New(3));
+ *
+ * v8::Local<v8::Function> function = t->GetFunction();
+ * v8::Local<v8::Object> instance = function->NewInstance();
+ * \endcode
+ *
+ * Let's use "function" as the JS variable name of the function object
+ * and "instance" for the instance object created above. The function
+ * and the instance will have the following properties:
+ *
+ * \code
+ * func_property in function == true;
+ * function.func_property == 1;
+ *
+ * function.prototype.proto_method() invokes 'InvokeCallback'
+ * function.prototype.proto_const == 2;
+ *
+ * instance instanceof function == true;
+ * instance.instance_accessor calls 'InstanceAccessorCallback'
+ * instance.instance_property == 3;
+ * \endcode
+ *
+ * A FunctionTemplate can inherit from another one by calling the
+ * FunctionTemplate::Inherit method. The following graph illustrates
+ * the semantics of inheritance:
+ *
+ * \code
+ * FunctionTemplate Parent -> Parent() . prototype -> { }
+ * ^ ^
+ * | Inherit(Parent) | .__proto__
+ * | |
+ * FunctionTemplate Child -> Child() . prototype -> { }
+ * \endcode
+ *
+ * A FunctionTemplate 'Child' inherits from 'Parent', the prototype
+ * object of the Child() function has __proto__ pointing to the
+ * Parent() function's prototype object. An instance of the Child
+ * function has all properties on Parent's instance templates.
+ *
+ * Let Parent be the FunctionTemplate initialized in the previous
+ * section and create a Child FunctionTemplate by:
+ *
+ * \code
+ * Local<FunctionTemplate> parent = t;
+ * Local<FunctionTemplate> child = FunctionTemplate::New();
+ * child->Inherit(parent);
+ *
+ * Local<Function> child_function = child->GetFunction();
+ * Local<Object> child_instance = child_function->NewInstance();
+ * \endcode
+ *
+ * The Child function and Child instance will have the following
+ * properties:
+ *
+ * \code
+ * child_func.prototype.__proto__ == function.prototype;
+ * child_instance.instance_accessor calls 'InstanceAccessorCallback'
+ * child_instance.instance_property == 3;
+ * \endcode
+ */
+class EXPORT FunctionTemplate : public Template {
+ public:
+ /** Creates a function template.*/
+ static Local<FunctionTemplate> New(
+ InvocationCallback callback = 0,
+ Handle<Value> data = Handle<Value>(),
+ Handle<Signature> signature = Handle<Signature>());
+ /** Returns the unique function instance in the current execution context.*/
+ Local<Function> GetFunction();
+
+ /**
+ * Set the call-handler callback for a FunctionTemplate. This
+ * callback is called whenever the function created from this
+ * FunctionTemplate is called.
+ */
+ void SetCallHandler(InvocationCallback callback,
+ Handle<Value> data = Handle<Value>());
+
+ /** Get the InstanceTemplate. */
+ Local<ObjectTemplate> InstanceTemplate();
+
+ /** Causes the function template to inherit from a parent function template.*/
+ void Inherit(Handle<FunctionTemplate> parent);
+
+ /**
+ * A PrototypeTemplate is the template used to create the prototype object
+ * of the function created by this template.
+ */
+ Local<ObjectTemplate> PrototypeTemplate();
+
+
+ /**
+ * Set the class name of the FunctionTemplate. This is used for
+ * printing objects created with the function created from the
+ * FunctionTemplate as its constructor.
+ */
+ void SetClassName(Handle<String> name);
+
+ /**
+ * Determines whether the __proto__ accessor ignores instances of
+ * the function template. If instances of the function template are
+ * ignored, __proto__ skips all instances and instead returns the
+ * next object in the prototype chain.
+ *
+ * Call with a value of true to make the __proto__ accessor ignore
+ * instances of the function template. Call with a value of false
+ * to make the __proto__ accessor not ignore instances of the
+ * function template. By default, instances of a function template
+ * are not ignored.
+ */
+ void SetHiddenPrototype(bool value);
+
+ /**
+ * Returns true if the given object is an instance of this function
+ * template.
+ */
+ bool HasInstance(Handle<Value> object);
+
+ private:
+ FunctionTemplate();
+ void AddInstancePropertyAccessor(Handle<String> name,
+ AccessorGetter getter,
+ AccessorSetter setter,
+ Handle<Value> data,
+ AccessControl settings,
+ PropertyAttribute attributes);
+ void SetNamedInstancePropertyHandler(NamedPropertyGetter getter,
+ NamedPropertySetter setter,
+ NamedPropertyQuery query,
+ NamedPropertyDeleter remover,
+ NamedPropertyEnumerator enumerator,
+ Handle<Value> data);
+ void SetIndexedInstancePropertyHandler(IndexedPropertyGetter getter,
+ IndexedPropertySetter setter,
+ IndexedPropertyQuery query,
+ IndexedPropertyDeleter remover,
+ IndexedPropertyEnumerator enumerator,
+ Handle<Value> data);
+ void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
+ Handle<Value> data);
+
+ friend class Context;
+ friend class ObjectTemplate;
+};
+
+
+/**
+ * An ObjectTemplate is used to create objects at runtime.
+ *
+ * Properties added to an ObjectTemplate are added to each object
+ * created from the ObjectTemplate.
+ */
+class EXPORT ObjectTemplate : public Template {
+ public:
+ /** Creates an ObjectTemplate. */
+ static Local<ObjectTemplate> New();
+
+ /** Creates a new instance of this template.*/
+ Local<Object> NewInstance();
+
+ /**
+ * Sets an accessor on the object template.
+ *
+ * Whenever the property with the given name is accessed on objects
+ * created from this ObjectTemplate the getter and setter callbacks
+ * are called instead of getting and setting the property directly
+ * on the JavaScript object.
+ *
+ * \param name The name of the property for which an accessor is added.
+ * \param getter The callback to invoke when getting the property.
+ * \param setter The callback to invoke when setting the property.
+ * \param data A piece of data that will be passed to the getter and setter
+ * callbacks whenever they are invoked.
+ * \param settings Access control settings for the accessor. This is a bit
+ * field consisting of one of more of
+ * DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
+ * The default is to not allow cross-context access.
+ * ALL_CAN_READ means that all cross-context reads are allowed.
+ * ALL_CAN_WRITE means that all cross-context writes are allowed.
+ * The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
+ * cross-context access.
+ * \param attribute The attributes of the property for which an accessor
+ * is added.
+ */
+ void SetAccessor(Handle<String> name,
+ AccessorGetter getter,
+ AccessorSetter setter = 0,
+ Handle<Value> data = Handle<Value>(),
+ AccessControl settings = DEFAULT,
+ PropertyAttribute attribute = None);
+
+ /**
+ * Sets a named property handler on the object template.
+ *
+ * Whenever a named property is accessed on objects created from
+ * this object template, the provided callback is invoked instead of
+ * accessing the property directly on the JavaScript object.
+ *
+ * \param getter The callback to invoke when getting a property.
+ * \param setter The callback to invoke when setting a property.
+ * \param query The callback to invoke to check is an object has a property.
+ * \param deleter The callback to invoke when deleting a property.
+ * \param enumerator The callback to invoke to enumerate all the named
+ * properties of an object.
+ * \param data A piece of data that will be passed to the callbacks
+ * whenever they are invoked.
+ */
+ void SetNamedPropertyHandler(NamedPropertyGetter getter,
+ NamedPropertySetter setter = 0,
+ NamedPropertyQuery query = 0,
+ NamedPropertyDeleter deleter = 0,
+ NamedPropertyEnumerator enumerator = 0,
+ Handle<Value> data = Handle<Value>());
+
+ /**
+ * Sets an indexed property handler on the object template.
+ *
+ * Whenever an indexed property is accessed on objects created from
+ * this object template, the provided callback is invoked instead of
+ * accessing the property directly on the JavaScript object.
+ *
+ * \param getter The callback to invoke when getting a property.
+ * \param setter The callback to invoke when setting a property.
+ * \param query The callback to invoke to check is an object has a property.
+ * \param deleter The callback to invoke when deleting a property.
+ * \param enumerator The callback to invoke to enumerate all the indexed
+ * properties of an object.
+ * \param data A piece of data that will be passed to the callbacks
+ * whenever they are invoked.
+ */
+ void SetIndexedPropertyHandler(IndexedPropertyGetter getter,
+ IndexedPropertySetter setter = 0,
+ IndexedPropertyQuery query = 0,
+ IndexedPropertyDeleter deleter = 0,
+ IndexedPropertyEnumerator enumerator = 0,
+ Handle<Value> data = Handle<Value>());
+ /**
+ * Sets the callback to be used when calling instances created from
+ * this template as a function. If no callback is set, instances
+ * behave like normal JavaScript objects that cannot be called as a
+ * function.
+ */
+ void SetCallAsFunctionHandler(InvocationCallback callback,
+ Handle<Value> data = Handle<Value>());
+
+ /**
+ * Mark object instances of the template as undetectable.
+ *
+ * In many ways, undetectable objects behave as though they are not
+ * there. They behave like 'undefined' in conditionals and when
+ * printed. However, properties can be accessed and called as on
+ * normal objects.
+ */
+ void MarkAsUndetectable();
+
+ /**
+ * Sets access check callbacks on the object template.
+ *
+ * When accessing properties on instances of this object template,
+ * the access check callback will be called to determine whether or
+ * not to allow cross-context access to the properties.
+ * The last parameter specifies whether access checks are turned
+ * on by default on instances. If access checks are off by default,
+ * they can be turned on on individual instances by calling
+ * Object::TurnOnAccessCheck().
+ */
+ void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
+ IndexedSecurityCallback indexed_handler,
+ Handle<Value> data = Handle<Value>(),
+ bool turned_on_by_default = true);
+
+ /**
+ * Gets the number of internal fields for objects generated from
+ * this template.
+ */
+ int InternalFieldCount();
+
+ /**
+ * Sets the number of internal fields for objects generated from
+ * this template.
+ */
+ void SetInternalFieldCount(int value);
+
+ private:
+ ObjectTemplate();
+ static Local<ObjectTemplate> New(Handle<FunctionTemplate> constructor);
+ friend class FunctionTemplate;
+};
+
+
+/**
+ * A Signature specifies which receivers and arguments a function can
+ * legally be called with.
+ */
+class EXPORT Signature : public Data {
+ public:
+ static Local<Signature> New(Handle<FunctionTemplate> receiver =
+ Handle<FunctionTemplate>(),
+ int argc = 0,
+ Handle<FunctionTemplate> argv[] = 0);
+ private:
+ Signature();
+};
+
+
+/**
+ * A utility for determining the type of objects based on the template
+ * they were constructed from.
+ */
+class EXPORT TypeSwitch : public Data {
+ public:
+ static Local<TypeSwitch> New(Handle<FunctionTemplate> type);
+ static Local<TypeSwitch> New(int argc, Handle<FunctionTemplate> types[]);
+ int match(Handle<Value> value);
+ private:
+ TypeSwitch();
+};
+
+
+// --- E x t e n s i o n s ---
+
+
+/**
+ * Ignore
+ */
+class EXPORT Extension { // NOLINT
+ public:
+ Extension(const char* name,
+ const char* source = 0,
+ int dep_count = 0,
+ const char** deps = 0);
+ virtual ~Extension() { }
+ virtual v8::Handle<v8::FunctionTemplate>
+ GetNativeFunction(v8::Handle<v8::String> name) {
+ return v8::Handle<v8::FunctionTemplate>();
+ }
+
+ const char* name() { return name_; }
+ const char* source() { return source_; }
+ int dependency_count() { return dep_count_; }
+ const char** dependencies() { return deps_; }
+ void set_auto_enable(bool value) { auto_enable_ = value; }
+ bool auto_enable() { return auto_enable_; }
+
+ private:
+ const char* name_;
+ const char* source_;
+ int dep_count_;
+ const char** deps_;
+ bool auto_enable_;
+
+ // Disallow copying and assigning.
+ Extension(const Extension&);
+ void operator=(const Extension&);
+};
+
+
+void EXPORT RegisterExtension(Extension* extension);
+
+
+/**
+ * Ignore
+ */
+class EXPORT DeclareExtension {
+ public:
+ inline DeclareExtension(Extension* extension) {
+ RegisterExtension(extension);
+ }
+};
+
+
+// --- S t a t i c s ---
+
+
+Handle<Primitive> EXPORT Undefined();
+Handle<Primitive> EXPORT Null();
+Handle<Boolean> EXPORT True();
+Handle<Boolean> EXPORT False();
+
+
+/**
+ * A set of constraints that specifies the limits of the runtime's
+ * memory use.
+ */
+class EXPORT ResourceConstraints {
+ public:
+ ResourceConstraints();
+ int max_young_space_size() const { return max_young_space_size_; }
+ void set_max_young_space_size(int value) { max_young_space_size_ = value; }
+ int max_old_space_size() const { return max_old_space_size_; }
+ void set_max_old_space_size(int value) { max_old_space_size_ = value; }
+ uint32_t* stack_limit() const { return stack_limit_; }
+ void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
+ private:
+ int max_young_space_size_;
+ int max_old_space_size_;
+ uint32_t* stack_limit_;
+};
+
+
+bool SetResourceConstraints(ResourceConstraints* constraints);
+
+
+// --- E x c e p t i o n s ---
+
+
+typedef void (*FatalErrorCallback)(const char* location, const char* message);
+
+
+typedef void (*MessageCallback)(Handle<Message> message, Handle<Value> data);
+
+
+/**
+ * Schedules an exception to be thrown when returning to JavaScript. When an
+ * exception has been scheduled it is illegal to invoke any JavaScript
+ * operation; the caller must return immediately and only after the exception
+ * has been handled does it become legal to invoke JavaScript operations.
+ */
+Handle<Value> EXPORT ThrowException(Handle<Value> exception);
+
+/**
+ * Create new error objects by calling the corresponding error object
+ * constructor with the message.
+ */
+class EXPORT Exception {
+ public:
+ static Local<Value> RangeError(Handle<String> message);
+ static Local<Value> ReferenceError(Handle<String> message);
+ static Local<Value> SyntaxError(Handle<String> message);
+ static Local<Value> TypeError(Handle<String> message);
+ static Local<Value> Error(Handle<String> message);
+};
+
+
+// --- C o u n t e r s C a l l b a c k s ---
+
+typedef int* (*CounterLookupCallback)(const char* name);
+
+// --- F a i l e d A c c e s s C h e c k C a l l b a c k ---
+typedef void (*FailedAccessCheckCallback)(Local<Object> target,
+ AccessType type,
+ Local<Value> data);
+
+// --- G a r b a g e C o l l e c t i o n C a l l b a c k s
+
+/**
+ * Applications can register a callback function which is called
+ * before and after a major garbage collection. Allocations are not
+ * allowed in the callback function, you therefore cannot manipulate
+ * objects (set or delete properties for example) since it is possible
+ * such operations will result in the allocation of objects.
+ */
+typedef void (*GCCallback)();
+
+
+// --- E x t e r n a l S y m b o l C a l l b a c k ---
+
+/**
+ * Callback used to allocate certain V8 symbols as external strings.
+ *
+ * The data passed to the callback is utf8 encoded.
+ *
+ * Allocations are not allowed in the callback function, you therefore
+ * cannot manipulate objects (set or delete properties for example)
+ * since it is possible such operations will result in the allocation
+ * of objects.
+ */
+typedef String::ExternalStringResource* (*ExternalSymbolCallback)(
+ const char* utf8,
+ size_t length);
+
+
+// --- C o n t e x t G e n e r a t o r ---
+
+/**
+ * Applications must provide a callback function which is called to generate
+ * a context if a context was not deserialized from the snapshot.
+ */
+typedef Persistent<Context> (*ContextGenerator)();
+
+
+/**
+ * Container class for static utility functions.
+ */
+class EXPORT V8 {
+ public:
+ /** Set the callback to invoke in case of fatal errors. */
+ static void SetFatalErrorHandler(FatalErrorCallback that);
+
+ /**
+ * Ignore out-of-memory exceptions.
+ *
+ * V8 running out of memory is treated as a fatal error by default.
+ * This means that the fatal error handler is called and that V8 is
+ * terminated.
+ *
+ * IgnoreOutOfMemoryException can be used to not treat a
+ * out-of-memory situation as a fatal error. This way, the contexts
+ * that did not cause the out of memory problem might be able to
+ * continue execution.
+ */
+ static void IgnoreOutOfMemoryException();
+
+ /**
+ * Check if V8 is dead and therefore unusable. This is the case after
+ * fatal errors such as out-of-memory situations.
+ */
+ static bool IsDead();
+
+ /**
+ * Adds a message listener.
+ *
+ * The same message listener can be added more than once and it that
+ * case it will be called more than once for each message.
+ */
+ static bool AddMessageListener(MessageCallback that,
+ Handle<Value> data = Handle<Value>());
+
+ /**
+ * Remove all message listeners from the specified callback function.
+ */
+ static void RemoveMessageListeners(MessageCallback that);
+
+ /**
+ * Sets V8 flags from a string.
+ */
+ static void SetFlagsFromString(const char* str, int length);
+
+ /**
+ * Sets V8 flags from the command line.
+ */
+ static void SetFlagsFromCommandLine(int* argc,
+ char** argv,
+ bool remove_flags);
+
+ /** Get the version string. */
+ static const char* GetVersion();
+
+ /**
+ * Enables the host application to provide a mechanism for recording
+ * statistics counters.
+ */
+ static void SetCounterFunction(CounterLookupCallback);
+
+ /**
+ * Enables the computation of a sliding window of states. The sliding
+ * window information is recorded in statistics counters.
+ */
+ static void EnableSlidingStateWindow();
+
+ /** Callback function for reporting failed access checks.*/
+ static void SetFailedAccessCheckCallbackFunction(FailedAccessCheckCallback);
+
+ /**
+ * Enables the host application to receive a notification before a
+ * major garbage colletion. Allocations are not allowed in the
+ * callback function, you therefore cannot manipulate objects (set
+ * or delete properties for example) since it is possible such
+ * operations will result in the allocation of objects.
+ */
+ static void SetGlobalGCPrologueCallback(GCCallback);
+
+ /**
+ * Enables the host application to receive a notification after a
+ * major garbage collection. Allocations are not allowed in the
+ * callback function, you therefore cannot manipulate objects (set
+ * or delete properties for example) since it is possible such
+ * operations will result in the allocation of objects.
+ */
+ static void SetGlobalGCEpilogueCallback(GCCallback);
+
+ /**
+ * Applications can register a callback that will be used when
+ * allocating most of the V8 symbols. The callback must return an
+ * external string resource that represents the symbols.
+ *
+ * Most often when performing a property lookup the key will be a
+ * symbol. Allocating symbols as external strings can reduce the
+ * amount of string conversions needed when using interceptors and
+ * accessors.
+ *
+ * \note This is an experimental feature and it might be removed.
+ */
+ static void SetExternalSymbolCallback(ExternalSymbolCallback);
+
+ /**
+ * Allows the host application to group objects together. If one
+ * object in the group is alive, all objects in the group are alive.
+ * After each garbage collection, object groups are removed. It is
+ * intended to be used in the before-garbage-collection callback
+ * function, for instance to simulate DOM tree connections among JS
+ * wrapper objects.
+ */
+ static void AddObjectGroup(Persistent<Value>* objects, size_t length);
+
+ /**
+ * Initializes from snapshot if possible. Otherwise, attempts to
+ * initialize from scratch.
+ */
+ static bool Initialize();
+
+ /**
+ * Adjusts the amount of registered external memory. Used to give
+ * V8 an indication of the amount of externally allocated memory
+ * that is kept alive by JavaScript objects. V8 uses this to decide
+ * when to perform global garbage collections. Registering
+ * externally allocated memory will trigger global garbage
+ * collections more often than otherwise in an attempt to garbage
+ * collect the JavaScript objects keeping the externally allocated
+ * memory alive.
+ *
+ * \param change_in_bytes the change in externally allocated memory
+ * that is kept alive by JavaScript objects.
+ * \returns the adjusted value.
+ */
+ static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
+
+ private:
+ V8();
+
+ static void** GlobalizeReference(void** handle);
+ static void DisposeGlobal(void** global_handle);
+ static void MakeWeak(void** global_handle, void* data, WeakReferenceCallback);
+ static void ClearWeak(void** global_handle);
+ static bool IsGlobalNearDeath(void** global_handle);
+ static bool IsGlobalWeak(void** global_handle);
+
+ template <class T> friend class Handle;
+ template <class T> friend class Local;
+ template <class T> friend class Persistent;
+ friend class Context;
+};
+
+
+/**
+ * An external exception handler.
+ */
+class EXPORT TryCatch {
+ public:
+
+ /**
+ * Creates a new try/catch block and registers it with v8.
+ */
+ TryCatch();
+
+ /**
+ * Unregisters and deletes this try/catch block.
+ */
+ ~TryCatch();
+
+ /**
+ * Returns true if an exception has been caught by this try/catch block.
+ */
+ bool HasCaught() const;
+
+ /**
+ * Returns the exception caught by this try/catch block. If no exception has
+ * been caught an empty handle is returned.
+ *
+ * The returned handle is valid until this TryCatch block has been destroyed.
+ */
+ Local<Value> Exception() const;
+
+ /**
+ * Returns the message associated with this exception. If there is
+ * no message associated an empty handle is returned.
+ *
+ * The returned handle is valid until this TryCatch block has been
+ * destroyed.
+ */
+ Local<v8::Message> Message() const;
+
+ /**
+ * Clears any exceptions that may have been caught by this try/catch block.
+ * After this method has been called, HasCaught() will return false.
+ *
+ * It is not necessary to clear a try/catch block before using it again; if
+ * another exception is thrown the previously caught exception will just be
+ * overwritten. However, it is often a good idea since it makes it easier
+ * to determine which operation threw a given exception.
+ */
+ void Reset();
+
+ /**
+ * Set verbosity of the external exception handler.
+ *
+ * By default, exceptions that are caught by an external exception
+ * handler are not reported. Call SetVerbose with true on an
+ * external exception handler to have exceptions caught by the
+ * handler reported as if they were not caught.
+ */
+ void SetVerbose(bool value);
+
+ /**
+ * Set whether or not this TryCatch should capture a Message object
+ * which holds source information about where the exception
+ * occurred. True by default.
+ */
+ void SetCaptureMessage(bool value);
+
+ public:
+ TryCatch* next_;
+ void* exception_;
+ void* message_;
+ bool is_verbose_;
+ bool capture_message_;
+ void* js_handler_;
+};
+
+
+// --- C o n t e x t ---
+
+
+/**
+ * Ignore
+ */
+class EXPORT ExtensionConfiguration {
+ public:
+ ExtensionConfiguration(int name_count, const char* names[])
+ : name_count_(name_count), names_(names) { }
+ private:
+ friend class ImplementationUtilities;
+ int name_count_;
+ const char** names_;
+};
+
+
+/**
+ * A sandboxed execution context with its own set of built-in objects
+ * and functions.
+ */
+class EXPORT Context {
+ public:
+ /** Returns the global object of the context. */
+ Local<Object> Global();
+
+ /**
+ * Detaches the global object from its context before
+ * the global object can be reused to create a new context.
+ */
+ void DetachGlobal();
+
+ /** Creates a new context. */
+ static Persistent<Context> New(
+ ExtensionConfiguration* extensions = 0,
+ Handle<ObjectTemplate> global_template = Handle<ObjectTemplate>(),
+ Handle<Value> global_object = Handle<Value>());
+
+ /** Returns the last entered context. */
+ static Local<Context> GetEntered();
+
+ /** Returns the context that is on the top of the stack. */
+ static Local<Context> GetCurrent();
+
+ /**
+ * Sets the security token for the context. To access an object in
+ * another context, the security tokens must match.
+ */
+ void SetSecurityToken(Handle<Value> token);
+
+ /** Restores the security token to the default value. */
+ void UseDefaultSecurityToken();
+
+ /** Returns the security token of this context.*/
+ Handle<Value> GetSecurityToken();
+
+ /**
+ * Enter this context. After entering a context, all code compiled
+ * and run is compiled and run in this context. If another context
+ * is already entered, this old context is saved so it can be
+ * restored when the new context is exited.
+ */
+ void Enter();
+
+ /**
+ * Exit this context. Exiting the current context restores the
+ * context that was in place when entering the current context.
+ */
+ void Exit();
+
+ /** Returns true if the context has experienced an out of memory situation. */
+ bool HasOutOfMemoryException();
+
+ /** Returns true if V8 has a current context. */
+ static bool InContext();
+
+ /**
+ * Stack-allocated class which sets the execution context for all
+ * operations executed within a local scope.
+ */
+ class EXPORT Scope {
+ public:
+ inline Scope(Handle<Context> context) : context_(context) {
+ context_->Enter();
+ }
+ inline ~Scope() { context_->Exit(); }
+ private:
+ Handle<Context> context_;
+ };
+
+ private:
+ friend class Value;
+ friend class Script;
+ friend class Object;
+ friend class Function;
+};
+
+
+/**
+ * Multiple threads in V8 are allowed, but only one thread at a time
+ * is allowed to use V8. The definition of 'using V8' includes
+ * accessing handles or holding onto object pointers obtained from V8
+ * handles. It is up to the user of V8 to ensure (perhaps with
+ * locking) that this constraint is not violated.
+ *
+ * If you wish to start using V8 in a thread you can do this by constructing
+ * a v8::Locker object. After the code using V8 has completed for the
+ * current thread you can call the destructor. This can be combined
+ * with C++ scope-based construction as follows:
+ *
+ * \code
+ * ...
+ * {
+ * v8::Locker locker;
+ * ...
+ * // Code using V8 goes here.
+ * ...
+ * } // Destructor called here
+ * \endcode
+ *
+ * If you wish to stop using V8 in a thread A you can do this by either
+ * by destroying the v8::Locker object as above or by constructing a
+ * v8::Unlocker object:
+ *
+ * \code
+ * {
+ * v8::Unlocker unlocker;
+ * ...
+ * // Code not using V8 goes here while V8 can run in another thread.
+ * ...
+ * } // Destructor called here.
+ * \endcode
+ *
+ * The Unlocker object is intended for use in a long-running callback
+ * from V8, where you want to release the V8 lock for other threads to
+ * use.
+ *
+ * The v8::Locker is a recursive lock. That is, you can lock more than
+ * once in a given thread. This can be useful if you have code that can
+ * be called either from code that holds the lock or from code that does
+ * not. The Unlocker is not recursive so you can not have several
+ * Unlockers on the stack at once, and you can not use an Unlocker in a
+ * thread that is not inside a Locker's scope.
+ *
+ * An unlocker will unlock several lockers if it has to and reinstate
+ * the correct depth of locking on its destruction. eg.:
+ *
+ * \code
+ * // V8 not locked.
+ * {
+ * v8::Locker locker;
+ * // V8 locked.
+ * {
+ * v8::Locker another_locker;
+ * // V8 still locked (2 levels).
+ * {
+ * v8::Unlocker unlocker;
+ * // V8 not locked.
+ * }
+ * // V8 locked again (2 levels).
+ * }
+ * // V8 still locked (1 level).
+ * }
+ * // V8 Now no longer locked.
+ * \endcode
+ */
+class EXPORT Unlocker {
+ public:
+ Unlocker();
+ ~Unlocker();
+};
+
+
+class EXPORT Locker {
+ public:
+ Locker();
+ ~Locker();
+
+ /**
+ * Start preemption.
+ *
+ * When preemption is started, a timer is fired every n milli seconds
+ * that will switch between multiple threads that are in contention
+ * for the V8 lock.
+ */
+ static void StartPreemption(int every_n_ms);
+
+ /**
+ * Stop preemption.
+ */
+ static void StopPreemption();
+
+ /**
+ * Returns whether or not the locker is locked by the current thread.
+ */
+ static bool IsLocked();
+
+ private:
+ bool has_lock_;
+ bool top_level_;
+
+ // Disallow copying and assigning.
+ Locker(const Locker&);
+ void operator=(const Locker&);
+};
+
+
+
+// --- I m p l e m e n t a t i o n ---
+
+template <class T>
+Handle<T>::Handle() : val_(0) { }
+
+
+template <class T>
+Local<T>::Local() : Handle<T>() { }
+
+
+template <class T>
+Local<T> Local<T>::New(Handle<T> that) {
+ if (that.IsEmpty()) return Local<T>();
+ void** p = reinterpret_cast<void**>(*that);
+ return Local<T>(reinterpret_cast<T*>(HandleScope::CreateHandle(*p)));
+}
+
+
+template <class T>
+Persistent<T> Persistent<T>::New(Handle<T> that) {
+ if (that.IsEmpty()) return Persistent<T>();
+ void** p = reinterpret_cast<void**>(*that);
+ return Persistent<T>(reinterpret_cast<T*>(V8::GlobalizeReference(p)));
+}
+
+
+template <class T>
+bool Persistent<T>::IsNearDeath() {
+ if (this->IsEmpty()) return false;
+ return V8::IsGlobalNearDeath(reinterpret_cast<void**>(**this));
+}
+
+
+template <class T>
+bool Persistent<T>::IsWeak() {
+ if (this->IsEmpty()) return false;
+ return V8::IsGlobalWeak(reinterpret_cast<void**>(**this));
+}
+
+
+template <class T>
+void Persistent<T>::Dispose() {
+ if (this->IsEmpty()) return;
+ V8::DisposeGlobal(reinterpret_cast<void**>(**this));
+}
+
+
+template <class T>
+Persistent<T>::Persistent() : Handle<T>() { }
+
+template <class T>
+void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
+ V8::MakeWeak(reinterpret_cast<void**>(**this), parameters, callback);
+}
+
+template <class T>
+void Persistent<T>::ClearWeak() {
+ V8::ClearWeak(reinterpret_cast<void**>(**this));
+}
+
+template <class T>
+T* Handle<T>::operator->() {
+ return val_;
+}
+
+
+template <class T>
+T* Handle<T>::operator*() {
+ return val_;
+}
+
+
+Local<Value> Arguments::operator[](int i) const {
+ if (i < 0 || length_ <= i) return Local<Value>(*Undefined());
+ return Local<Value>(reinterpret_cast<Value*>(values_ - i));
+}
+
+
+Local<Function> Arguments::Callee() const {
+ return callee_;
+}
+
+
+Local<Object> Arguments::This() const {
+ return Local<Object>(reinterpret_cast<Object*>(values_ + 1));
+}
+
+
+Local<Object> Arguments::Holder() const {
+ return holder_;
+}
+
+
+Local<Value> Arguments::Data() const {
+ return data_;
+}
+
+
+bool Arguments::IsConstructCall() const {
+ return is_construct_call_;
+}
+
+
+int Arguments::Length() const {
+ return length_;
+}
+
+
+Local<Value> AccessorInfo::Data() const {
+ return data_;
+}
+
+
+Local<Object> AccessorInfo::This() const {
+ return self_;
+}
+
+
+Local<Object> AccessorInfo::Holder() const {
+ return holder_;
+}
+
+
+template <class T>
+Local<T> HandleScope::Close(Handle<T> value) {
+ void** after = RawClose(reinterpret_cast<void**>(*value));
+ return Local<T>(reinterpret_cast<T*>(after));
+}
+
+Handle<Value> ScriptOrigin::ResourceName() const {
+ return resource_name_;
+}
+
+
+Handle<Integer> ScriptOrigin::ResourceLineOffset() const {
+ return resource_line_offset_;
+}
+
+
+Handle<Integer> ScriptOrigin::ResourceColumnOffset() const {
+ return resource_column_offset_;
+}
+
+
+Handle<Boolean> Boolean::New(bool value) {
+ return value ? True() : False();
+}
+
+
+void Template::Set(const char* name, v8::Handle<Data> value) {
+ Set(v8::String::New(name), value);
+}
+
+
+/**
+ * \example shell.cc
+ * A simple shell that takes a list of expressions on the
+ * command-line and executes them.
+ */
+
+
+/**
+ * \example process.cc
+ */
+
+
+} // namespace v8
+
+
+#undef EXPORT
+#undef EXPORT_INLINE
+#undef TYPE_CHECK
+
+
+#endif // V8_H_
diff --git a/Plugins/skins/skins.vcproj b/Plugins/skins/skins.vcproj index 9515ae8..dbef34f 100644 --- a/Plugins/skins/skins.vcproj +++ b/Plugins/skins/skins.vcproj @@ -48,7 +48,7 @@ <Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="../../include,sdk"
+ AdditionalIncludeDirectories="../../include,sdk,libs"
PreprocessorDefinitions="WIN32;W32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug/skins.pch"
@@ -74,7 +74,7 @@ <Tool
Name="VCLinkerTool"
AdditionalOptions="/ALIGN:4096 /filealign:0x200 /ignore:4108 "
- AdditionalDependencies="msimg32.lib comctl32.lib"
+ AdditionalDependencies="msimg32.lib comctl32.lib $(ProjectDir)libs\v8_g.lib"
OutputFile="..\..\bin\debug\Plugins\skins.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
@@ -146,7 +146,7 @@ Optimization="2"
InlineFunctionExpansion="0"
WholeProgramOptimization="true"
- AdditionalIncludeDirectories="../../include,sdk"
+ AdditionalIncludeDirectories="../../include,sdk,libs"
PreprocessorDefinitions="WIN32;W32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS"
StringPooling="true"
RuntimeLibrary="0"
@@ -174,7 +174,7 @@ <Tool
Name="VCLinkerTool"
AdditionalOptions="/ALIGN:4096 /filealign:0x200 /ignore:4108 "
- AdditionalDependencies="msimg32.lib comctl32.lib"
+ AdditionalDependencies="msimg32.lib comctl32.lib $(ProjectDir)libs\v8.lib"
OutputFile="..\..\bin\release\Plugins\skins.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
@@ -247,7 +247,7 @@ <Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="../../include,sdk"
+ AdditionalIncludeDirectories="../../include,sdk,libs"
PreprocessorDefinitions="WIN32;W32;_DEBUG;_WINDOWS;UNICODE;_USRDLL;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="1"
PrecompiledHeaderFile=".\Unicode_Debug/skins.pch"
@@ -273,7 +273,7 @@ <Tool
Name="VCLinkerTool"
AdditionalOptions="/ALIGN:4096 /filealign:0x200 /ignore:4108 "
- AdditionalDependencies="msimg32.lib comctl32.lib"
+ AdditionalDependencies="msimg32.lib comctl32.lib $(ProjectDir)libs\v8_g.lib"
OutputFile="..\..\bin\debug unicode\Plugins\skinsW.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
@@ -346,7 +346,7 @@ InlineFunctionExpansion="0"
FavorSizeOrSpeed="1"
WholeProgramOptimization="true"
- AdditionalIncludeDirectories="../../include,sdk"
+ AdditionalIncludeDirectories="../../include,sdk,libs"
PreprocessorDefinitions="WIN32;W32;NDEBUG;_WINDOWS;UNICODE;_USRDLL;_CRT_SECURE_NO_WARNINGS"
StringPooling="true"
RuntimeLibrary="0"
@@ -374,7 +374,7 @@ <Tool
Name="VCLinkerTool"
AdditionalOptions="/ALIGN:4096 /filealign:0x200 /ignore:4108 "
- AdditionalDependencies="msimg32.lib comctl32.lib"
+ AdditionalDependencies="msimg32.lib comctl32.lib $(ProjectDir)libs\v8.lib"
OutputFile="..\..\bin\release unicode\Plugins\skinsW.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
@@ -449,6 +449,174 @@ RelativePath="resource.h"
>
</File>
+ <Filter
+ Name="SkinLib Header Files"
+ >
+ <File
+ RelativePath=".\SkinLib\globals.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\Position.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\scope.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\Size.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\SkinnedDialog.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\SkinOption.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\SkinOptions.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\tstring.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\utf8_helpers.h"
+ >
+ </File>
+ <Filter
+ Name="Fields Header Files"
+ >
+ <File
+ RelativePath=".\SkinLib\ButtonField.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ControlField.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\Dialog.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\EditField.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\Field.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\IconField.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ImageField.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\LabelField.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\TextField.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="v8 Header Files"
+ >
+ <File
+ RelativePath=".\SkinLib\BorderState_v8_wrapper.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ControlFieldState_v8_wrapper.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\DialogState_v8_wrapper.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\FieldState_v8_wrapper.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\FontState_v8_wrapper.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\SkinOption_v8_wrapper.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\TextFieldState_v8_wrapper.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\V8Script.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\V8Wrappers.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="States Header Files"
+ >
+ <File
+ RelativePath=".\SkinLib\BorderState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ButtonFieldState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ControlFieldState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\DialogState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\EditFieldState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\FieldState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\FontState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\IconFieldState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ImageFieldState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\LabelFieldState.h"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\TextFieldState.h"
+ >
+ </File>
+ </Filter>
+ </Filter>
</Filter>
<Filter
Name="Resource Files"
@@ -695,6 +863,154 @@ />
</FileConfiguration>
</File>
+ <Filter
+ Name="SkinLib Source Files"
+ >
+ <File
+ RelativePath=".\SkinLib\Position.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\Size.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\SkinnedDialog.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\SkinOptions.cpp"
+ >
+ </File>
+ <Filter
+ Name="Fields Source Files"
+ >
+ <File
+ RelativePath=".\SkinLib\ButtonField.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ControlField.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\Dialog.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\EditField.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\Field.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\IconField.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ImageField.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\LabelField.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\TextField.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="v8 Source Files"
+ >
+ <File
+ RelativePath=".\SkinLib\BorderState_v8_wrapper.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ControlFieldState_v8_wrapper.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\DialogState_v8_wrapper.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\FieldState_v8_wrapper.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\FontState_v8_wrapper.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\SkinOption_v8_wrapper.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\TextFieldState_v8_wrapper.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\V8Script.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\V8Wrappers.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="States Source Files"
+ >
+ <File
+ RelativePath=".\SkinLib\BorderState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ButtonFieldState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ControlFieldState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\DialogState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\EditFieldState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\FieldState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\FontState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\IconFieldState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\ImageFieldState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\LabelFieldState.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\SkinLib\TextFieldState.cpp"
+ >
+ </File>
+ </Filter>
+ </Filter>
</Filter>
<Filter
Name="Docs"
|