X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConfig%2FConfig_WidgetAPI.cpp;h=085648e9708b5f6d6f1d96bd5bbd6146aba02608;hb=35a88fdd724349275bbff32b9596a44e7cd422e2;hp=80eb568111877703e67921312149ef32a20bc05a;hpb=1b6e67870beeeb667864eaff5b1bb9c1570b7259;p=modules%2Fshaper.git diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index 80eb56811..085648e97 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -6,99 +6,108 @@ */ #include +#include +#include #include #include +#include Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml) { myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str()); - myCurrentNode = NULL; + myCurrentNode = xmlDocGetRootElement(myDoc); } - Config_WidgetAPI::~Config_WidgetAPI() { xmlFreeDoc(myDoc); } -void Config_WidgetAPI::reset() +bool Config_WidgetAPI::toNextWidget() +{ + //Skip all non-element node, stop if next node is null + xmlNodePtr aNextNode = myCurrentNode; + do { + aNextNode = aNextNode->next; + } while (aNextNode && !isElementNode(aNextNode)); + + if (!aNextNode) { + toParentWidget(); + return false; + } + myCurrentNode = aNextNode; + return true; +} + +bool Config_WidgetAPI::toChildWidget() { - xmlNodePtr aRoot = xmlDocGetRootElement(myDoc); - if(aRoot) { - myCurrentNode = aRoot->children; + if (myCurrentNode && hasChild(myCurrentNode)) { + myCurrentNode = myCurrentNode->children; + while (!isElementNode(myCurrentNode)) { + myCurrentNode = myCurrentNode->next; + } + return true; } + return false; } -bool Config_WidgetAPI::nextWidget() +bool Config_WidgetAPI::toParentWidget() { - if(myCurrentNode) { - myCurrentNode = myCurrentNode->next; + if (myCurrentNode) { + myCurrentNode = myCurrentNode->parent; } return myCurrentNode != NULL; } -std::string Config_WidgetAPI::widgetType() +std::string Config_WidgetAPI::widgetType() const { std::string result = ""; - if(myCurrentNode) { + if (myCurrentNode) { result = std::string((char *) myCurrentNode->name); } return result; } -std::string Config_WidgetAPI::getProperty(const char* thePropName) +bool Config_WidgetAPI::isContainerWidget() const { - std::string result = ""; - char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName); - if (!aPropChars || aPropChars[0] == 0) - return result; - result = std::string(aPropChars); - return result; + return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP, + NULL); } -std::string Config_WidgetAPI::widgetId() +bool Config_WidgetAPI::isPagedWidget() const { - return getProperty("id"); + return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH, + NULL); } -std::string Config_WidgetAPI::widgetTooltip() +std::string Config_WidgetAPI::getProperty(const char* thePropName) const { - return getProperty("tooltip"); + return ::getProperty(myCurrentNode, thePropName); } -std::string Config_WidgetAPI::widgetIcon() +bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const { - return getProperty("icon"); + return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault); } -std::string Config_WidgetAPI::widgetLabel() +std::string Config_WidgetAPI::widgetId() const { - return getProperty("label"); + return getProperty(_ID); } -bool Config_WidgetAPI::isNode(xmlNodePtr theNode, const char* theNodeName, ...) +std::string Config_WidgetAPI::widgetIcon() const { - bool result = false; - const xmlChar* aName = theNode->name; - if (!aName || theNode->type != XML_ELEMENT_NODE) - return false; + return getProperty(ANY_WDG_ICON); +} - if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) - return true; +std::string Config_WidgetAPI::widgetLabel() const +{ + return getProperty(ANY_WDG_LABEL); +} - va_list args; // define argument list variable - va_start(args, theNodeName); // init list; point to last defined argument - while(true) { - char *anArg = va_arg (args, char*); // get next argument - if (anArg == NULL) - break; - if (!xmlStrcmp(aName, (const xmlChar *) anArg)) { - va_end(args); // cleanup the system stack - return true; - } - } - va_end(args); // cleanup the system stack - return false; +std::string Config_WidgetAPI::widgetTooltip() const +{ + return getProperty(ANY_WDG_TOOLTIP); }