summaryrefslogtreecommitdiff
path: root/Plugins/skins/SkinLib
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/skins/SkinLib')
-rw-r--r--Plugins/skins/SkinLib/Dialog.cpp5
-rw-r--r--Plugins/skins/SkinLib/Dialog.h4
-rw-r--r--Plugins/skins/SkinLib/SkinnedDialog.cpp21
-rw-r--r--Plugins/skins/SkinLib/SkinnedDialog.h3
-rw-r--r--Plugins/skins/SkinLib/V8Script.cpp10
-rw-r--r--Plugins/skins/SkinLib/V8Script.h4
-rw-r--r--Plugins/skins/SkinLib/V8Wrappers.cpp97
-rw-r--r--Plugins/skins/SkinLib/V8Wrappers.h5
8 files changed, 120 insertions, 29 deletions
diff --git a/Plugins/skins/SkinLib/Dialog.cpp b/Plugins/skins/SkinLib/Dialog.cpp
index 4f13392..edc8437 100644
--- a/Plugins/skins/SkinLib/Dialog.cpp
+++ b/Plugins/skins/SkinLib/Dialog.cpp
@@ -72,6 +72,11 @@ unsigned int Dialog::getFieldCount() const
return fields.size();
}
+DialogInfo * Dialog::getInfo()
+{
+ return &info;
+}
+
const Size & Dialog::getSize() const
{
return size;
diff --git a/Plugins/skins/SkinLib/Dialog.h b/Plugins/skins/SkinLib/Dialog.h
index 90701cf..0e85b8e 100644
--- a/Plugins/skins/SkinLib/Dialog.h
+++ b/Plugins/skins/SkinLib/Dialog.h
@@ -3,6 +3,7 @@
#include <vector>
#include "Field.h"
+#include "DialogInfo.h"
class DialogState;
@@ -22,6 +23,8 @@ public:
virtual int getIndexOf(Field *field) const;
virtual unsigned int getFieldCount() const;
+ virtual DialogInfo * getInfo();
+
virtual const Size & getSize() const;
virtual void setSize(const Size &size);
@@ -30,6 +33,7 @@ public:
private:
const std::string name;
std::vector<Field *> fields;
+ DialogInfo info;
Size size;
};
diff --git a/Plugins/skins/SkinLib/SkinnedDialog.cpp b/Plugins/skins/SkinLib/SkinnedDialog.cpp
index a6a3b2b..f8dfb04 100644
--- a/Plugins/skins/SkinLib/SkinnedDialog.cpp
+++ b/Plugins/skins/SkinLib/SkinnedDialog.cpp
@@ -112,7 +112,7 @@ DialogState * SkinnedDialog::getState()
return NULL;
state = Dialog::createState();
- if (!script->run(state, opts))
+ if (!script->run(state, opts, getInfo()))
{
releaseState();
return NULL;
@@ -139,25 +139,6 @@ void SkinnedDialog::releaseState()
state = NULL;
}
-DialogState * SkinnedDialog::createState(const TCHAR *text, MessageCallback errorCallback, void *errorCallbackParam)
-{
- V8Script script;
- script.setExceptionCallback(errorCallback, errorCallbackParam);
-
- if (!script.compile(text, this))
- return NULL;
-
- DialogState *state = Dialog::createState();
- if (!script.run(state, opts))
- {
- delete state;
- return NULL;
- }
-
- return state;
-}
-
-
bool SkinnedDialog::fileChanged()
{
if (filename.size() <= 0)
diff --git a/Plugins/skins/SkinLib/SkinnedDialog.h b/Plugins/skins/SkinLib/SkinnedDialog.h
index ea99280..1387082 100644
--- a/Plugins/skins/SkinLib/SkinnedDialog.h
+++ b/Plugins/skins/SkinLib/SkinnedDialog.h
@@ -49,9 +49,6 @@ public:
/// Each call to this method can potentially create the state, so don't cache it.
virtual DialogState * getState();
- /// Create a state based on the script passed in text. the caller have to free the DialogState *
- virtual DialogState * createState(const TCHAR *text, MessageCallback errorCallback = NULL, void *errorCallbackParam = NULL);
-
virtual void setErrorCallback(MessageCallback cb, void *param = NULL);
virtual void setTraceCallback(MessageCallback cb, void *param = NULL);
diff --git a/Plugins/skins/SkinLib/V8Script.cpp b/Plugins/skins/SkinLib/V8Script.cpp
index ff31443..c761918 100644
--- a/Plugins/skins/SkinLib/V8Script.cpp
+++ b/Plugins/skins/SkinLib/V8Script.cpp
@@ -46,6 +46,7 @@ bool V8Script::compile(const TCHAR *source, Dialog *dlg)
context->Global()->Set(String::New("window"), wrappers->newDialogState(), ReadOnly);
context->Global()->Set(String::New("opts"), wrappers->newOptions(), ReadOnly);
+ context->Global()->Set(String::New("info"), wrappers->newDialogInfo(), ReadOnly);
for(unsigned int i = 0; i < dlg->getFieldCount(); i++)
{
Field *field = dlg->getField(i);
@@ -115,11 +116,12 @@ static Handle<Object> get(Handle<Object> obj, const char *field)
return scope.Close( Handle<Object>::Cast(v) );
}
-void V8Script::fillWrappers(DialogState *state, SkinOptions *opts, bool configure)
+void V8Script::fillWrappers(DialogState *state, SkinOptions *opts, DialogInfo *info, bool configure)
{
Local<Object> global = context->Global();
wrappers->fillOptions(get(global, "opts"), opts, configure);
wrappers->fillDialogState(get(global, "window"), state);
+ wrappers->fillDialogInfo(get(global, "info"), info);
for(unsigned int i = 0; i < state->fields.size(); i++)
{
FieldState *field = state->fields[i];
@@ -141,7 +143,7 @@ std::pair<SkinOptions *,DialogState *> V8Script::configure(Dialog *dlg)
Context::Scope context_scope(context);
- fillWrappers(state, opts, true);
+ fillWrappers(state, opts, dlg->getInfo(), true);
TryCatch try_catch;
Handle<Value> result = configureFunction->Call(context->Global(), 0, NULL);
@@ -157,7 +159,7 @@ std::pair<SkinOptions *,DialogState *> V8Script::configure(Dialog *dlg)
return std::pair<SkinOptions *,DialogState *>(opts, state);
}
-bool V8Script::run(DialogState * state, SkinOptions *opts)
+bool V8Script::run(DialogState * state, SkinOptions *opts, DialogInfo *info)
{
if (!isValid())
return false;
@@ -166,7 +168,7 @@ bool V8Script::run(DialogState * state, SkinOptions *opts)
Context::Scope context_scope(context);
- fillWrappers(state, opts, false);
+ fillWrappers(state, opts, info, false);
TryCatch try_catch;
Handle<Value> result = drawFunction->Call(context->Global(), 0, NULL);
diff --git a/Plugins/skins/SkinLib/V8Script.h b/Plugins/skins/SkinLib/V8Script.h
index 45a9af7..b7e1f3f 100644
--- a/Plugins/skins/SkinLib/V8Script.h
+++ b/Plugins/skins/SkinLib/V8Script.h
@@ -25,7 +25,7 @@ public:
std::pair<SkinOptions *,DialogState *> configure(Dialog *dlg);
- bool run(DialogState * state, SkinOptions *opts);
+ bool run(DialogState * state, SkinOptions *opts, DialogInfo *info);
void setExceptionCallback(ExceptionCallback cb, void *param = NULL);
@@ -38,7 +38,7 @@ private:
void *exceptionCallbackParam;
void reportException(v8::TryCatch *try_catch);
- void fillWrappers(DialogState *state, SkinOptions *opts, bool configure);
+ void fillWrappers(DialogState *state, SkinOptions *opts, DialogInfo *info, bool configure);
};
diff --git a/Plugins/skins/SkinLib/V8Wrappers.cpp b/Plugins/skins/SkinLib/V8Wrappers.cpp
index 1a9e0b6..9384e3c 100644
--- a/Plugins/skins/SkinLib/V8Wrappers.cpp
+++ b/Plugins/skins/SkinLib/V8Wrappers.cpp
@@ -238,6 +238,7 @@ void V8Wrappers::fillOptions(Handle<Object> v8Obj, SkinOptions *obj, bool config
v8Obj->SetInternalField(1, Boolean::New(configure));
}
+
static Handle<Value> Get_SkinOption_value(Local<String> property, const AccessorInfo &info)
{
HandleScope scope;
@@ -286,3 +287,99 @@ void V8Wrappers::addSkinOptionTemplateFields(Handle<ObjectTemplate> &templ)
templ->SetAccessor(String::New("value"), Get_SkinOption_value, Set_SkinOption_value);
}
+
+
+static Handle<Value> Get_DialogInfo_Fields(Local<String> aName, const AccessorInfo &info)
+{
+ HandleScope scope;
+
+ Local<Object> self = info.Holder();
+ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ DialogInfo *dialogInfo = (DialogInfo *) wrap->Value();
+ if (dialogInfo == NULL)
+ return scope.Close( Undefined() );
+
+ String::AsciiValue name(aName);
+ if (name.length() <= 0)
+ return scope.Close( Undefined() );
+
+ wrap = Local<External>::Cast(info.Data());
+ if (wrap.IsEmpty())
+ return scope.Close( Undefined() );
+
+ V8Wrappers *wrappers = (V8Wrappers *) wrap->Value();
+ if (wrappers == NULL)
+ return scope.Close( Undefined() );
+
+ Local<String> aPrefix = Local<String>::Cast(self->GetInternalField(1));
+ if (aPrefix.IsEmpty())
+ return scope.Close( Undefined() );
+
+ String::AsciiValue prefix(aPrefix);
+
+ std::string var;
+ var += *prefix;
+ var += *name;
+
+ switch(dialogInfo->getType(var.c_str()))
+ {
+ case TYPE_VARIABLE:
+ {
+ var += '.';
+
+ Handle<Object> ret = wrappers->newDialogInfo();
+ wrappers->fillDialogInfo(ret, dialogInfo, var.c_str());
+ return scope.Close( ret );
+ }
+ case TYPE_INT:
+ return scope.Close( Int32::New(dialogInfo->getAsInt(var.c_str())) );
+ case TYPE_DOUBLE:
+ return scope.Close( Number::New(dialogInfo->getAsDouble(var.c_str())) );
+ case TYPE_BOOL:
+ return scope.Close( Boolean::New(dialogInfo->getAsBool(var.c_str())) );
+ case TYPE_STRING:
+ return scope.Close( String::New((const V8_TCHAR *) dialogInfo->getAsString(var.c_str())) );
+ case UNKNOWN:
+ default:
+ return scope.Close( Undefined() );
+ }
+}
+
+Handle<ObjectTemplate> V8Wrappers::getDialogInfoTemplate()
+{
+ HandleScope scope;
+
+ if (!dialogInfoTemplate.IsEmpty())
+ return dialogInfoTemplate;
+
+ Handle<ObjectTemplate> templ = ObjectTemplate::New();
+ templ->SetInternalFieldCount(2);
+ templ->SetNamedPropertyHandler(&Get_DialogInfo_Fields, 0, 0, 0, 0, External::New(this));
+
+ dialogInfoTemplate = Persistent<ObjectTemplate>::New(templ);
+
+ return dialogInfoTemplate;
+}
+
+Handle<Object> V8Wrappers::newDialogInfo()
+{
+ HandleScope scope;
+
+ Handle<Object> obj = getDialogInfoTemplate()->NewInstance();
+
+ return scope.Close(obj);
+}
+
+void V8Wrappers::fillDialogInfo(Handle<Object> v8Obj, DialogInfo *obj, const char *prefix)
+{
+ HandleScope scope;
+
+ _ASSERT(!v8Obj.IsEmpty());
+
+ v8Obj->SetInternalField(0, External::New(obj));
+
+ v8Obj->SetInternalField(1, String::New(prefix != NULL ? prefix : ""));
+}
diff --git a/Plugins/skins/SkinLib/V8Wrappers.h b/Plugins/skins/SkinLib/V8Wrappers.h
index 4b7a672..b2c5eb2 100644
--- a/Plugins/skins/SkinLib/V8Wrappers.h
+++ b/Plugins/skins/SkinLib/V8Wrappers.h
@@ -15,8 +15,13 @@ public:
virtual v8::Handle<v8::Object> newOptions();
virtual void fillOptions(v8::Handle<v8::Object> v8Obj, SkinOptions *obj, bool configure);
+ virtual v8::Handle<v8::ObjectTemplate> getDialogInfoTemplate();
+ virtual v8::Handle<v8::Object> newDialogInfo();
+ virtual void fillDialogInfo(v8::Handle<v8::Object> v8Obj, DialogInfo *obj, const char *prefix = NULL);
+
private:
v8::Persistent<v8::ObjectTemplate> optionsTemplate;
+ v8::Persistent<v8::ObjectTemplate> dialogInfoTemplate;
protected:
virtual void addGlobalTemplateFields(v8::Handle<v8::ObjectTemplate> &templ);