diff --git a/gb.xml/src/CDocument.cpp b/gb.xml/src/CDocument.cpp index aee281c32..12fd3bf70 100644 --- a/gb.xml/src/CDocument.cpp +++ b/gb.xml/src/CDocument.cpp @@ -31,6 +31,7 @@ BEGIN_METHOD(CDocument_new, GB_STRING fileName) if(Node::NoInstanciate) return; +if(GB.Is(_object, GB.FindClass("HtmlDocument"))) return;//Called as inherited HtmlDocument constructor if(!MISSING(fileName)) { @@ -47,7 +48,7 @@ END_METHOD BEGIN_METHOD_VOID(CDocument_free) -//delete THIS; +delete THIS; END_METHOD @@ -158,8 +159,9 @@ END_METHOD BEGIN_METHOD(CDocument_createElement, GB_STRING tagName) Element *elmt = new Element(STRING(tagName), LENGTH(tagName)); - +Node::NoInstanciate = true; GBI::Return(elmt); +Node::NoInstanciate = false; END_METHOD diff --git a/gb.xml/src/CElement.cpp b/gb.xml/src/CElement.cpp index 09cf1b159..02a5dee5a 100644 --- a/gb.xml/src/CElement.cpp +++ b/gb.xml/src/CElement.cpp @@ -29,6 +29,7 @@ BEGIN_METHOD(CElement_new, GB_STRING tagName) if(Node::NoInstanciate) return; +if(GB.Component.Exist("gb.xml.html")) return;//html part override if(!MISSING(tagName)) { diff --git a/gb.xml/src/element.cpp b/gb.xml/src/element.cpp index cc0eaac3a..157243662 100644 --- a/gb.xml/src/element.cpp +++ b/gb.xml/src/element.cpp @@ -537,7 +537,7 @@ void Element::setTagName(const char *ntagName, size_t nlenTagName) else { lenTagName = nlenTagName; - tagName = (char*)malloc(sizeof(char) * lenTagName); + tagName = (char*)realloc(tagName, sizeof(char) * lenTagName); memcpy(tagName, ntagName, lenTagName); } } diff --git a/gb.xml/src/html/CDocument.cpp b/gb.xml/src/html/CDocument.cpp index 8d2863f86..09e704565 100644 --- a/gb.xml/src/html/CDocument.cpp +++ b/gb.xml/src/html/CDocument.cpp @@ -54,6 +54,15 @@ BEGIN_METHOD_VOID(CDocument_free) END_METHOD +BEGIN_METHOD(CDocument_createElement, GB_STRING tagName) + +Element *elmt = new Element(STRING(tagName), LENGTH(tagName)); +Node::NoInstanciate = true; +GBI::Return(elmt); +Node::NoInstanciate = false; + +END_METHOD + BEGIN_PROPERTY(CDocument_Html5) if(READ_PROPERTY) @@ -117,34 +126,44 @@ END_PROPERTY BEGIN_PROPERTY(CDocument_root) +Node::NoInstanciate = true; GBI::Return(THIS->root); +Node::NoInstanciate = false; END_PROPERTY BEGIN_PROPERTY(CDocument_head) +Node::NoInstanciate = true; GBI::Return(THIS->getHead()); +Node::NoInstanciate = false; END_PROPERTY BEGIN_PROPERTY(CDocument_body) +Node::NoInstanciate = true; GBI::Return(THIS->getBody()); +Node::NoInstanciate = false; END_PROPERTY BEGIN_METHOD(CDocument_getElementById, GB_STRING id; GB_INTEGER depth) +Node::NoInstanciate = true; GBI::Return(THIS->getElementById(STRING(id), LENGTH(id), VARGOPT(depth, -1))); +Node::NoInstanciate = false; END_METHOD BEGIN_METHOD(CDocument_getElementsByClassName, GB_STRING className; GB_INTEGER depth) +Node::NoInstanciate = true; if(LENGTH(className) <= 0) return; GB_ARRAY array; THIS->getElementsByClassName(STRING(className), LENGTH(className), &array, VARGOPT(depth, -1)); GB.ReturnObject(array); +Node::NoInstanciate = false; END_METHOD @@ -242,7 +261,9 @@ GB_DESC CDocumentDesc[] = GB_METHOD("_new", "", CDocument_new, "[(Path)s]"), GB_METHOD("_free", "", CDocument_free, ""), - + + + GB_METHOD("CreateElement", "XmlElement", CDocument_createElement, "(TagName)s"), GB_PROPERTY("Html5", "b", CDocument_Html5), //GB_METHOD("ForceSetContent", "", CDocument_forceSetContent, "(Data)s"), GB_PROPERTY("Title", "s", CDocument_Title), diff --git a/gb.xml/src/html/CElement.cpp b/gb.xml/src/html/CElement.cpp index 36b489848..f0f7b802c 100644 --- a/gb.xml/src/html/CElement.cpp +++ b/gb.xml/src/html/CElement.cpp @@ -26,7 +26,25 @@ /*========== Element */ #undef THIS +#undef THISNODE #define THIS (static_cast(_object)->node->toElement()) +#define THISNODE (static_cast(_object)->node) + +BEGIN_METHOD(CElement_new, GB_STRING tagName) + +if(Node::NoInstanciate) return; + +if(!MISSING(tagName)) +{ + THISNODE = new Element(STRING(tagName), LENGTH(tagName)); +} +else +{ + THISNODE = new Element; +} + THIS->GBObject = static_cast(_object); + +END_METHOD BEGIN_PROPERTY(CElement_id) @@ -91,7 +109,8 @@ END_METHOD GB_DESC CElementDesc[] = { GB_DECLARE("XmlElement", sizeof(CNode)), - + + GB_METHOD("_new", "", CElement_new, "[(TagName)s]"), GB_PROPERTY("Id", "s", CElement_id), GB_PROPERTY("ClassName", "s", CElement_className),