Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / Config / Config_WidgetAPI.cpp
index 65d4b14cad33bd13191fd5730a56ffd6b1405234..8d295ce05a64e6ae50d8c4adf9ae109f7b26eb4a 100644 (file)
@@ -6,15 +6,17 @@
  */
 
 #include <Config_WidgetAPI.h>
+#include <Config_Keywords.h>
+#include <Config_Common.h>
 
-#include <libxml\parser.h>
-#include <libxml\tree.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
 
 
 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
 {
   myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
-  myCurrentNode = NULL;
+  myCurrentNode = xmlDocGetRootElement(myDoc);
 }
 
 
@@ -23,23 +25,43 @@ Config_WidgetAPI::~Config_WidgetAPI()
   xmlFreeDoc(myDoc);
 }
 
-void Config_WidgetAPI::reset()
+bool Config_WidgetAPI::toNextWidget()
 {
-  xmlNodePtr aRoot = xmlDocGetRootElement(myDoc);
-  if(aRoot) {
-    myCurrentNode = aRoot->children;
+  //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::nextWidget()
+bool Config_WidgetAPI::toChildWidget()
+{
+  if(myCurrentNode && hasChild(myCurrentNode)) {
+    myCurrentNode = myCurrentNode->children;
+    while(!isElementNode(myCurrentNode)) {
+      myCurrentNode = myCurrentNode->next;
+    } 
+    return true;
+  }
+  return false;
+}
+
+bool Config_WidgetAPI::toParentWidget()
 {
   if(myCurrentNode) {
-    myCurrentNode = myCurrentNode->next;
+    myCurrentNode = myCurrentNode->parent;
   }
   return myCurrentNode != NULL;
 }
 
-std::string Config_WidgetAPI::widgetType()
+std::string Config_WidgetAPI::widgetType() const
 {
   std::string result = "";
   if(myCurrentNode) {
@@ -48,7 +70,19 @@ std::string Config_WidgetAPI::widgetType()
   return result;
 }
 
-std::string Config_WidgetAPI::getProperty(const char* thePropName)
+bool Config_WidgetAPI::isContainerWidget() const
+{
+  return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
+                               NULL);
+}
+
+bool Config_WidgetAPI::isPagedWidget() const
+{
+  return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
+                               NULL);
+}
+
+std::string Config_WidgetAPI::getProperty(const char* thePropName) const
 {
   std::string result = "";
   char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName);
@@ -58,47 +92,22 @@ std::string Config_WidgetAPI::getProperty(const char* thePropName)
   return result;
 }
 
-std::string Config_WidgetAPI::widgetId()
-{
-  return getProperty("id");
-}
-
-std::string Config_WidgetAPI::widgetTooltip()
+std::string Config_WidgetAPI::widgetId() const
 {
-  return getProperty("tooltip");
+  return getProperty(_ID);
 }
 
-std::string Config_WidgetAPI::widgetIcon()
+std::string Config_WidgetAPI::widgetIcon() const
 {
-  return getProperty("icon");
+  return getProperty(ANY_WDG_ICON);
 }
 
-std::string Config_WidgetAPI::widgetLabel()
+std::string Config_WidgetAPI::widgetLabel() const
 {
-  return getProperty("label");
+  return getProperty(ANY_WDG_LABEL);
 }
 
-bool Config_WidgetAPI::isNode(xmlNodePtr theNode, const char* theNodeName, ...)
+std::string Config_WidgetAPI::widgetTooltip() const
 {
-  bool result = false;
-  const xmlChar* aName = theNode->name;
-  if (!aName || theNode->type != XML_ELEMENT_NODE)
-    return false;
-
-  if (!xmlStrcmp(aName, (const xmlChar *) theNodeName))
-    return true;
-
-  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;
+  return getProperty(ANY_WDG_TOOLTIP);
 }