From bb6784e0e1a385cdd20b41d3254093e89a210332 Mon Sep 17 00:00:00 2001 From: pescuma Date: Wed, 31 Dec 2008 21:12:58 +0000 Subject: skins: Added SkinLib git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@120 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/skins/SkinLib/BorderState.cpp | 59 + Plugins/skins/SkinLib/BorderState.h | 28 + Plugins/skins/SkinLib/BorderState_v8_wrapper.cpp | 90 + Plugins/skins/SkinLib/BorderState_v8_wrapper.h | 10 + Plugins/skins/SkinLib/ButtonField.cpp | 22 + Plugins/skins/SkinLib/ButtonField.h | 19 + Plugins/skins/SkinLib/ButtonFieldState.cpp | 24 + Plugins/skins/SkinLib/ButtonFieldState.h | 21 + Plugins/skins/SkinLib/ControlField.cpp | 122 + Plugins/skins/SkinLib/ControlField.h | 37 + Plugins/skins/SkinLib/ControlFieldState.cpp | 86 + Plugins/skins/SkinLib/ControlFieldState.h | 39 + .../skins/SkinLib/ControlFieldState_v8_wrapper.cpp | 38 + .../skins/SkinLib/ControlFieldState_v8_wrapper.h | 10 + Plugins/skins/SkinLib/Dialog.cpp | 72 + Plugins/skins/SkinLib/Dialog.h | 34 + Plugins/skins/SkinLib/DialogState.cpp | 81 + Plugins/skins/SkinLib/DialogState.h | 45 + Plugins/skins/SkinLib/DialogState_v8_wrapper.cpp | 54 + Plugins/skins/SkinLib/DialogState_v8_wrapper.h | 10 + Plugins/skins/SkinLib/EditField.cpp | 22 + Plugins/skins/SkinLib/EditField.h | 19 + Plugins/skins/SkinLib/EditFieldState.cpp | 52 + Plugins/skins/SkinLib/EditFieldState.h | 22 + Plugins/skins/SkinLib/Field.cpp | 29 + Plugins/skins/SkinLib/Field.h | 55 + Plugins/skins/SkinLib/FieldState.cpp | 175 ++ Plugins/skins/SkinLib/FieldState.h | 58 + Plugins/skins/SkinLib/FieldState.rec | 54 + Plugins/skins/SkinLib/FieldState_v8_wrapper.cpp | 180 ++ Plugins/skins/SkinLib/FieldState_v8_wrapper.h | 10 + Plugins/skins/SkinLib/FontState.cpp | 185 ++ Plugins/skins/SkinLib/FontState.h | 57 + Plugins/skins/SkinLib/FontState_v8_wrapper.cpp | 128 + Plugins/skins/SkinLib/FontState_v8_wrapper.h | 10 + Plugins/skins/SkinLib/IconField.cpp | 37 + Plugins/skins/SkinLib/IconField.h | 27 + Plugins/skins/SkinLib/IconFieldState.cpp | 31 + Plugins/skins/SkinLib/IconFieldState.h | 26 + Plugins/skins/SkinLib/ImageField.cpp | 37 + Plugins/skins/SkinLib/ImageField.h | 26 + Plugins/skins/SkinLib/ImageFieldState.cpp | 31 + Plugins/skins/SkinLib/ImageFieldState.h | 26 + Plugins/skins/SkinLib/LabelField.cpp | 22 + Plugins/skins/SkinLib/LabelField.h | 20 + Plugins/skins/SkinLib/LabelFieldState.cpp | 29 + Plugins/skins/SkinLib/LabelFieldState.h | 23 + Plugins/skins/SkinLib/Position.cpp | 9 + Plugins/skins/SkinLib/Position.h | 16 + Plugins/skins/SkinLib/Size.cpp | 84 + Plugins/skins/SkinLib/Size.h | 27 + Plugins/skins/SkinLib/SkinOption.h | 1 + Plugins/skins/SkinLib/SkinOption_v8_wrapper.cpp | 105 + Plugins/skins/SkinLib/SkinOption_v8_wrapper.h | 10 + Plugins/skins/SkinLib/SkinOptions.cpp | 216 ++ Plugins/skins/SkinLib/SkinOptions.h | 98 + Plugins/skins/SkinLib/SkinnedDialog.cpp | 252 ++ Plugins/skins/SkinLib/SkinnedDialog.h | 89 + Plugins/skins/SkinLib/TextField.cpp | 77 + Plugins/skins/SkinLib/TextField.h | 35 + Plugins/skins/SkinLib/TextFieldState.cpp | 58 + Plugins/skins/SkinLib/TextFieldState.h | 36 + .../skins/SkinLib/TextFieldState_v8_wrapper.cpp | 38 + Plugins/skins/SkinLib/TextFieldState_v8_wrapper.h | 10 + Plugins/skins/SkinLib/V8Script.cpp | 220 ++ Plugins/skins/SkinLib/V8Script.h | 41 + Plugins/skins/SkinLib/V8Wrappers.cpp | 532 +++++ Plugins/skins/SkinLib/V8Wrappers.h | 73 + Plugins/skins/SkinLib/globals.h | 11 + Plugins/skins/SkinLib/scope.h | 37 + Plugins/skins/SkinLib/tstring.h | 13 + Plugins/skins/SkinLib/utf8_helpers.h | 124 + Plugins/skins/libs/v8-debug.h | 164 ++ Plugins/skins/libs/v8.h | 2472 ++++++++++++++++++++ Plugins/skins/skins.vcproj | 332 ++- 75 files changed, 7464 insertions(+), 8 deletions(-) create mode 100644 Plugins/skins/SkinLib/BorderState.cpp create mode 100644 Plugins/skins/SkinLib/BorderState.h create mode 100644 Plugins/skins/SkinLib/BorderState_v8_wrapper.cpp create mode 100644 Plugins/skins/SkinLib/BorderState_v8_wrapper.h create mode 100644 Plugins/skins/SkinLib/ButtonField.cpp create mode 100644 Plugins/skins/SkinLib/ButtonField.h create mode 100644 Plugins/skins/SkinLib/ButtonFieldState.cpp create mode 100644 Plugins/skins/SkinLib/ButtonFieldState.h create mode 100644 Plugins/skins/SkinLib/ControlField.cpp create mode 100644 Plugins/skins/SkinLib/ControlField.h create mode 100644 Plugins/skins/SkinLib/ControlFieldState.cpp create mode 100644 Plugins/skins/SkinLib/ControlFieldState.h create mode 100644 Plugins/skins/SkinLib/ControlFieldState_v8_wrapper.cpp create mode 100644 Plugins/skins/SkinLib/ControlFieldState_v8_wrapper.h create mode 100644 Plugins/skins/SkinLib/Dialog.cpp create mode 100644 Plugins/skins/SkinLib/Dialog.h create mode 100644 Plugins/skins/SkinLib/DialogState.cpp create mode 100644 Plugins/skins/SkinLib/DialogState.h create mode 100644 Plugins/skins/SkinLib/DialogState_v8_wrapper.cpp create mode 100644 Plugins/skins/SkinLib/DialogState_v8_wrapper.h create mode 100644 Plugins/skins/SkinLib/EditField.cpp create mode 100644 Plugins/skins/SkinLib/EditField.h create mode 100644 Plugins/skins/SkinLib/EditFieldState.cpp create mode 100644 Plugins/skins/SkinLib/EditFieldState.h create mode 100644 Plugins/skins/SkinLib/Field.cpp create mode 100644 Plugins/skins/SkinLib/Field.h create mode 100644 Plugins/skins/SkinLib/FieldState.cpp create mode 100644 Plugins/skins/SkinLib/FieldState.h create mode 100644 Plugins/skins/SkinLib/FieldState.rec create mode 100644 Plugins/skins/SkinLib/FieldState_v8_wrapper.cpp create mode 100644 Plugins/skins/SkinLib/FieldState_v8_wrapper.h create mode 100644 Plugins/skins/SkinLib/FontState.cpp create mode 100644 Plugins/skins/SkinLib/FontState.h create mode 100644 Plugins/skins/SkinLib/FontState_v8_wrapper.cpp create mode 100644 Plugins/skins/SkinLib/FontState_v8_wrapper.h create mode 100644 Plugins/skins/SkinLib/IconField.cpp create mode 100644 Plugins/skins/SkinLib/IconField.h create mode 100644 Plugins/skins/SkinLib/IconFieldState.cpp create mode 100644 Plugins/skins/SkinLib/IconFieldState.h create mode 100644 Plugins/skins/SkinLib/ImageField.cpp create mode 100644 Plugins/skins/SkinLib/ImageField.h create mode 100644 Plugins/skins/SkinLib/ImageFieldState.cpp create mode 100644 Plugins/skins/SkinLib/ImageFieldState.h create mode 100644 Plugins/skins/SkinLib/LabelField.cpp create mode 100644 Plugins/skins/SkinLib/LabelField.h create mode 100644 Plugins/skins/SkinLib/LabelFieldState.cpp create mode 100644 Plugins/skins/SkinLib/LabelFieldState.h create mode 100644 Plugins/skins/SkinLib/Position.cpp create mode 100644 Plugins/skins/SkinLib/Position.h create mode 100644 Plugins/skins/SkinLib/Size.cpp create mode 100644 Plugins/skins/SkinLib/Size.h create mode 100644 Plugins/skins/SkinLib/SkinOption.h create mode 100644 Plugins/skins/SkinLib/SkinOption_v8_wrapper.cpp create mode 100644 Plugins/skins/SkinLib/SkinOption_v8_wrapper.h create mode 100644 Plugins/skins/SkinLib/SkinOptions.cpp create mode 100644 Plugins/skins/SkinLib/SkinOptions.h create mode 100644 Plugins/skins/SkinLib/SkinnedDialog.cpp create mode 100644 Plugins/skins/SkinLib/SkinnedDialog.h create mode 100644 Plugins/skins/SkinLib/TextField.cpp create mode 100644 Plugins/skins/SkinLib/TextField.h create mode 100644 Plugins/skins/SkinLib/TextFieldState.cpp create mode 100644 Plugins/skins/SkinLib/TextFieldState.h create mode 100644 Plugins/skins/SkinLib/TextFieldState_v8_wrapper.cpp create mode 100644 Plugins/skins/SkinLib/TextFieldState_v8_wrapper.h create mode 100644 Plugins/skins/SkinLib/V8Script.cpp create mode 100644 Plugins/skins/SkinLib/V8Script.h create mode 100644 Plugins/skins/SkinLib/V8Wrappers.cpp create mode 100644 Plugins/skins/SkinLib/V8Wrappers.h create mode 100644 Plugins/skins/SkinLib/globals.h create mode 100644 Plugins/skins/SkinLib/scope.h create mode 100644 Plugins/skins/SkinLib/tstring.h create mode 100644 Plugins/skins/SkinLib/utf8_helpers.h create mode 100644 Plugins/skins/libs/v8-debug.h create mode 100644 Plugins/skins/libs/v8.h 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 +#include "BorderState.h" + +using namespace v8; + + +#ifdef UNICODE +# define V8_TCHAR uint16_t +#else +# define V8_TCHAR char +#endif + + +static Handle Get_BorderState_left(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + BorderState *tmp = (BorderState *) wrap->Value(); + return Int32::New(tmp->getLeft()); +} + +static void Set_BorderState_left(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + BorderState *tmp = (BorderState *) wrap->Value(); + tmp->setLeft(value->Int32Value()); +} + + +static Handle Get_BorderState_right(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + BorderState *tmp = (BorderState *) wrap->Value(); + return Int32::New(tmp->getRight()); +} + +static void Set_BorderState_right(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + BorderState *tmp = (BorderState *) wrap->Value(); + tmp->setRight(value->Int32Value()); +} + + +static Handle Get_BorderState_top(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + BorderState *tmp = (BorderState *) wrap->Value(); + return Int32::New(tmp->getTop()); +} + +static void Set_BorderState_top(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + BorderState *tmp = (BorderState *) wrap->Value(); + tmp->setTop(value->Int32Value()); +} + + +static Handle Get_BorderState_bottom(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + BorderState *tmp = (BorderState *) wrap->Value(); + return Int32::New(tmp->getBottom()); +} + +static void Set_BorderState_bottom(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + BorderState *tmp = (BorderState *) wrap->Value(); + tmp->setBottom(value->Int32Value()); +} + + +void AddBorderStateAcessors(Handle &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 + +void AddBorderStateAcessors(v8::Handle &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 +#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 Get_ControlFieldState_text(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + ControlFieldState *tmp = (ControlFieldState *) wrap->Value(); + return String::New((const V8_TCHAR *) tmp->getText()); +} + +static void Set_ControlFieldState_text(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + ControlFieldState *tmp = (ControlFieldState *) wrap->Value(); + String::Utf8Value utf8_value(value); + tmp->setText(Utf8ToTchar(*utf8_value)); +} + + +void AddControlFieldStateAcessors(Handle &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 + +void AddControlFieldStateAcessors(v8::Handle &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 +#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 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 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 +#include "DialogState.h" + +using namespace v8; + + +#ifdef UNICODE +# define V8_TCHAR uint16_t +#else +# define V8_TCHAR char +#endif + + +static Handle Get_DialogState_width(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + DialogState *tmp = (DialogState *) wrap->Value(); + return Int32::New(tmp->getWidth()); +} + +static void Set_DialogState_width(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + DialogState *tmp = (DialogState *) wrap->Value(); + tmp->setWidth(value->Int32Value()); +} + + +static Handle Get_DialogState_height(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + DialogState *tmp = (DialogState *) wrap->Value(); + return Int32::New(tmp->getHeight()); +} + +static void Set_DialogState_height(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + DialogState *tmp = (DialogState *) wrap->Value(); + tmp->setHeight(value->Int32Value()); +} + + +void AddDialogStateAcessors(Handle &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 + +void AddDialogStateAcessors(v8::Handle &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 +#include +#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 +#include "FieldState.h" + +using namespace v8; + + +#ifdef UNICODE +# define V8_TCHAR uint16_t +#else +# define V8_TCHAR char +#endif + + +static Handle Get_FieldState_x(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Int32::New(tmp->getX()); +} + +static void Set_FieldState_x(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setX(value->Int32Value()); +} + + +static Handle Get_FieldState_y(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Int32::New(tmp->getY()); +} + +static void Set_FieldState_y(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setY(value->Int32Value()); +} + + +static Handle Get_FieldState_width(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Int32::New(tmp->getWidth()); +} + +static void Set_FieldState_width(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setWidth(value->Int32Value()); +} + + +static Handle Get_FieldState_height(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Int32::New(tmp->getHeight()); +} + +static void Set_FieldState_height(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setHeight(value->Int32Value()); +} + + +static Handle Get_FieldState_left(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Int32::New(tmp->getLeft()); +} + +static void Set_FieldState_left(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setLeft(value->Int32Value()); +} + + +static Handle Get_FieldState_top(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Int32::New(tmp->getTop()); +} + +static void Set_FieldState_top(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setTop(value->Int32Value()); +} + + +static Handle Get_FieldState_right(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Int32::New(tmp->getRight()); +} + +static void Set_FieldState_right(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setRight(value->Int32Value()); +} + + +static Handle Get_FieldState_bottom(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Int32::New(tmp->getBottom()); +} + +static void Set_FieldState_bottom(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setBottom(value->Int32Value()); +} + + +static Handle Get_FieldState_visible(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + return Boolean::New(tmp->isVisible()); +} + +static void Set_FieldState_visible(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FieldState *tmp = (FieldState *) wrap->Value(); + tmp->setVisible(value->BooleanValue()); +} + + +void AddFieldStateAcessors(Handle &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 + +void AddFieldStateAcessors(v8::Handle &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 +#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 Get_FontState_face(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + return String::New((const V8_TCHAR *) tmp->getFace()); +} + +static void Set_FontState_face(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + String::Utf8Value utf8_value(value); + tmp->setFace(Utf8ToTchar(*utf8_value)); +} + + +static Handle Get_FontState_size(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + return Int32::New(tmp->getSize()); +} + +static void Set_FontState_size(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + tmp->setSize(value->Int32Value()); +} + + +static Handle Get_FontState_italic(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + return Boolean::New(tmp->isItalic()); +} + +static void Set_FontState_italic(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + tmp->setItalic(value->BooleanValue()); +} + + +static Handle Get_FontState_bold(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + return Boolean::New(tmp->isBold()); +} + +static void Set_FontState_bold(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + tmp->setBold(value->BooleanValue()); +} + + +static Handle Get_FontState_underline(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + return Boolean::New(tmp->isUnderline()); +} + +static void Set_FontState_underline(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + tmp->setUnderline(value->BooleanValue()); +} + + +static Handle Get_FontState_strikeOut(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + return Boolean::New(tmp->isStrikeOut()); +} + +static void Set_FontState_strikeOut(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + FontState *tmp = (FontState *) wrap->Value(); + tmp->setStrikeOut(value->BooleanValue()); +} + + +void AddFontStateAcessors(Handle &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 + +void AddFontStateAcessors(v8::Handle &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 +#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 Get_SkinOption_description(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + SkinOption *tmp = (SkinOption *) wrap->Value(); + return String::New((const V8_TCHAR *) tmp->getDescription()); +} + +static void Set_SkinOption_description(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + SkinOption *tmp = (SkinOption *) wrap->Value(); + String::Utf8Value utf8_value(value); + tmp->setDescription(Utf8ToTchar(*utf8_value)); +} + + +static Handle Get_SkinOption_min(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + SkinOption *tmp = (SkinOption *) wrap->Value(); + return Int32::New(tmp->getMin()); +} + +static void Set_SkinOption_min(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + SkinOption *tmp = (SkinOption *) wrap->Value(); + tmp->setMin(value->Int32Value()); +} + + +static Handle Get_SkinOption_max(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + SkinOption *tmp = (SkinOption *) wrap->Value(); + return Int32::New(tmp->getMax()); +} + +static void Set_SkinOption_max(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + SkinOption *tmp = (SkinOption *) wrap->Value(); + tmp->setMax(value->Int32Value()); +} + + +static Handle Get_SkinOption_type(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::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 property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::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 &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 + +void AddSkinOptionAcessors(v8::Handle &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 +#include "tstring.h" +#include + + +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 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 +#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 +#include +#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 +#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 Get_TextFieldState_text(Local property, const AccessorInfo &info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + TextFieldState *tmp = (TextFieldState *) wrap->Value(); + return String::New((const V8_TCHAR *) tmp->getText()); +} + +static void Set_TextFieldState_text(Local property, Local value, const AccessorInfo& info) +{ + Local self = info.Holder(); + Local wrap = Local::Cast(self->GetInternalField(0)); + TextFieldState *tmp = (TextFieldState *) wrap->Value(); + String::Utf8Value utf8_value(value); + tmp->setText(Utf8ToTchar(*utf8_value)); +} + + +void AddTextFieldStateAcessors(Handle &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 + +void AddTextFieldStateAcessors(v8::Handle &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