PageRenderTime 43ms CodeModel.GetById 2ms app.highlight 35ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llviewquery.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 151 lines | 98 code | 19 blank | 34 comment | 16 complexity | 625b4f960e5f78a24bad331068feb760 MD5 | raw file
  1/** 
  2 * @file llviewquery.cpp
  3 * @brief Implementation of view query class.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "linden_common.h"
 28
 29#include "llview.h"
 30#include "lluictrl.h"
 31#include "llviewquery.h"
 32
 33void LLQuerySorter::operator() (LLView * parent, viewList_t &children) const {}
 34
 35filterResult_t LLLeavesFilter::operator() (const LLView* const view, const viewList_t & children) const 
 36{
 37	return filterResult_t(children.empty(), TRUE);
 38}
 39
 40filterResult_t LLRootsFilter::operator() (const LLView* const view, const viewList_t & children) const 
 41{
 42	return filterResult_t(TRUE, FALSE);
 43}
 44
 45filterResult_t LLVisibleFilter::operator() (const LLView* const view, const viewList_t & children) const 
 46{
 47	return filterResult_t(view->getVisible(), view->getVisible());
 48}
 49filterResult_t LLEnabledFilter::operator() (const LLView* const view, const viewList_t & children) const 
 50{
 51	return filterResult_t(view->getEnabled(), view->getEnabled());
 52}
 53filterResult_t LLTabStopFilter::operator() (const LLView* const view, const viewList_t & children) const 
 54{
 55	return filterResult_t(view->isCtrl() && static_cast<const LLUICtrl*>(view)->hasTabStop(),
 56						view->canFocusChildren());
 57}
 58
 59filterResult_t LLCtrlFilter::operator() (const LLView* const view, const viewList_t & children) const 
 60{
 61	return filterResult_t(view->isCtrl(),TRUE);
 62}
 63
 64//
 65// LLViewQuery
 66//
 67
 68viewList_t LLViewQuery::run(LLView* view) const
 69{
 70	viewList_t result;
 71
 72	// prefilter gets immediate children of view
 73	filterResult_t pre = runFilters(view, *view->getChildList(), mPreFilters);
 74	if(!pre.first && !pre.second)
 75	{
 76		// not including ourselves or the children
 77		// nothing more to do
 78		return result;
 79	}
 80
 81	viewList_t filtered_children;
 82	filterResult_t post(TRUE, TRUE);
 83	if(pre.second)
 84	{
 85		// run filters on children
 86		filterChildren(view, filtered_children);
 87		// only run post filters if this element passed pre filters
 88		// so if you failed to pass the pre filter, you can't filter out children in post
 89		if (pre.first)
 90		{
 91			post = runFilters(view, filtered_children, mPostFilters);
 92			}
 93		}
 94
 95	if(pre.first && post.first) 
 96	{
 97		result.push_back(view);
 98	}
 99
100	if(pre.second && post.second)
101	{
102		result.insert(result.end(), filtered_children.begin(), filtered_children.end());
103	}
104
105	return result;
106}
107
108void LLViewQuery::filterChildren(LLView * view, viewList_t & filtered_children) const
109{
110	LLView::child_list_t views(*(view->getChildList()));
111	if (mSorterp)
112	{
113		(*mSorterp)(view, views); // sort the children per the sorter
114	}
115	for(LLView::child_list_iter_t iter = views.begin();
116		iter != views.end();
117		iter++)
118	{
119		viewList_t indiv_children = this->run(*iter);
120		filtered_children.splice(filtered_children.end(), indiv_children);
121	}
122}
123
124filterResult_t LLViewQuery::runFilters(LLView * view, const viewList_t children, const filterList_t filters) const
125{
126	filterResult_t result = filterResult_t(TRUE, TRUE);
127	for(filterList_const_iter_t iter = filters.begin();
128		iter != filters.end();
129		iter++)
130	{
131		filterResult_t filtered = (**iter)(view, children);
132		result.first = result.first && filtered.first;
133		result.second = result.second && filtered.second;
134	}
135	return result;
136}
137
138class SortByTabOrder : public LLQuerySorter, public LLSingleton<SortByTabOrder>
139{
140	/*virtual*/ void operator() (LLView * parent, LLView::child_list_t &children) const 
141	{
142		children.sort(LLCompareByTabOrder(parent->getCtrlOrder()));
143	}
144};
145
146LLCtrlQuery::LLCtrlQuery() : 
147	LLViewQuery()
148{
149	setSorter(SortByTabOrder::getInstance());
150}
151