Exemplo n.º 1
0
//
// ICRoot::FindByName
//
// Find a root level control by name
//
// The syntax for this function is as follow
//
//   '^' - begins searching from previous control
//   '|' - begins searching from the root
//   '<' - moves to the parent of the current control
//         more '<' characters will move up more levels
//
// In the structure:
//
// root
//   +- child1
//   | +- a
//   |   +- b
//   |
//   +- child2
//      +- a
//
// with base of 'b': 
//   '<a'           refers to the window 'root\child1\a'
//   '<<<child2.a'  refers to the window 'root\child2\a'
//   '|child2.a'    also refers to 'root\child2\a'
// 
IControl *ICRoot::FindByName(const char *name, IControl *base)
{
  char path[256];
  char *token, *p = path;
  IControl *ctrl = base ? base : this;

  Utils::Strmcpy(path, name, sizeof(path));

  // if we find '^' then 
  if (*p == '^' && previous.Alive())
  {
    ctrl = previous;
    p++;
  }
  else
  {
    // if we find '|' then base search from root
    while (*p == '|')
    {
      ctrl = this;
      p++;
    }
  }

  // for each '<' move base up one level
  while (*p == '<') 
  {
    if (ctrl == NULL)
    {
      ERR_FATAL(("Too many '<' in control name [%s]", name));
    }
    ctrl = ctrl->parent;
    p++;
  }

  // descend into the tree searching for '.' seperated names
  if (ctrl)
  {
    token = strtok(p, ".");

    while (token && ctrl)
    {
      ctrl = ctrl->Find(Crc::CalcStr(token));
      token = strtok(NULL, ".");
    }
  }

  return ctrl;
}