PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llpanel.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 349 lines | 208 code | 76 blank | 65 comment | 3 complexity | 2618ae9c4b4cdda85bff3a48b9db40b1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanel.h
  3. * @author James Cook, Tom Yedwab
  4. * @brief LLPanel base class
  5. *
  6. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #ifndef LL_LLPANEL_H
  28. #define LL_LLPANEL_H
  29. #include "llcallbackmap.h"
  30. #include "lluictrl.h"
  31. #include "llviewborder.h"
  32. #include "lluiimage.h"
  33. #include "lluistring.h"
  34. #include "v4color.h"
  35. #include "llbadgeholder.h"
  36. #include <list>
  37. #include <queue>
  38. const S32 LLPANEL_BORDER_WIDTH = 1;
  39. const BOOL BORDER_YES = TRUE;
  40. const BOOL BORDER_NO = FALSE;
  41. class LLButton;
  42. class LLUIImage;
  43. /*
  44. * General purpose concrete view base class.
  45. * Transparent or opaque,
  46. * With or without border,
  47. * Can contain LLUICtrls.
  48. */
  49. class LLPanel : public LLUICtrl, public LLBadgeHolder
  50. {
  51. public:
  52. struct LocalizedString : public LLInitParam::Block<LocalizedString>
  53. {
  54. Mandatory<std::string> name;
  55. Mandatory<std::string> value;
  56. LocalizedString();
  57. };
  58. struct Params
  59. : public LLInitParam::Block<Params, LLUICtrl::Params>
  60. {
  61. Optional<bool> has_border;
  62. Optional<LLViewBorder::Params> border;
  63. Optional<bool> background_visible,
  64. background_opaque;
  65. Optional<LLUIColor> bg_opaque_color,
  66. bg_alpha_color,
  67. bg_opaque_image_overlay,
  68. bg_alpha_image_overlay;
  69. // opaque image is for "panel in foreground" look
  70. Optional<LLUIImage*> bg_opaque_image,
  71. bg_alpha_image;
  72. Optional<S32> min_width,
  73. min_height;
  74. Optional<std::string> filename;
  75. Optional<std::string> class_name;
  76. Optional<std::string> help_topic;
  77. Multiple<LocalizedString> strings;
  78. Optional<CommitCallbackParam> visible_callback;
  79. Optional<bool> accepts_badge;
  80. Params();
  81. };
  82. protected:
  83. friend class LLUICtrlFactory;
  84. // RN: for some reason you can't just use LLUICtrlFactory::getDefaultParams as a default argument in VC8
  85. static const LLPanel::Params& getDefaultParams();
  86. // Panels can get constructed directly
  87. LLPanel(const LLPanel::Params& params = getDefaultParams());
  88. public:
  89. BOOL buildFromFile(const std::string &filename, LLXMLNodePtr output_node = NULL, const LLPanel::Params&default_params = getDefaultParams());
  90. static LLPanel* createFactoryPanel(const std::string& name);
  91. /*virtual*/ ~LLPanel();
  92. // LLView interface
  93. /*virtual*/ BOOL isPanel() const;
  94. /*virtual*/ void draw();
  95. /*virtual*/ BOOL handleKeyHere( KEY key, MASK mask );
  96. /*virtual*/ void handleVisibilityChange ( BOOL new_visibility );
  97. // From LLFocusableElement
  98. /*virtual*/ void setFocus( BOOL b );
  99. // New virtuals
  100. virtual void refresh(); // called in setFocus()
  101. virtual void clearCtrls(); // overridden in LLPanelObject and LLPanelVolume
  102. // Border controls
  103. void addBorder( LLViewBorder::Params p);
  104. void addBorder();
  105. void removeBorder();
  106. BOOL hasBorder() const { return mBorder != NULL; }
  107. void setBorderVisible( BOOL b );
  108. void setBackgroundColor( const LLColor4& color ) { mBgOpaqueColor = color; }
  109. const LLColor4& getBackgroundColor() const { return mBgOpaqueColor; }
  110. void setTransparentColor(const LLColor4& color) { mBgAlphaColor = color; }
  111. const LLColor4& getTransparentColor() const { return mBgAlphaColor; }
  112. void setBackgroundImage(LLUIImage* image) { mBgOpaqueImage = image; }
  113. void setTransparentImage(LLUIImage* image) { mBgAlphaImage = image; }
  114. LLPointer<LLUIImage> getBackgroundImage() const { return mBgOpaqueImage; }
  115. LLPointer<LLUIImage> getTransparentImage() const { return mBgAlphaImage; }
  116. LLColor4 getBackgroundImageOverlay() { return mBgOpaqueImageOverlay; }
  117. LLColor4 getTransparentImageOverlay() { return mBgAlphaImageOverlay; }
  118. void setBackgroundVisible( BOOL b ) { mBgVisible = b; }
  119. BOOL isBackgroundVisible() const { return mBgVisible; }
  120. void setBackgroundOpaque(BOOL b) { mBgOpaque = b; }
  121. BOOL isBackgroundOpaque() const { return mBgOpaque; }
  122. void setDefaultBtn(LLButton* btn = NULL);
  123. void setDefaultBtn(const std::string& id);
  124. void updateDefaultBtn();
  125. void setLabel(const LLStringExplicit& label) { mLabel = label; }
  126. std::string getLabel() const { return mLabel; }
  127. void setHelpTopic(const std::string& help_topic) { mHelpTopic = help_topic; }
  128. std::string getHelpTopic() const { return mHelpTopic; }
  129. void setCtrlsEnabled(BOOL b);
  130. LLHandle<LLPanel> getHandle() const { return getDerivedHandle<LLPanel>(); }
  131. const LLCallbackMap::map_t& getFactoryMap() const { return mFactoryMap; }
  132. CommitCallbackRegistry::ScopedRegistrar& getCommitCallbackRegistrar() { return mCommitCallbackRegistrar; }
  133. EnableCallbackRegistry::ScopedRegistrar& getEnableCallbackRegistrar() { return mEnableCallbackRegistrar; }
  134. void initFromParams(const Params& p);
  135. BOOL initPanelXML( LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node, const LLPanel::Params& default_params);
  136. bool hasString(const std::string& name);
  137. std::string getString(const std::string& name, const LLStringUtil::format_map_t& args) const;
  138. std::string getString(const std::string& name) const;
  139. // ** Wrappers for setting child properties by name ** -TomY
  140. // WARNING: These are deprecated, please use getChild<T>("name")->doStuff() idiom instead
  141. // LLView
  142. void childSetVisible(const std::string& name, bool visible);
  143. void childShow(const std::string& name) { childSetVisible(name, true); }
  144. void childHide(const std::string& name) { childSetVisible(name, false); }
  145. bool childIsVisible(const std::string& id) const;
  146. void childSetTentative(const std::string& name, bool tentative);
  147. void childSetEnabled(const std::string& name, bool enabled);
  148. void childEnable(const std::string& name) { childSetEnabled(name, true); }
  149. void childDisable(const std::string& name) { childSetEnabled(name, false); };
  150. bool childIsEnabled(const std::string& id) const;
  151. void childSetToolTip(const std::string& id, const std::string& msg);
  152. void childSetRect(const std::string& id, const LLRect &rect);
  153. bool childGetRect(const std::string& id, LLRect& rect) const;
  154. // LLUICtrl
  155. void childSetFocus(const std::string& id, BOOL focus = TRUE);
  156. BOOL childHasFocus(const std::string& id);
  157. // *TODO: Deprecate; for backwards compatability only:
  158. // Prefer getChild<LLUICtrl>("foo")->setCommitCallback(boost:bind(...)),
  159. // which takes a generic slot. Or use mCommitCallbackRegistrar.add() with
  160. // a named callback and reference it in XML.
  161. void childSetCommitCallback(const std::string& id, boost::function<void (LLUICtrl*,void*)> cb, void* data);
  162. void childSetValidate(const std::string& id, boost::function<bool (const LLSD& data)> cb );
  163. void childSetColor(const std::string& id, const LLColor4& color);
  164. LLCtrlSelectionInterface* childGetSelectionInterface(const std::string& id) const;
  165. LLCtrlListInterface* childGetListInterface(const std::string& id) const;
  166. LLCtrlScrollInterface* childGetScrollInterface(const std::string& id) const;
  167. // This is the magic bullet for data-driven UI
  168. void childSetValue(const std::string& id, LLSD value);
  169. LLSD childGetValue(const std::string& id) const;
  170. // For setting text / label replacement params, e.g. "Hello [NAME]"
  171. // Not implemented for all types, defaults to noop, returns FALSE if not applicaple
  172. BOOL childSetTextArg(const std::string& id, const std::string& key, const LLStringExplicit& text);
  173. BOOL childSetLabelArg(const std::string& id, const std::string& key, const LLStringExplicit& text);
  174. BOOL childSetToolTipArg(const std::string& id, const std::string& key, const LLStringExplicit& text);
  175. // LLTabContainer
  176. void childShowTab(const std::string& id, const std::string& tabname, bool visible = true);
  177. LLPanel *childGetVisibleTab(const std::string& id) const;
  178. // Find a child with a nonempty Help topic
  179. LLPanel *childGetVisibleTabWithHelp();
  180. LLPanel *childGetVisiblePanelWithHelp();
  181. // LLTextBox/LLTextEditor/LLLineEditor
  182. void childSetText(const std::string& id, const LLStringExplicit& text) { childSetValue(id, LLSD(text)); }
  183. // *NOTE: Does not return text from <string> tags, use getString()
  184. std::string childGetText(const std::string& id) const { return childGetValue(id).asString(); }
  185. // LLLineEditor
  186. void childSetPrevalidate(const std::string& id, bool (*func)(const LLWString &) );
  187. // LLButton
  188. void childSetAction(const std::string& id, boost::function<void(void*)> function, void* value);
  189. void childSetAction(const std::string& id, const commit_signal_t::slot_type& function);
  190. // LLTextBox
  191. void childSetActionTextbox(const std::string& id, boost::function<void(void*)> function, void* value = NULL);
  192. void childSetControlName(const std::string& id, const std::string& control_name);
  193. static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node = NULL);
  194. //call onOpen to let panel know when it's about to be shown or activated
  195. virtual void onOpen(const LLSD& key) {}
  196. void setXMLFilename(std::string filename) { mXMLFilename = filename; };
  197. std::string getXMLFilename() { return mXMLFilename; };
  198. boost::signals2::connection setVisibleCallback( const commit_signal_t::slot_type& cb );
  199. protected:
  200. // Override to set not found list
  201. LLButton* getDefaultButton() { return mDefaultBtn; }
  202. LLCallbackMap::map_t mFactoryMap;
  203. CommitCallbackRegistry::ScopedRegistrar mCommitCallbackRegistrar;
  204. EnableCallbackRegistry::ScopedRegistrar mEnableCallbackRegistrar;
  205. commit_signal_t* mVisibleSignal; // Called when visibility changes, passes new visibility as LLSD()
  206. std::string mHelpTopic; // the name of this panel's help topic to display in the Help Viewer
  207. typedef std::deque<const LLCallbackMap::map_t*> factory_stack_t;
  208. static factory_stack_t sFactoryStack;
  209. // for setting the xml filename when building panel in context dependent cases
  210. std::string mXMLFilename;
  211. private:
  212. BOOL mBgVisible; // any background at all?
  213. BOOL mBgOpaque; // use opaque color or image
  214. LLUIColor mBgOpaqueColor;
  215. LLUIColor mBgAlphaColor;
  216. LLUIColor mBgOpaqueImageOverlay;
  217. LLUIColor mBgAlphaImageOverlay;
  218. LLPointer<LLUIImage> mBgOpaqueImage; // "panel in front" look
  219. LLPointer<LLUIImage> mBgAlphaImage; // "panel in back" look
  220. LLViewBorder* mBorder;
  221. LLButton* mDefaultBtn;
  222. LLUIString mLabel;
  223. typedef std::map<std::string, std::string> ui_string_map_t;
  224. ui_string_map_t mUIStrings;
  225. }; // end class LLPanel
  226. // Build time optimization, generate once in .cpp file
  227. #ifndef LLPANEL_CPP
  228. extern template class LLPanel* LLView::getChild<class LLPanel>(
  229. const std::string& name, BOOL recurse) const;
  230. #endif
  231. typedef boost::function<LLPanel* (void)> LLPanelClassCreatorFunc;
  232. // local static instance for registering a particular panel class
  233. class LLRegisterPanelClass
  234. : public LLSingleton< LLRegisterPanelClass >
  235. {
  236. public:
  237. // reigister with either the provided builder, or the generic templated builder
  238. void addPanelClass(const std::string& tag,LLPanelClassCreatorFunc func)
  239. {
  240. mPanelClassesNames[tag] = func;
  241. }
  242. LLPanel* createPanelClass(const std::string& tag)
  243. {
  244. param_name_map_t::iterator iT = mPanelClassesNames.find(tag);
  245. if(iT == mPanelClassesNames.end())
  246. return 0;
  247. return iT->second();
  248. }
  249. template<typename T>
  250. static T* defaultPanelClassBuilder()
  251. {
  252. T* pT = new T();
  253. return pT;
  254. }
  255. private:
  256. typedef std::map< std::string, LLPanelClassCreatorFunc> param_name_map_t;
  257. param_name_map_t mPanelClassesNames;
  258. };
  259. // local static instance for registering a particular panel class
  260. template<typename T>
  261. class LLRegisterPanelClassWrapper
  262. : public LLRegisterPanelClass
  263. {
  264. public:
  265. // reigister with either the provided builder, or the generic templated builder
  266. LLRegisterPanelClassWrapper(const std::string& tag);
  267. };
  268. template<typename T>
  269. LLRegisterPanelClassWrapper<T>::LLRegisterPanelClassWrapper(const std::string& tag)
  270. {
  271. LLRegisterPanelClass::instance().addPanelClass(tag,&LLRegisterPanelClass::defaultPanelClassBuilder<T>);
  272. }
  273. #endif