From 334bfbad3fda3860f51b74cd6370786ef253ad49 Mon Sep 17 00:00:00 2001 From: pescuma Date: Tue, 20 Jan 2009 23:24:30 +0000 Subject: skins: templates are kept in memory git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@128 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/skins/SkinLib/V8Script.cpp | 225 ++++++++++++------------------------- 1 file changed, 69 insertions(+), 156 deletions(-) (limited to 'Plugins/skins/SkinLib/V8Script.cpp') diff --git a/Plugins/skins/SkinLib/V8Script.cpp b/Plugins/skins/SkinLib/V8Script.cpp index 0d0fc85..fb32181 100644 --- a/Plugins/skins/SkinLib/V8Script.cpp +++ b/Plugins/skins/SkinLib/V8Script.cpp @@ -1,96 +1,37 @@ #include "globals.h" #include "V8Script.h" +#include "V8Wrappers.h" #include using namespace v8; +#ifdef UNICODE +# define V8_TCHAR uint16_t +#else +# define V8_TCHAR char +#endif -V8Script::V8Script() : exceptionCallback(NULL), exceptionCallbackParam(NULL) -{ -} +V8Wrappers *wrappers = NULL; -V8Script::~V8Script() -{ - dispose(); -} -static Handle IsEmptyCallback(const Arguments& args) +void V8Script::initializeEngine() { - if (args.Length() < 1) - return Undefined(); - - HandleScope scope; - - for(int i = 0; i < args.Length(); i++) - { - Local arg = args[0]; - - if (arg.IsEmpty() || arg->IsNull() || arg->IsUndefined()) - { - return Boolean::New(true); - } - else if (arg->IsObject()) - { - Local self = Local::Cast(arg); - if (self->InternalFieldCount() < 1) - continue; - - Local wrap = Local::Cast(self->GetInternalField(0)); - FieldState *field = (FieldState *) wrap->Value(); - if (field == NULL) - continue; - - if (field->isEmpty()) - return Boolean::New(true); - } - else if (arg->IsString()) - { - Local str = Local::Cast(arg); - if (str->Length() <= 0) - return Boolean::New(true); - } - } + if (wrappers != NULL) + return; - return Boolean::New(false); + wrappers = new V8Wrappers(); } -static Handle RGBCallback(const Arguments& args) -{ - if (args.Length() != 3) - return Undefined(); - COLORREF color = RGB(args[0]->Int32Value(), args[1]->Int32Value(), args[2]->Int32Value()); - return Int32::New(color); +V8Script::V8Script() : exceptionCallback(NULL), exceptionCallbackParam(NULL) +{ } -static Handle AlertCallback(const Arguments& args) +V8Script::~V8Script() { - Local wrap = Local::Cast(args.Data()); - if (wrap.IsEmpty()) - return Int32::New(-1); - - Dialog *dialog = (Dialog *) wrap->Value(); - if (dialog == NULL) - return Int32::New(-1); - - if (args.Length() < 1) - return Int32::New(-1); - - Local arg = args[0]; - if (!arg->IsString()) - return Int32::New(-1); - - Local str = Local::Cast(arg); - String::Utf8Value utf8_value(str); - - std::tstring title; - title = CharToTchar(dialog->getName()); - title += _T(" - Skin alert"); - MessageBox(NULL, Utf8ToTchar(*utf8_value), title.c_str(), MB_OK); - - return Int32::New(0); + dispose(); } bool V8Script::compile(const TCHAR *source, Dialog *dlg) @@ -99,58 +40,67 @@ bool V8Script::compile(const TCHAR *source, Dialog *dlg) HandleScope handle_scope; - Handle global = ObjectTemplate::New(); - - global->Set(String::New("IsEmpty"), FunctionTemplate::New(&IsEmptyCallback)); - global->Set(String::New("RGB"), FunctionTemplate::New(&RGBCallback)); - global->Set(String::New("alert"), FunctionTemplate::New(&AlertCallback, External::New(dlg))); - - global->Set(String::New("NUMBER"), String::New("NUMBER")); - global->Set(String::New("CHECKBOX"), String::New("CHECKBOX")); - global->Set(String::New("TEXT"), String::New("TEXT")); - global->Set(String::New("LEFT"), String::New("LEFT")); - global->Set(String::New("CENTER"), String::New("CENTER")); - global->Set(String::New("RIGHT"), String::New("RIGHT")); - - context = Context::New(NULL, global); + context = Context::New(NULL, wrappers->getGlobalTemplate()); Context::Scope context_scope(context); - context->Global()->Set(String::New("window"), wrappers.createDialogWrapper(), ReadOnly); - context->Global()->Set(String::New("opts"), wrappers.createOptionsWrapper(), ReadOnly); + context->Global()->Set(String::New("window"), wrappers->newDialogState(), ReadOnly); + context->Global()->Set(String::New("opts"), wrappers->newOptions(), ReadOnly); for(unsigned int i = 0; i < dlg->getFieldCount(); i++) { Field *field = dlg->getField(i); - context->Global()->Set(String::New(field->getName()), wrappers.createWrapper(field->getType()), ReadOnly); + context->Global()->Set(String::New(field->getName()), wrappers->newState(field->getType()), ReadOnly); } - wrappers.clearTemplates(); TryCatch try_catch; - Local