From 05f6cf3f7788f8bfe5ee589a9f27a89217c67989 Mon Sep 17 00:00:00 2001 From: pescuma Date: Sat, 3 Jan 2009 05:12:30 +0000 Subject: skins: It's ALIVE! git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@121 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/skins/SkinLib/SkinnedDialog.cpp | 127 ++++++++++++++++---------------- 1 file changed, 64 insertions(+), 63 deletions(-) (limited to 'Plugins/skins/SkinLib/SkinnedDialog.cpp') diff --git a/Plugins/skins/SkinLib/SkinnedDialog.cpp b/Plugins/skins/SkinLib/SkinnedDialog.cpp index 34a4294..046fffe 100644 --- a/Plugins/skins/SkinLib/SkinnedDialog.cpp +++ b/Plugins/skins/SkinLib/SkinnedDialog.cpp @@ -8,8 +8,8 @@ SkinnedDialog::SkinnedDialog(const char *name) - : dlg(name), fileChangedTime(0), - script(NULL), state(NULL), opts(NULL), + : Dialog(name), fileChangedTime(0), + script(NULL), state(NULL), opts(NULL), defaultState(NULL), errorCallback(NULL), errorCallbackParam(NULL), traceCallback(NULL), traceCallbackParam(NULL) { @@ -26,10 +26,8 @@ const TCHAR * SkinnedDialog::getFilename() const return filename.c_str(); } -void SkinnedDialog::setFilename(const char *skin, const TCHAR *filename) +void SkinnedDialog::setFilename(const TCHAR *filename) { - this->skin = skin; - if (this->filename == filename) return; @@ -40,7 +38,7 @@ void SkinnedDialog::setFilename(const char *skin, const TCHAR *filename) bool SkinnedDialog::addField(Field *field) { - if (dlg.addField(field)) + if (Dialog::addField(field)) { releaseCompiledScript(); releaseState(); @@ -51,81 +49,69 @@ bool SkinnedDialog::addField(Field *field) 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) + if (getSize() == size) return; - dlg.setSize(size); + Dialog::setSize(size); releaseState(); } -DialogState * SkinnedDialog::getState() -{ +bool SkinnedDialog::compile() +{ bool changed = fileChanged(); - if (state != NULL && !changed) - return state; + if (!changed) + return true; - releaseState(); + releaseCompiledScript(); - if (filename.size() <= 0) - return NULL; + struct _stat st = {0}; + if (_tstat(filename.c_str(), &st) != 0) + return false; - if (changed || script == NULL) + std::tstring text; + readFile(text); + if (text.size() <= 0) + return false; + + script = new V8Script(); + script->setExceptionCallback(errorCallback, errorCallbackParam); + + if (!script->compile(text.c_str(), this)) { releaseCompiledScript(); + return false; + } - struct _stat st = {0}; - if (_tstat(filename.c_str(), &st) != 0) - return NULL; + std::pair pair = script->configure(this); + opts = pair.first; + defaultState = pair.second; + if (opts == NULL) + { + releaseCompiledScript(); + return false; + } + + fileChangedTime = st.st_mtime; - std::tstring text; - readFile(text); - if (text.size() <= 0) - return NULL; + return true; +} - script = new V8Script(); - script->setExceptionCallback(errorCallback, errorCallbackParam); +DialogState * SkinnedDialog::getState() +{ + if (state != NULL && !fileChanged()) + return state; - if (!script->compile(text.c_str(), &dlg)) - { - releaseCompiledScript(); - return NULL; - } + releaseState(); - opts = script->createOptions(&dlg); - if (opts == NULL) - { - releaseCompiledScript(); - return NULL; - } + if (filename.size() <= 0) + return NULL; - fileChangedTime = st.st_mtime; - } + if (!compile()) + return NULL; - state = dlg.createState(); + state = Dialog::createState(); if (!script->run(state, opts)) { releaseState(); @@ -142,6 +128,9 @@ void SkinnedDialog::releaseCompiledScript() delete opts; opts = NULL; + + delete defaultState; + defaultState = NULL; } void SkinnedDialog::releaseState() @@ -155,10 +144,10 @@ DialogState * SkinnedDialog::createState(const TCHAR *text, MessageCallback erro V8Script script; script.setExceptionCallback(errorCallback, errorCallbackParam); - if (!script.compile(text, &dlg)) + if (!script.compile(text, this)) return NULL; - DialogState *state = dlg.createState(); + DialogState *state = Dialog::createState(); if (!script.run(state, opts)) { delete state; @@ -249,4 +238,16 @@ void SkinnedDialog::trace(TCHAR *msg, ...) va_end(args); traceCallback(traceCallbackParam, buff); +} + +SkinOptions * SkinnedDialog::getOpts() +{ + compile(); + return opts; +} + +DialogState * SkinnedDialog::getDefaultState() +{ + compile(); + return defaultState; } \ No newline at end of file -- cgit v1.2.3