aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/llviewquery.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llui/llviewquery.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/linden/indra/llui/llviewquery.cpp b/linden/indra/llui/llviewquery.cpp
new file mode 100644
index 0000000..4867116
--- /dev/null
+++ b/linden/indra/llui/llviewquery.cpp
@@ -0,0 +1,145 @@
1/**
2 * @file llviewquery.cpp
3 * @brief Implementation of view query class.
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llview.h"
29#include "lluictrl.h"
30#include "llviewquery.h"
31
32void LLQuerySorter::operator() (LLView * parent, viewList_t &children) const {}
33
34filterResult_t LLNoLeavesFilter::operator() (const LLView* const view, const viewList_t & children) const
35{
36 return filterResult_t(!(view->getChildList()->size() == 0), TRUE);
37}
38
39filterResult_t LLVisibleFilter::operator() (const LLView* const view, const viewList_t & children) const
40{
41 return filterResult_t(view->getVisible(), view->getVisible());
42}
43filterResult_t LLEnabledFilter::operator() (const LLView* const view, const viewList_t & children) const
44{
45 return filterResult_t(view->getEnabled(), view->getEnabled());
46}
47filterResult_t LLTabStopFilter::operator() (const LLView* const view, const viewList_t & children) const
48{
49 return filterResult_t(view->isCtrl() && static_cast<const LLUICtrl* const>(view)->hasTabStop(),
50 view->canFocusChildren());
51}
52
53// LLViewQuery
54
55LLViewQuery::LLViewQuery(): mPreFilters(), mPostFilters(), mSorterp()
56{
57}
58
59void LLViewQuery::addPreFilter(const LLQueryFilter* prefilter) { mPreFilters.push_back(prefilter); }
60
61void LLViewQuery::addPostFilter(const LLQueryFilter* postfilter) { mPostFilters.push_back(postfilter); }
62
63const LLViewQuery::filterList_t & LLViewQuery::getPreFilters() const { return mPreFilters; }
64
65const LLViewQuery::filterList_t & LLViewQuery::getPostFilters() const { return mPostFilters; }
66
67void LLViewQuery::setSorter(const LLQuerySorter* sorterp) { mSorterp = sorterp; }
68const LLQuerySorter* LLViewQuery::getSorter() const { return mSorterp; }
69
70viewList_t LLViewQuery::run(LLView * view) const
71{
72 viewList_t result;
73
74 filterResult_t pre = runFilters(view, viewList_t(), mPreFilters);
75 if(!pre.first && !pre.second)
76 {
77 // skip post filters completely if we're not including ourselves or the children
78 return result;
79 }
80 if(pre.second)
81 {
82 // run filters on children
83 viewList_t filtered_children;
84 filterChildren(view, filtered_children);
85 filterResult_t post = runFilters(view, filtered_children, mPostFilters);
86 if(pre.first && post.first)
87 {
88 result.push_back(view);
89 }
90 if(post.second)
91 {
92 result.insert(result.end(), filtered_children.begin(), filtered_children.end());
93 }
94 }
95 else
96 {
97 if(pre.first)
98 {
99 result.push_back(view);
100 }
101 }
102 return result;
103}
104
105void LLViewQuery::filterChildren(LLView * view, viewList_t & filtered_children) const
106{
107 LLView::child_list_t views(*(view->getChildList()));
108 (*mSorterp)(view, views); // sort the children per the sorter
109 for(LLView::child_list_iter_t iter = views.begin();
110 iter != views.end();
111 iter++)
112 {
113 viewList_t indiv_children = this->run(*iter);
114 filtered_children.insert(filtered_children.end(), indiv_children.begin(), indiv_children.end());
115 }
116}
117
118filterResult_t LLViewQuery::runFilters(LLView * view, const viewList_t children, const filterList_t filters) const
119{
120 filterResult_t result = filterResult_t(TRUE, TRUE);
121 for(filterList_const_iter_t iter = filters.begin();
122 iter != filters.end();
123 iter++)
124 {
125 filterResult_t filtered = (**iter)(view, children);
126 result.first = result.first && filtered.first;
127 result.second = result.second && filtered.second;
128 }
129 return result;
130}
131
132class SortByTabOrder : public LLQuerySorter, public LLSingleton<SortByTabOrder>
133{
134 /*virtual*/ void operator() (LLView * parent, LLView::child_list_t &children) const
135 {
136 children.sort(LLCompareByTabOrder(parent->getCtrlOrder()));
137 }
138};
139
140LLCtrlQuery::LLCtrlQuery() :
141 LLViewQuery()
142{
143 setSorter(SortByTabOrder::getInstance());
144}
145