diff options
Diffstat (limited to 'indra/llui/llview.cpp')
-rwxr-xr-x | indra/llui/llview.cpp | 172 |
1 files changed, 75 insertions, 97 deletions
diff --git a/indra/llui/llview.cpp b/indra/llui/llview.cpp index 1982c97b8c..e0fa59793c 100755 --- a/indra/llui/llview.cpp +++ b/indra/llui/llview.cpp @@ -140,7 +140,6 @@ LLView::LLView(const LLView::Params& p) mFromXUI(p.from_xui), mIsFocusRoot(p.focus_root), mLastVisible(FALSE), - mNextInsertionOrdinal(0), mHoverCursor(getCursorFromString(p.hover_cursor)), mEnabled(p.enabled), mMouseOpaque(p.mouse_opaque), @@ -275,22 +274,6 @@ void LLView::sendChildToBack(LLView* child) } } -void LLView::moveChildToFrontOfTabGroup(LLUICtrl* child) -{ - if(mCtrlOrder.find(child) != mCtrlOrder.end()) - { - mCtrlOrder[child].second = -1 * mNextInsertionOrdinal++; - } -} - -void LLView::moveChildToBackOfTabGroup(LLUICtrl* child) -{ - if(mCtrlOrder.find(child) != mCtrlOrder.end()) - { - mCtrlOrder[child].second = mNextInsertionOrdinal++; - } -} - // virtual bool LLView::addChild(LLView* child, S32 tab_group) { @@ -298,7 +281,8 @@ bool LLView::addChild(LLView* child, S32 tab_group) { return false; } - if (mParentView == child) + + if (this == child) { LL_ERRS() << "Adding view " << child->getName() << " as child of itself" << LL_ENDL; } @@ -312,14 +296,10 @@ bool LLView::addChild(LLView* child, S32 tab_group) // add to front of child list, as normal mChildList.push_front(child); - // add to ctrl list if is LLUICtrl - if (child->isCtrl()) + // add to tab order list + if (tab_group != 0) { - LLUICtrl* ctrl = static_cast<LLUICtrl*>(child); - mCtrlOrder.insert(tab_order_pair_t(ctrl, - tab_order_t(tab_group, mNextInsertionOrdinal))); - - mNextInsertionOrdinal++; + mTabOrder.insert(tab_order_pair_t(child, tab_group)); } child->mParentView = this; @@ -350,13 +330,10 @@ void LLView::removeChild(LLView* child) llassert(child->mInDraw == false); mChildList.remove( child ); child->mParentView = NULL; - if (child->isCtrl()) + child_tab_order_t::iterator found = mTabOrder.find(child); + if(found != mTabOrder.end()) { - child_tab_order_t::iterator found = mCtrlOrder.find(static_cast<LLUICtrl*>(child)); - if(found != mCtrlOrder.end()) - { - mCtrlOrder.erase(found); - } + mTabOrder.erase(found); } } else @@ -366,53 +343,6 @@ void LLView::removeChild(LLView* child) updateBoundingRect(); } -LLView::ctrl_list_t LLView::getCtrlList() const -{ - ctrl_list_t controls; - BOOST_FOREACH(LLView* viewp, mChildList) - { - if(viewp->isCtrl()) - { - controls.push_back(static_cast<LLUICtrl*>(viewp)); - } - } - return controls; -} - -LLView::ctrl_list_t LLView::getCtrlListSorted() const -{ - ctrl_list_t controls = getCtrlList(); - std::sort(controls.begin(), controls.end(), LLCompareByTabOrder(mCtrlOrder)); - return controls; -} - - -// This method compares two LLViews by the tab order specified in the comparator object. The -// code for this is a little convoluted because each argument can have four states: -// 1) not a control, 2) a control but not in the tab order, 3) a control in the tab order, 4) null -bool LLCompareByTabOrder::operator() (const LLView* const a, const LLView* const b) const -{ - S32 a_score = 0, b_score = 0; - if(a) a_score--; - if(b) b_score--; - if(a && a->isCtrl()) a_score--; - if(b && b->isCtrl()) b_score--; - if(a_score == -2 && b_score == -2) - { - const LLUICtrl * const a_ctrl = static_cast<const LLUICtrl*>(a); - const LLUICtrl * const b_ctrl = static_cast<const LLUICtrl*>(b); - LLView::child_tab_order_const_iter_t a_found = mTabOrder.find(a_ctrl), b_found = mTabOrder.find(b_ctrl); - if(a_found != mTabOrder.end()) a_score--; - if(b_found != mTabOrder.end()) b_score--; - if(a_score == -3 && b_score == -3) - { - // whew! Once we're in here, they're both in the tab order, and we can compare based on that - return compareTabOrders(a_found->second, b_found->second); - } - } - return (a_score == b_score) ? a < b : a_score < b_score; -} - BOOL LLView::isInVisibleChain() const { BOOL visible = TRUE; @@ -536,9 +466,9 @@ BOOL LLView::focusPrevRoot() // static BOOL LLView::focusNext(LLView::child_list_t & result) { - LLView::child_list_iter_t focused = result.end(); - for(LLView::child_list_iter_t iter = result.begin(); - iter != result.end(); + LLView::child_list_reverse_iter_t focused = result.rend(); + for(LLView::child_list_reverse_iter_t iter = result.rbegin(); + iter != result.rend(); ++iter) { if(gFocusMgr.childHasKeyboardFocus(*iter)) @@ -547,14 +477,14 @@ BOOL LLView::focusNext(LLView::child_list_t & result) break; } } - LLView::child_list_iter_t next = focused; - next = (next == result.end()) ? result.begin() : ++next; + LLView::child_list_reverse_iter_t next = focused; + next = (next == result.rend()) ? result.rbegin() : ++next; while(next != focused) { // wrap around to beginning if necessary - if(next == result.end()) + if(next == result.rend()) { - next = result.begin(); + next = result.rbegin(); } if((*next)->isCtrl()) { @@ -572,9 +502,9 @@ BOOL LLView::focusNext(LLView::child_list_t & result) // static BOOL LLView::focusPrev(LLView::child_list_t & result) { - LLView::child_list_reverse_iter_t focused = result.rend(); - for(LLView::child_list_reverse_iter_t iter = result.rbegin(); - iter != result.rend(); + LLView::child_list_iter_t focused = result.end(); + for(LLView::child_list_iter_t iter = result.begin(); + iter != result.end(); ++iter) { if(gFocusMgr.childHasKeyboardFocus(*iter)) @@ -583,14 +513,14 @@ BOOL LLView::focusPrev(LLView::child_list_t & result) break; } } - LLView::child_list_reverse_iter_t next = focused; - next = (next == result.rend()) ? result.rbegin() : ++next; + LLView::child_list_iter_t next = focused; + next = (next == result.end()) ? result.begin() : ++next; while(next != focused) { // wrap around to beginning if necessary - if(next == result.rend()) + if(next == result.end()) { - next = result.rbegin(); + next = result.begin(); } if((*next)->isCtrl()) { @@ -614,7 +544,7 @@ BOOL LLView::focusPrev(LLView::child_list_t & result) void LLView::deleteAllChildren() { // clear out the control ordering - mCtrlOrder.clear(); + mTabOrder.clear(); while (!mChildList.empty()) { @@ -1823,15 +1753,63 @@ BOOL LLView::localRectToOtherView( const LLRect& local, LLRect* other, const LLV return FALSE; } + +class CompareByTabOrder +{ +public: + CompareByTabOrder(const LLView::child_tab_order_t& order, S32 default_tab_group = 0) + : mTabOrder(order), + mDefaultTabGroup(default_tab_group) + {} + virtual ~CompareByTabOrder() {} + + // This method compares two LLViews by the tab order specified in the comparator object. The + // code for this is a little convoluted because each argument can have four states: + // 1) not a control, 2) a control but not in the tab order, 3) a control in the tab order, 4) null + bool operator() (const LLView* const a, const LLView* const b) const + { + S32 a_group = 0, b_group = 0; + if(!a) return false; + if(!b) return true; + + LLView::child_tab_order_const_iter_t a_found = mTabOrder.find(a), b_found = mTabOrder.find(b); + if(a_found != mTabOrder.end()) + { + a_group = a_found->second; + } + if(b_found != mTabOrder.end()) + { + b_group = b_found->second; + } + + if(a_group < mDefaultTabGroup && b_group >= mDefaultTabGroup) return true; + if(b_group < mDefaultTabGroup && a_group >= mDefaultTabGroup) return false; + return a_group > b_group; // sort correctly if they're both on the same side of the default tab groupreturn a > b; + } +private: + // ok to store a reference, as this should only be allocated on stack during view query operations + const LLView::child_tab_order_t& mTabOrder; + const S32 mDefaultTabGroup; +}; + +class SortByTabOrder : public LLQuerySorter, public LLSingleton<SortByTabOrder> +{ + /*virtual*/ void sort(LLView * parent, LLView::child_list_t &children) const + { + children.sort(CompareByTabOrder(parent->getTabOrder(), parent->getDefaultTabGroup())); + } +}; + // static -const LLCtrlQuery & LLView::getTabOrderQuery() +const LLViewQuery & LLView::getTabOrderQuery() { - static LLCtrlQuery query; + static LLViewQuery query; if(query.getPreFilters().size() == 0) { query.addPreFilter(LLVisibleFilter::getInstance()); query.addPreFilter(LLEnabledFilter::getInstance()); query.addPreFilter(LLTabStopFilter::getInstance()); query.addPostFilter(LLLeavesFilter::getInstance()); + query.setSorter(SortByTabOrder::getInstance()); } return query; } @@ -1846,9 +1824,9 @@ class LLFocusRootsFilter : public LLQueryFilter, public LLSingleton<LLFocusRoots }; // static -const LLCtrlQuery & LLView::getFocusRootsQuery() +const LLViewQuery & LLView::getFocusRootsQuery() { - static LLCtrlQuery query; + static LLViewQuery query; if(query.getPreFilters().size() == 0) { query.addPreFilter(LLVisibleFilter::getInstance()); query.addPreFilter(LLEnabledFilter::getInstance()); |