//////////////////////////////////////////////////////////////////////////
        protected bool ParseStructure(ref List <Token> Tokens)
        {
            string       Name;
            List <Token> Value;
            int          LineNum;

            while (GetValue(ref Tokens, out Name, out Value, out LineNum))
            {
                DefinitionFileItem item = new DefinitionFileItem();
                item.Name    = Name;
                item.Parent  = this;
                item.LineNum = LineNum;

                Children.Add(item);


                string value;
                if (IsValue(Value, out value))
                {
                    item.Value = value;
                }
                else
                {
                    while (Value.Count > 0)
                    {
                        item.ParseStructure(ref Value);
                    }
                }
            }
            if (Tokens.Count == 0)
            {
                return(true);
            }
            else
            {
                Tokens.Clear();
                return(false);
            }
        }
        //////////////////////////////////////////////////////////////////////////
        private void FixHotspot(DefinitionFileItem node, int modX, int modY)
        {
            bool found = false;
            foreach (DefinitionFileItem subNode in node.Children)
            {
                if (subNode.Name.ToUpper() == "HOTSPOT")
                {
                    found = true;
                    int[] values = subNode.GetIntArray();
                    if (values.Length > 1)
                    {
                        values[0] += modX;
                        values[1] += modY;

                        subNode.Value = string.Format("{0},{1}", values[0], values[1]);
                    }
                    break;
                }
            }

            if (!found)
            {
                DefinitionFileItem subNode = new DefinitionFileItem();
                subNode.Name = "HOTSPOT";
                subNode.Value = string.Format("{0},{1}", modX, modY);

                node.Children.Add(subNode);
            }
            IsChanged = true;
        }
        //////////////////////////////////////////////////////////////////////////
        private void ProcessNode(DefinitionFileItem node)
        {
            if (node.Name != null && node.Name.ToUpper() == "IMAGE")
            {
                int modX, modY;
                Optimizer.CropImage(node.Value, out modX, out modY);

                if (modX != 0 || modY != 0) FixHotspot(node.Parent, modX, modY);
            }

            // the collection can grow by adding a missing hotspot, hence no foreach
            int numNodes = node.Children.Count;
            for (int i = 0; i < numNodes; i++)
            {
                DefinitionFileItem subNode = node.Children[i];
                ProcessNode(subNode);
            }
        }
        //////////////////////////////////////////////////////////////////////////
        private void NodeToString(DefinitionFileItem node, ref string str, string indent)
        {
            if (node.Name != null) str += indent + node.Name;

            if (node.Children.Count > 0)
            {
                if (node.Name != null) str += "\n" + indent + "{\n";

                foreach (DefinitionFileItem subNode in node.Children)
                {
                    string newIndent = indent;
                    if (node.Name != null) newIndent += "  ";
                    NodeToString(subNode, ref str, newIndent);
                }

                if (node.Name != null) str += indent + "}\n";
            }
            else
            {
                if (IsNumberList(node.Value))
                {
                    str += " { " + node.Value.Replace(",", ", ") + " } ";
                }
                else
                {
                    bool needsQuotes = node.Value.Contains(" ") || node.Value.Contains("\\") || node.Value == "";

                    str += " = ";
                    if (needsQuotes) str += "\"";
                    str += node.Value;
                    if (needsQuotes) str += "\"";
                }
                str += "\n";
            }
        }
        //////////////////////////////////////////////////////////////////////////
        protected bool ParseStructure(ref List<Token> Tokens)
        {
            string Name;
            List<Token> Value;
            int LineNum;

            while(GetValue(ref Tokens, out Name, out Value, out LineNum))
            {
                DefinitionFileItem item = new DefinitionFileItem();
                item.Name = Name;
                item.Parent = this;
                item.LineNum = LineNum;

                Children.Add(item);

                string value;
                if(IsValue(Value, out value))
                {
                    item.Value = value;
                }
                else
                {
                    while (Value.Count > 0)
                    {
                        item.ParseStructure(ref Value);
                    }
                }

            }
            if (Tokens.Count == 0) return true;
            else
            {
                Tokens.Clear();
                return false;
            }
        }
 //////////////////////////////////////////////////////////////////////////
 private void ScanDefinition(string DefFilename, DefinitionFileItem DefFileItem)
 {
     if (DefFileItem.Children.Count > 0)
     {
         for (int i = 0; i < DefFileItem.Children.Count; i++)
         {
             ScanDefinition(DefFilename, DefFileItem.Children[i]);
         }
     }
     else if (DefFileItem.Value!=string.Empty)
     {
         string[] ItemsToScan = new string[] { "CAPTION", "TITLE", "TEXT" };
         foreach(string Item in ItemsToScan)
         {
             if(DefFileItem.Name.ToUpper() == Item)
             {
                 Strings.Add(new StringLocation(DefFileItem.Value, DefFilename, DefFileItem.LineNum, StringLocation.StringType.DefinitionFile));
             }
         }
     }
 }