From f6970e6ad1f0576ec194fdc8d369030f1e31aeab Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Fri, 18 Feb 2011 13:04:41 -0800 Subject: Implemented path resolution. Should be able to test this now. --- indra/newview/lluilistener.cpp | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/indra/newview/lluilistener.cpp b/indra/newview/lluilistener.cpp index dafca0abf2..22d3b8b219 100644 --- a/indra/newview/lluilistener.cpp +++ b/indra/newview/lluilistener.cpp @@ -34,9 +34,11 @@ // std headers // external library headers // other Linden headers +#include "llviewerwindow.h" // to get root view #include "lluictrl.h" #include "llerror.h" + LLUIListener::LLUIListener(): LLEventAPI("UI", "LLUICtrl::CommitCallbackRegistry listener.\n" @@ -78,9 +80,38 @@ void LLUIListener::call(const LLSD& event) const } } -const LLUICtrl* resolve_path(const LLUICtrl* base, const std::string path) +const LLView* resolve_path(const LLView* context, const std::string path) { - // *TODO: walk the path + std::vector parts; + const std::string delims("/"); + LLStringUtilBase::getTokens(path, parts, delims); + + bool recurse = false; + for (std::vector::iterator it = parts.begin(); + it != parts.end() && context; it++) + { + std::string part = *it; + + if (part.length() == 0) + { + // Allow "foo//bar" meaning "descendant named bar" + recurse = true; + } + else + { + const LLView* found = context->findChildView(part, recurse); + if (!found) + { + return NULL; + } + else + { + context = found; + } + recurse = false; + } + } + return NULL; } @@ -88,9 +119,10 @@ void LLUIListener::getValue(const LLSD&event) const { LLSD reply; - const LLUICtrl* root = NULL; // *TODO: look this up - const LLUICtrl* ctrl = resolve_path(root, event["path"].asString()); - + const LLView* root = (LLView*)(gViewerWindow->getRootView()); + const LLView* view = resolve_path(root, event["path"].asString()); + const LLUICtrl* ctrl(dynamic_cast(view)); + if (ctrl) { reply["value"] = ctrl->getValue(); -- cgit v1.2.3