From 0e39a7881e29fe58761403424941b78f82042ac1 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Fri, 18 Feb 2011 11:31:18 -0800 Subject: Initial stub for getValue() and path walker --- indra/newview/lluilistener.cpp | 31 +++++++++++++++++++++++++++++++ indra/newview/lluilistener.h | 1 + 2 files changed, 32 insertions(+) (limited to 'indra') diff --git a/indra/newview/lluilistener.cpp b/indra/newview/lluilistener.cpp index 4d6eac4958..dafca0abf2 100644 --- a/indra/newview/lluilistener.cpp +++ b/indra/newview/lluilistener.cpp @@ -47,6 +47,12 @@ LLUIListener::LLUIListener(): "as if from a user gesture on a menu -- or a button click.", &LLUIListener::call, LLSD().with("function", LLSD())); + + add("getValue", + "For the UI control identified by the path in [\"path\"], return the control's\n" + "current value as [\"value\"] reply.", + &LLUIListener::getValue, + LLSD().with("path", LLSD())); } void LLUIListener::call(const LLSD& event) const @@ -71,3 +77,28 @@ void LLUIListener::call(const LLSD& event) const (*func)(NULL, event["parameter"]); } } + +const LLUICtrl* resolve_path(const LLUICtrl* base, const std::string path) +{ + // *TODO: walk the path + return NULL; +} + +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()); + + if (ctrl) + { + reply["value"] = ctrl->getValue(); + } + else + { + // *TODO: ??? return something indicating failure to resolve + } + + sendReply(reply, event, "reply"); +} diff --git a/indra/newview/lluilistener.h b/indra/newview/lluilistener.h index e7847f01e8..08724024dc 100644 --- a/indra/newview/lluilistener.h +++ b/indra/newview/lluilistener.h @@ -41,6 +41,7 @@ public: private: void call(const LLSD& event) const; + void getValue(const LLSD&event) const; }; #endif /* ! defined(LL_LLUILISTENER_H) */ -- cgit v1.2.3 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(-) (limited to 'indra') 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 From 96cac7c82fcb189a61d514a244b62970e943e4ad Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Fri, 18 Feb 2011 17:01:48 -0800 Subject: Fix up path resolution. --- indra/newview/lluilistener.cpp | 80 +++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 17 deletions(-) (limited to 'indra') diff --git a/indra/newview/lluilistener.cpp b/indra/newview/lluilistener.cpp index 22d3b8b219..d02d126cb5 100644 --- a/indra/newview/lluilistener.cpp +++ b/indra/newview/lluilistener.cpp @@ -32,6 +32,7 @@ #include "lluilistener.h" // STL headers // std headers +#include // external library headers // other Linden headers #include "llviewerwindow.h" // to get root view @@ -80,45 +81,90 @@ void LLUIListener::call(const LLSD& event) const } } +// Split string given a single character delimiter. +// Note that this returns empty strings for leading, trailing, and adjacent +// delimiters, such as "/foo/bar//baz/" -> ["", "foo", "bar", "", "baz", "" ] +std::vector split(const std::string& s, char delim) +{ + std::stringstream ss(s); + std::string item; + std::vector items; + while (std::getline(ss, item, delim)) + { + items.push_back(item); + } + return items; +} + +// Walk the LLView tree to resolve a path +// Paths can be discovered using Develop > XUI > Show XUI Paths +// +// A leading "/" indicates the root of the tree is the starting +// position of the search, (otherwise the context node is used) +// +// Adjacent "//" mean that the next level of the search is done +// recursively ("descendant" rather than "child"). +// +// Return values: If no match is found, NULL is returned, +// otherwise the matching LLView* is returned. +// +// Examples: +// +// "/" -> return the root view +// "/foo" -> find "foo" as a direct child of the root +// "foo" -> find "foo" as a direct child of the context node +// "//foo" -> find the first "foo" child anywhere in the tree +// "/foo/bar" -> find "foo" as direct child of the root, and +// "bar" as a direct child of "foo" +// "//foo//bar/baz" -> find the first "foo" anywhere in the +// tree, the first "bar" anywhere under it, and "baz" +// as a direct child of that +// const LLView* resolve_path(const LLView* context, const std::string path) { - std::vector parts; - const std::string delims("/"); - LLStringUtilBase::getTokens(path, parts, delims); + std::vector parts = split(path, '/'); + + if (parts.size() == 0) + { + return context; + } + + std::vector::iterator it = parts.begin(); + + // leading / means "start at root" + if ((*it).length() == 0) + { + context = (LLView*)(gViewerWindow->getRootView()); + it++; + } bool recurse = false; - for (std::vector::iterator it = parts.begin(); - it != parts.end() && context; it++) + for (; 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; - } + + context = found; recurse = false; } } - return NULL; + return context; } void LLUIListener::getValue(const LLSD&event) const { - LLSD reply; - + LLSD reply = LLSD::emptyMap(); + const LLView* root = (LLView*)(gViewerWindow->getRootView()); const LLView* view = resolve_path(root, event["path"].asString()); const LLUICtrl* ctrl(dynamic_cast(view)); @@ -132,5 +178,5 @@ void LLUIListener::getValue(const LLSD&event) const // *TODO: ??? return something indicating failure to resolve } - sendReply(reply, event, "reply"); + sendReply(reply, event); } -- cgit v1.2.3 From 1362a3e117dadbc5b1de18487314d4af57ce850f Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Tue, 22 Feb 2011 20:13:07 -0500 Subject: Move Josh's resolvePath() function to LLUI. Use boost::split_iterator to split LLView pathname on slashes. --- indra/llui/llui.cpp | 49 +++++++++++++++++++++++ indra/llui/llui.h | 27 +++++++++++++ indra/newview/lluilistener.cpp | 89 ++---------------------------------------- 3 files changed, 80 insertions(+), 85 deletions(-) (limited to 'indra') diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index c300fe55d9..87669574c2 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -61,6 +61,8 @@ // for XUIParse #include "llquaternion.h" #include +#include +#include // // Globals @@ -2020,6 +2022,53 @@ void LLUI::positionViewNearMouse(LLView* view, S32 spawn_x, S32 spawn_y) view->translateIntoRectWithExclusion( virtual_window_rect, mouse_rect, FALSE ); } +LLView* LLUI::resolvePath(LLView* context, const std::string& path) +{ + // Nothing about resolvePath() should require non-const LLView*. If caller + // wants non-const, call the const flavor and then cast away const-ness. + return const_cast(resolvePath(const_cast(context), path)); +} + +const LLView* LLUI::resolvePath(const LLView* context, const std::string& path) +{ + // Create an iterator over slash-separated parts of 'path'. Dereferencing + // this iterator returns an iterator_range over the substring. Unlike + // LLStringUtil::getTokens(), this split_iterator doesn't combine adjacent + // delimiters: leading/trailing slash produces an empty substring, double + // slash produces an empty substring. That's what we need. + boost::split_iterator ti(path, boost::first_finder("/")), tend; + + if (ti == tend) + { + // 'path' is completely empty, no navigation + return context; + } + + // leading / means "start at root" + if (ti->empty()) + { + context = getRootView(); + ++ti; + } + + bool recurse = false; + for (; ti != tend && context; ++ti) + { + if (ti->empty()) + { + recurse = true; + } + else + { + std::string part(ti->begin(), ti->end()); + context = context->findChildView(part, recurse); + recurse = false; + } + } + + return context; +} + // LLLocalClipRect and LLScreenClipRect moved to lllocalcliprect.h/cpp diff --git a/indra/llui/llui.h b/indra/llui/llui.h index 62d10df8b2..50cb9e6632 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -185,6 +185,33 @@ public: //helper functions (should probably move free standing rendering helper functions here) static LLView* getRootView() { return sRootView; } static void setRootView(LLView* view) { sRootView = view; } + /** + * Walk the LLView tree to resolve a path + * Paths can be discovered using Develop > XUI > Show XUI Paths + * + * A leading "/" indicates the root of the tree is the starting + * position of the search, (otherwise the context node is used) + * + * Adjacent "//" mean that the next level of the search is done + * recursively ("descendant" rather than "child"). + * + * Return values: If no match is found, NULL is returned, + * otherwise the matching LLView* is returned. + * + * Examples: + * + * "/" -> return the root view + * "/foo" -> find "foo" as a direct child of the root + * "foo" -> find "foo" as a direct child of the context node + * "//foo" -> find the first "foo" child anywhere in the tree + * "/foo/bar" -> find "foo" as direct child of the root, and + * "bar" as a direct child of "foo" + * "//foo//bar/baz" -> find the first "foo" anywhere in the + * tree, the first "bar" anywhere under it, and "baz" + * as a direct child of that + */ + static const LLView* resolvePath(const LLView* context, const std::string& path); + static LLView* resolvePath(LLView* context, const std::string& path); static std::string locateSkin(const std::string& filename); static void setMousePositionScreen(S32 x, S32 y); static void getMousePositionScreen(S32 *x, S32 *y); diff --git a/indra/newview/lluilistener.cpp b/indra/newview/lluilistener.cpp index d02d126cb5..6b2cd71d40 100644 --- a/indra/newview/lluilistener.cpp +++ b/indra/newview/lluilistener.cpp @@ -32,10 +32,9 @@ #include "lluilistener.h" // STL headers // std headers -#include // external library headers // other Linden headers -#include "llviewerwindow.h" // to get root view +#include "llui.h" // getRootView(), resolvePath() #include "lluictrl.h" #include "llerror.h" @@ -55,7 +54,7 @@ LLUIListener::LLUIListener(): "For the UI control identified by the path in [\"path\"], return the control's\n" "current value as [\"value\"] reply.", &LLUIListener::getValue, - LLSD().with("path", LLSD())); + LLSDMap("path", LLSD())("reply", LLSD())); } void LLUIListener::call(const LLSD& event) const @@ -81,92 +80,12 @@ void LLUIListener::call(const LLSD& event) const } } -// Split string given a single character delimiter. -// Note that this returns empty strings for leading, trailing, and adjacent -// delimiters, such as "/foo/bar//baz/" -> ["", "foo", "bar", "", "baz", "" ] -std::vector split(const std::string& s, char delim) -{ - std::stringstream ss(s); - std::string item; - std::vector items; - while (std::getline(ss, item, delim)) - { - items.push_back(item); - } - return items; -} - -// Walk the LLView tree to resolve a path -// Paths can be discovered using Develop > XUI > Show XUI Paths -// -// A leading "/" indicates the root of the tree is the starting -// position of the search, (otherwise the context node is used) -// -// Adjacent "//" mean that the next level of the search is done -// recursively ("descendant" rather than "child"). -// -// Return values: If no match is found, NULL is returned, -// otherwise the matching LLView* is returned. -// -// Examples: -// -// "/" -> return the root view -// "/foo" -> find "foo" as a direct child of the root -// "foo" -> find "foo" as a direct child of the context node -// "//foo" -> find the first "foo" child anywhere in the tree -// "/foo/bar" -> find "foo" as direct child of the root, and -// "bar" as a direct child of "foo" -// "//foo//bar/baz" -> find the first "foo" anywhere in the -// tree, the first "bar" anywhere under it, and "baz" -// as a direct child of that -// -const LLView* resolve_path(const LLView* context, const std::string path) -{ - std::vector parts = split(path, '/'); - - if (parts.size() == 0) - { - return context; - } - - std::vector::iterator it = parts.begin(); - - // leading / means "start at root" - if ((*it).length() == 0) - { - context = (LLView*)(gViewerWindow->getRootView()); - it++; - } - - bool recurse = false; - for (; it != parts.end() && context; it++) - { - std::string part = *it; - - if (part.length() == 0) - { - recurse = true; - } - else - { - const LLView* found = context->findChildView(part, recurse); - if (!found) - return NULL; - - context = found; - recurse = false; - } - } - - return context; -} - void LLUIListener::getValue(const LLSD&event) const { LLSD reply = LLSD::emptyMap(); - const LLView* root = (LLView*)(gViewerWindow->getRootView()); - const LLView* view = resolve_path(root, event["path"].asString()); + const LLView* root = LLUI::getRootView(); + const LLView* view = LLUI::resolvePath(root, event["path"].asString()); const LLUICtrl* ctrl(dynamic_cast(view)); if (ctrl) -- cgit v1.2.3