llviewquery.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * @file llviewquery.cpp
  3. * @brief Implementation of view query class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "llviewquery.h"
  34. #include "lluictrl.h"
  35. #include "llview.h"
  36. void LLQuerySorter::operator()(LLView* parent, view_list_t& children) const
  37. {
  38. }
  39. filter_result_t LLLeavesFilter::operator()(const LLView* const view,
  40. const view_list_t& children) const
  41. {
  42. return filter_result_t(children.empty(), true);
  43. }
  44. filter_result_t LLRootsFilter::operator()(const LLView* const view,
  45. const view_list_t& children) const
  46. {
  47. return filter_result_t(true, false);
  48. }
  49. filter_result_t LLVisibleFilter::operator()(const LLView* const view,
  50. const view_list_t& children) const
  51. {
  52. return filter_result_t(view->getVisible(), view->getVisible());
  53. }
  54. filter_result_t LLEnabledFilter::operator()(const LLView* const view,
  55. const view_list_t& children) const
  56. {
  57. return filter_result_t(view->getEnabled(), view->getEnabled());
  58. }
  59. filter_result_t LLTabStopFilter::operator()(const LLView* const view,
  60. const view_list_t& children) const
  61. {
  62. return filter_result_t(view->isCtrl() &&
  63. static_cast<const LLUICtrl*>(view)->hasTabStop(),
  64. view->canFocusChildren());
  65. }
  66. filter_result_t LLCtrlFilter::operator()(const LLView* const view,
  67. const view_list_t& children) const
  68. {
  69. return filter_result_t(view->isCtrl(), true);
  70. }
  71. //
  72. // LLViewQuery
  73. //
  74. view_list_t LLViewQuery::run(LLView* view) const
  75. {
  76. view_list_t result;
  77. // prefilter gets immediate children of view
  78. filter_result_t pre = runFilters(view, *view->getChildList(), mPreFilters);
  79. if (!pre.first && !pre.second)
  80. {
  81. // Not including ourselves or the children; nothing more to do
  82. return result;
  83. }
  84. view_list_t filtered_children;
  85. filter_result_t post(true, true);
  86. if (pre.second)
  87. {
  88. // run filters on children
  89. filterChildren(view, filtered_children);
  90. // only run post filters if this element passed pre filters so if you
  91. // failed to pass the pre filter, you can't filter out children in post
  92. if (pre.first)
  93. {
  94. post = runFilters(view, filtered_children, mPostFilters);
  95. }
  96. }
  97. if (pre.first && post.first)
  98. {
  99. result.push_back(view);
  100. }
  101. if (pre.second && post.second)
  102. {
  103. result.insert(result.end(), filtered_children.begin(),
  104. filtered_children.end());
  105. }
  106. return result;
  107. }
  108. void LLViewQuery::filterChildren(LLView* view,
  109. view_list_t& filtered_children) const
  110. {
  111. LLView::child_list_t views(*(view->getChildList()));
  112. if (mSorterp)
  113. {
  114. (*mSorterp)(view, views); // sort the children per the sorter
  115. }
  116. for (LLView::child_list_iter_t iter = views.begin(), end = views.end();
  117. iter != end; ++iter)
  118. {
  119. view_list_t indiv_children = this->run(*iter);
  120. filtered_children.insert(filtered_children.end(),
  121. indiv_children.begin(), indiv_children.end());
  122. }
  123. }
  124. filter_result_t LLViewQuery::runFilters(LLView* view,
  125. const view_list_t& children,
  126. const filter_list_t& filters) const
  127. {
  128. filter_result_t result = filter_result_t(true, true);
  129. for (filter_list_const_iter_t iter = filters.begin(), end = filters.end();
  130. iter != end; ++iter)
  131. {
  132. filter_result_t filtered = (**iter)(view, children);
  133. result.first = result.first && filtered.first;
  134. result.second = result.second && filtered.second;
  135. }
  136. return result;
  137. }
  138. class SortByTabOrder : public LLQuerySorter, public LLSingleton<SortByTabOrder>
  139. {
  140. friend class LLSingleton<SortByTabOrder>;
  141. void operator()(LLView* parent,
  142. LLView::child_list_t& children) const override
  143. {
  144. children.sort(LLCompareByTabOrder(parent->getCtrlOrder()));
  145. }
  146. };
  147. LLCtrlQuery::LLCtrlQuery()
  148. : LLViewQuery()
  149. {
  150. setSorter(SortByTabOrder::getInstance());
  151. }