PageRenderTime 27ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llfloaterreg.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 153 lines | 78 code | 26 blank | 49 comment | 0 complexity | d50d6daa7bbd67d1bd4ee8fcc83ca8f9 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaterreg.h
  3. * @brief LLFloaterReg Floater Registration Class
  4. *
  5. * $LicenseInfo:firstyear=2002&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. #ifndef LLFLOATERREG_H
  27. #define LLFLOATERREG_H
  28. /// llcommon
  29. #include "llrect.h"
  30. #include "llsd.h"
  31. #include <boost/function.hpp>
  32. //*******************************************************
  33. //
  34. // Floater Class Registry
  35. //
  36. class LLFloater;
  37. class LLUICtrl;
  38. typedef boost::function<LLFloater* (const LLSD& key)> LLFloaterBuildFunc;
  39. class LLFloaterReg
  40. {
  41. public:
  42. // We use a list of LLFloater's instead of a set for two reasons:
  43. // 1) With a list we have a predictable ordering, useful for finding the last opened floater of a given type.
  44. // 2) We can change the key of a floater without altering the list.
  45. typedef std::list<LLFloater*> instance_list_t;
  46. typedef const instance_list_t const_instance_list_t;
  47. typedef std::map<std::string, instance_list_t> instance_map_t;
  48. struct BuildData
  49. {
  50. LLFloaterBuildFunc mFunc;
  51. std::string mFile;
  52. };
  53. typedef std::map<std::string, BuildData> build_map_t;
  54. private:
  55. friend class LLFloaterRegListener;
  56. static instance_list_t sNullInstanceList;
  57. static instance_map_t sInstanceMap;
  58. static build_map_t sBuildMap;
  59. static std::map<std::string,std::string> sGroupMap;
  60. static bool sBlockShowFloaters;
  61. /**
  62. * Defines list of floater names that can be shown despite state of sBlockShowFloaters.
  63. */
  64. static std::set<std::string> sAlwaysShowableList;
  65. public:
  66. // Registration
  67. // usage: LLFloaterClassRegistry::add("foo", (LLFloaterBuildFunc)&LLFloaterClassRegistry::build<LLFloaterFoo>);
  68. template <class T>
  69. static LLFloater* build(const LLSD& key)
  70. {
  71. T* floater = new T(key);
  72. return floater;
  73. }
  74. static void add(const std::string& name, const std::string& file, const LLFloaterBuildFunc& func,
  75. const std::string& groupname = LLStringUtil::null);
  76. // Helpers
  77. static LLFloater* getLastFloaterInGroup(const std::string& name);
  78. static LLFloater* getLastFloaterCascading();
  79. // Find / get (create) / remove / destroy
  80. static LLFloater* findInstance(const std::string& name, const LLSD& key = LLSD());
  81. static LLFloater* getInstance(const std::string& name, const LLSD& key = LLSD());
  82. static LLFloater* removeInstance(const std::string& name, const LLSD& key = LLSD());
  83. static bool destroyInstance(const std::string& name, const LLSD& key = LLSD());
  84. // Iterators
  85. static const_instance_list_t& getFloaterList(const std::string& name);
  86. // Visibility Management
  87. // return NULL if instance not found or can't create instance (no builder)
  88. static LLFloater* showInstance(const std::string& name, const LLSD& key = LLSD(), BOOL focus = FALSE);
  89. // Close a floater (may destroy or set invisible)
  90. // return false if can't find instance
  91. static bool hideInstance(const std::string& name, const LLSD& key = LLSD());
  92. // return true if instance is visible:
  93. static bool toggleInstance(const std::string& name, const LLSD& key = LLSD());
  94. static bool instanceVisible(const std::string& name, const LLSD& key = LLSD());
  95. static void showInitialVisibleInstances();
  96. static void hideVisibleInstances(const std::set<std::string>& exceptions = std::set<std::string>());
  97. static void restoreVisibleInstances();
  98. // Control Variables
  99. static std::string getRectControlName(const std::string& name);
  100. static std::string declareRectControl(const std::string& name);
  101. static std::string getVisibilityControlName(const std::string& name);
  102. static std::string declareVisibilityControl(const std::string& name);
  103. static std::string declareDockStateControl(const std::string& name);
  104. static std::string getDockStateControlName(const std::string& name);
  105. static void registerControlVariables();
  106. // Callback wrappers
  107. static void toggleInstanceOrBringToFront(const LLSD& sdname, const LLSD& key = LLSD());
  108. // Typed find / get / show
  109. template <class T>
  110. static T* findTypedInstance(const std::string& name, const LLSD& key = LLSD())
  111. {
  112. return dynamic_cast<T*>(findInstance(name, key));
  113. }
  114. template <class T>
  115. static T* getTypedInstance(const std::string& name, const LLSD& key = LLSD())
  116. {
  117. return dynamic_cast<T*>(getInstance(name, key));
  118. }
  119. template <class T>
  120. static T* showTypedInstance(const std::string& name, const LLSD& key = LLSD(), BOOL focus = FALSE)
  121. {
  122. return dynamic_cast<T*>(showInstance(name, key, focus));
  123. }
  124. static void blockShowFloaters(bool value) { sBlockShowFloaters = value;}
  125. static U32 getVisibleFloaterInstanceCount();
  126. };
  127. #endif