diff options
-rw-r--r-- | Plugins/skins/Docs/skins_changelog.txt | 2 | ||||
-rw-r--r-- | Plugins/skins/Docs/skins_version.txt | 2 | ||||
-rw-r--r-- | Plugins/skins/SkinLib/Dialog.cpp | 5 | ||||
-rw-r--r-- | Plugins/skins/SkinLib/Dialog.h | 4 | ||||
-rw-r--r-- | Plugins/skins/SkinLib/SkinnedDialog.cpp | 21 | ||||
-rw-r--r-- | Plugins/skins/SkinLib/SkinnedDialog.h | 3 | ||||
-rw-r--r-- | Plugins/skins/SkinLib/V8Script.cpp | 10 | ||||
-rw-r--r-- | Plugins/skins/SkinLib/V8Script.h | 4 | ||||
-rw-r--r-- | Plugins/skins/SkinLib/V8Wrappers.cpp | 97 | ||||
-rw-r--r-- | Plugins/skins/SkinLib/V8Wrappers.h | 5 | ||||
-rw-r--r-- | Plugins/skins/m_skins.h | 5 | ||||
-rw-r--r-- | Plugins/skins/m_skins_cpp.h | 6 | ||||
-rw-r--r-- | Plugins/skins/skins.cpp | 54 | ||||
-rw-r--r-- | Plugins/skins/skins.vcproj | 10 |
14 files changed, 196 insertions, 32 deletions
diff --git a/Plugins/skins/Docs/skins_changelog.txt b/Plugins/skins/Docs/skins_changelog.txt index e982db6..b2d58ce 100644 --- a/Plugins/skins/Docs/skins_changelog.txt +++ b/Plugins/skins/Docs/skins_changelog.txt @@ -5,6 +5,8 @@ Changelog: . 0.0.0.2
* Fix for float numbers
+ Added valign (not used yet)
+ + Added dialog info (allow clients to set script variables starting with info)
+ + The zip will contain also the pdbs (at least until it is more stable)
. 0.0.0.1
+ Initial version
\ No newline at end of file diff --git a/Plugins/skins/Docs/skins_version.txt b/Plugins/skins/Docs/skins_version.txt index 775fefd..edf515f 100644 --- a/Plugins/skins/Docs/skins_version.txt +++ b/Plugins/skins/Docs/skins_version.txt @@ -1 +1 @@ -Skins 0.0.0.1
\ No newline at end of file +Skins 0.0.0.2
\ No newline at end of file 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);
diff --git a/Plugins/skins/m_skins.h b/Plugins/skins/m_skins.h index 081f834..5e692ea 100644 --- a/Plugins/skins/m_skins.h +++ b/Plugins/skins/m_skins.h @@ -64,6 +64,11 @@ struct SKIN_INTERFACE SKINNED_FIELD (*AddImageField)(SKINNED_DIALOG dlg, const char *name, const char *description);
SKINNED_FIELD (*GetField)(SKINNED_DIALOG dlg, const char *name);
void (*SetDialogSize)(SKINNED_DIALOG dlg, int width, int height);
+ void (*SetInfoInt)(SKINNED_DIALOG dlg, const char *name, int value);
+ void (*SetInfoDouble)(SKINNED_DIALOG dlg, const char *name, double value);
+ void (*SetInfoBool)(SKINNED_DIALOG dlg, const char *name, BOOL value);
+ void (*SetInfoString)(SKINNED_DIALOG dlg, const char *name, const TCHAR *value);
+ void (*RemoveInfo)(SKINNED_DIALOG dlg, const char *name);
// Field methods
void (*SetEnabled)(SKINNED_FIELD field, BOOL enabled);
diff --git a/Plugins/skins/m_skins_cpp.h b/Plugins/skins/m_skins_cpp.h index 4f3be3b..c290028 100644 --- a/Plugins/skins/m_skins_cpp.h +++ b/Plugins/skins/m_skins_cpp.h @@ -194,6 +194,12 @@ public: SkinIconField getIconField(const char *name) { return SkinIconField( mski.GetField(dlg, name) ); }
SkinImageField getImageField(const char *name) { return SkinImageField( mski.GetField(dlg, name) ); }
+ void setInfoInt(const char *name, int value) { mski.SetInfoInt(dlg, name, value); }
+ void setInfoDouble(const char *name, double value) { mski.SetInfoDouble(dlg, name, value); }
+ void setInfoBool(const char *name, bool value) { mski.SetInfoBool(dlg, name, value); }
+ void setInfoString(const char *name, const TCHAR *value) { mski.SetInfoString(dlg, name, value); }
+ void removeInfo(const char *name) { mski.RemoveInfo(dlg, name); }
+
SkinDialogState run() { return SkinDialogState( mski.Run(dlg) ); }
private:
diff --git a/Plugins/skins/skins.cpp b/Plugins/skins/skins.cpp index 46ef919..47674d5 100644 --- a/Plugins/skins/skins.cpp +++ b/Plugins/skins/skins.cpp @@ -30,7 +30,7 @@ PLUGININFOEX pluginInfo={ #else
"Skins",
#endif
- PLUGIN_MAKE_VERSION(0,0,0,1),
+ PLUGIN_MAKE_VERSION(0,0,0,2),
"Skins",
"Ricardo Pescuma Domenecci",
"",
@@ -495,6 +495,52 @@ void Interface_SetDialogSize(SKINNED_DIALOG aDlg, int width, int height) dlg->setSize(Size(width, height));
}
+void Interface_SetInfoInt(SKINNED_DIALOG aDlg, const char *name, int value)
+{
+ if (aDlg == NULL || name == NULL)
+ return;
+
+ MirandaSkinnedDialog *dlg = (MirandaSkinnedDialog *) aDlg;
+ dlg->getInfo()->set(name, value);
+}
+
+void Interface_SetInfoDouble(SKINNED_DIALOG aDlg, const char *name, double value)
+{
+ if (aDlg == NULL || name == NULL)
+ return;
+
+ MirandaSkinnedDialog *dlg = (MirandaSkinnedDialog *) aDlg;
+ dlg->getInfo()->set(name, value);
+}
+
+void Interface_SetInfoBool(SKINNED_DIALOG aDlg, const char *name, BOOL value)
+{
+ if (aDlg == NULL || name == NULL)
+ return;
+
+ MirandaSkinnedDialog *dlg = (MirandaSkinnedDialog *) aDlg;
+ dlg->getInfo()->set(name, value);
+}
+
+void Interface_SetInfoString(SKINNED_DIALOG aDlg, const char *name, const TCHAR *value)
+{
+ if (aDlg == NULL || name == NULL)
+ return;
+
+ MirandaSkinnedDialog *dlg = (MirandaSkinnedDialog *) aDlg;
+ dlg->getInfo()->set(name, value);
+}
+
+void Interface_RemoveInfo(SKINNED_DIALOG aDlg, const char *name)
+{
+ if (aDlg == NULL || name == NULL)
+ return;
+
+ MirandaSkinnedDialog *dlg = (MirandaSkinnedDialog *) aDlg;
+ dlg->getInfo()->remove(name);
+}
+
+
void Interface_SetEnabled(SKINNED_FIELD aField, BOOL enabled)
{
if (aField == NULL)
@@ -858,6 +904,12 @@ static int Service_GetInterface(WPARAM wParam, LPARAM lParam) mski->GetField = &Interface_GetField;
mski->SetDialogSize = &Interface_SetDialogSize;
+ mski->SetInfoInt = &Interface_SetInfoInt;
+ mski->SetInfoDouble = &Interface_SetInfoDouble;
+ mski->SetInfoBool = &Interface_SetInfoBool;
+ mski->SetInfoString = &Interface_SetInfoString;
+ mski->RemoveInfo = &Interface_RemoveInfo;
+
mski->SetEnabled = &Interface_SetEnabled;
mski->SetToolTipA = &Interface_SetToolTipA;
mski->SetToolTipW = &Interface_SetToolTipW;
diff --git a/Plugins/skins/skins.vcproj b/Plugins/skins/skins.vcproj index 23afa14..a12a20d 100644 --- a/Plugins/skins/skins.vcproj +++ b/Plugins/skins/skins.vcproj @@ -249,7 +249,7 @@ Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../include,sdk,libs,../utils"
- PreprocessorDefinitions="WIN32;W32;_DEBUG;DEBUG;_WINDOWS;UNICODE;_USRDLL;_CRT_SECURE_NO_WARNINGS"
+ PreprocessorDefinitions="WIN32;W32;_DEBUG;DEBUG;_WINDOWS;UNICODE;_USRDLL;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@@ -500,6 +500,10 @@ >
</File>
<File
+ RelativePath=".\SkinLib\DialogInfo.h"
+ >
+ </File>
+ <File
RelativePath=".\SkinLib\EditField.h"
>
</File>
@@ -886,6 +890,10 @@ >
</File>
<File
+ RelativePath=".\SkinLib\DialogInfo.cpp"
+ >
+ </File>
+ <File
RelativePath=".\SkinLib\EditField.cpp"
>
</File>
|