llpanel.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /**
  2. * @file llpanel.h
  3. * @author James Cook, Tom Yedwab
  4. * @brief LLPanel base class
  5. *
  6. * $LicenseInfo:firstyear=2001&license=viewergpl$
  7. *
  8. * Copyright (c) 2001-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLPANEL_H
  34. #define LL_LLPANEL_H
  35. #include "llbutton.h"
  36. #include "llcallbackmap.h"
  37. #include "lllineeditor.h"
  38. #include "lluictrl.h"
  39. #include "lluistring.h"
  40. #include "llviewborder.h"
  41. #include "llcolor4.h"
  42. constexpr S32 LLPANEL_BORDER_WIDTH = 1;
  43. constexpr bool BORDER_YES = true;
  44. constexpr bool BORDER_NO = false;
  45. class LLFloater;
  46. // General purpose concrete view base class, transparent or opaque, with or
  47. // without border, can contain LLUICtrls.
  48. class LLPanel : public LLUICtrl
  49. {
  50. protected:
  51. LOG_CLASS(LLPanel);
  52. public:
  53. // Minimal constructor for data-driven initialization
  54. LLPanel();
  55. LLPanel(const std::string& name);
  56. // Position and size not saved
  57. LLPanel(const std::string& name, const LLRect& rect, bool bordered = true);
  58. // Position and size are saved to rect_control
  59. LLPanel(const std::string& name, const std::string& rect_control,
  60. bool bordered = true);
  61. ~LLPanel() override;
  62. const std::string& getTag() const override;
  63. LLXMLNodePtr getXML(bool save_children = true) const override;
  64. // LLView interface
  65. LL_INLINE LLPanel* asPanel() override { return this; }
  66. void draw() override;
  67. bool handleKeyHere(KEY key, MASK mask) override;
  68. // Override to set not found list:
  69. LLView* getChildView(const char* name, bool recurse = true,
  70. bool create_if_missing = true) const override;
  71. // LLFocusableElement interface
  72. void setFocus(bool b) override;
  73. // LLUICtrl interface
  74. void setAlpha(F32 alpha) override;
  75. // New virtuals
  76. virtual void refresh(); // Called in setFocus()
  77. virtual bool postBuild();
  78. // Overridden in LLPanelObject and LLPanelVolume
  79. virtual void clearCtrls();
  80. // Border controls
  81. void addBorder(LLViewBorder::EBevel bevel = LLViewBorder::BEVEL_OUT,
  82. LLViewBorder::EStyle style = LLViewBorder::STYLE_LINE,
  83. S32 border_thickness = LLPANEL_BORDER_WIDTH);
  84. void removeBorder();
  85. LL_INLINE bool hasBorder() const { return mBorder != NULL; }
  86. void setBorderVisible(bool b);
  87. LL_INLINE void setBackgroundColor(const LLColor4& c) { mBgColorOpaque = c; }
  88. LL_INLINE const LLColor4& getBackgroundColor() const { return mBgColorOpaque; }
  89. LL_INLINE void setTransparentColor(const LLColor4& c) { mBgColorAlpha = c; }
  90. LL_INLINE const LLColor4& getTransparentColor() const { return mBgColorAlpha; }
  91. LL_INLINE void setBackgroundVisible(bool b) { mBgVisible = b; }
  92. LL_INLINE bool isBackgroundVisible() const { return mBgVisible; }
  93. LL_INLINE void setBackgroundOpaque(bool b) { mBgOpaque = b; }
  94. LL_INLINE bool isBackgroundOpaque() const { return mBgOpaque; }
  95. void setDefaultBtn(LLButton* btn = NULL);
  96. void setDefaultBtn(const char* id);
  97. void updateDefaultBtn();
  98. LL_INLINE void setLabel(const std::string& label) { mLabel = label; }
  99. LL_INLINE std::string getLabel() const { return mLabel; }
  100. LL_INLINE void setRectControl(const std::string& rc) { mRectControl.assign(rc); }
  101. LL_INLINE const std::string& getRectControl() const { return mRectControl; }
  102. void storeRectControl();
  103. void setCtrlsEnabled(bool b);
  104. LL_INLINE LLHandle<LLPanel> getHandle() const { return getDerivedHandle<LLPanel>(); }
  105. LL_INLINE S32 getLastTabGroup() const { return mLastTabGroup; }
  106. const LLCallbackMap::map_t& getFactoryMap() const { return mFactoryMap; }
  107. bool initPanelXML(LLXMLNodePtr nodep, LLView* parentp,
  108. LLUICtrlFactory* factoryp);
  109. void initChildrenXML(LLXMLNodePtr nodep, LLUICtrlFactory* factoryp);
  110. void setPanelParameters(LLXMLNodePtr nodep, LLView* parentp);
  111. LLFloater* getParentFloater() const;
  112. std::string getString(const std::string& name,
  113. const LLStringUtil::format_map_t& args) const;
  114. std::string getString(const std::string& name) const;
  115. // ** Wrappers for setting child properties by name ** -TomY
  116. // LLView
  117. void childSetVisible(const char* name, bool visible);
  118. LL_INLINE void childShow(const char* name) { childSetVisible(name, true); }
  119. LL_INLINE void childHide(const char* name) { childSetVisible(name, false); }
  120. bool childIsVisible(const char* id) const;
  121. void childSetTentative(const char* name, bool tentative);
  122. void childSetEnabled(const char* name, bool enabled);
  123. LL_INLINE void childEnable(const char* name) { childSetEnabled(name, true); }
  124. LL_INLINE void childDisable(const char* name) { childSetEnabled(name, false); }
  125. bool childIsEnabled(const char* id) const;
  126. void childSetToolTip(const char* id, const std::string& msg);
  127. void childSetRect(const char* id, const LLRect& rect);
  128. bool childGetRect(const char* id, LLRect& rect) const;
  129. void childSetFocus(const char* id, bool focus = true);
  130. bool childHasFocus(const char* id);
  131. void childSetFocusChangedCallback(const char* id,
  132. void (*cb)(LLFocusableElement*, void*),
  133. void* user_data = NULL);
  134. void childSetCommitCallback(const char* id,
  135. void (*cb)(LLUICtrl*, void*),
  136. void* userdata = NULL);
  137. void childSetDoubleClickCallback(const char* id, void (*cb)(void*),
  138. void* userdata = NULL);
  139. void childSetValidate(const char* id, bool (*cb)(LLUICtrl*, void*));
  140. void childSetUserData(const char* id, void* userdata);
  141. void childSetColor(const char* id, const LLColor4& color);
  142. void childSetAlpha(const char* id, F32 alpha);
  143. // This is the magic bullet for data-driven UI
  144. void childSetValue(const char* id, LLSD value);
  145. LLSD childGetValue(const char* id) const;
  146. // For setting text / label replacement params, e.g. "Hello [NAME]"
  147. // Not implemented for all types, defaults to noop, return false if not
  148. // applicaple
  149. bool childSetTextArg(const char* id, const std::string& key,
  150. const std::string& text);
  151. bool childSetLabelArg(const char* id, const std::string& key,
  152. const std::string& text);
  153. bool childSetToolTipArg(const char* id, const std::string& key,
  154. const std::string& text);
  155. // LLIconCtrl
  156. enum Badge { BADGE_OK, BADGE_NOTE, BADGE_WARN, BADGE_ERROR };
  157. void childSetBadge(const char* id, Badge b, bool visible = true);
  158. // LLSliderCtrl / LLMultiSlider / LLSpinCtrl
  159. void childSetMinValue(const char* id, LLSD min_value);
  160. void childSetMaxValue(const char* id, LLSD max_value);
  161. // LLTabContainer
  162. void childShowTab(const char* id, const std::string& tabname,
  163. bool visible = true);
  164. LLPanel* childGetVisibleTab(const char* id) const;
  165. void childSetTabChangeCallback(const char* id, const std::string& tabname,
  166. void (*on_tab_clicked)(void*, bool),
  167. void* userdata,
  168. void (*on_precommit)(void*, bool) = NULL);
  169. // LLTextBox
  170. void childSetWrappedText(const char* id, const std::string& text,
  171. bool visible = true);
  172. // LLTextBox/LLTextEditor/LLLineEditor
  173. LL_INLINE void childSetText(const char* id, const std::string& text)
  174. {
  175. childSetValue(id, LLSD(text));
  176. }
  177. LL_INLINE std::string childGetText(const char* id) const
  178. {
  179. return childGetValue(id).asString();
  180. }
  181. // LLLineEditor
  182. void childSetKeystrokeCallback(const char* id,
  183. void (*keystroke_callback)(LLLineEditor*,
  184. void*),
  185. void* user_data);
  186. void childSetPrevalidate(const char* id, bool (*func)(const LLWString&));
  187. // LLButton
  188. void childSetAction(const char* id, void(*function)(void*), void* value);
  189. void childSetActionTextbox(const char* id, void(*function)(void*),
  190. void* value = NULL);
  191. void childSetControlName(const char* id, const char* ctrl_name);
  192. // Error reporting
  193. void childNotFound(const char* id) const;
  194. void childDisplayNotFound();
  195. static LLView* fromXML(LLXMLNodePtr nodep, LLView* parentp,
  196. LLUICtrlFactory* factoryp);
  197. protected:
  198. // Override to set not found list
  199. LL_INLINE LLButton* getDefaultButton() { return mDefaultBtn; }
  200. private:
  201. // Common construction logic
  202. void init();
  203. // From LLView
  204. void addCtrl(LLUICtrl* ctrl, S32 tab_group) override;
  205. void addCtrlAtEnd(LLUICtrl* ctrl, S32 tab_group) override;
  206. protected:
  207. LLCallbackMap::map_t mFactoryMap;
  208. private:
  209. // Unified error reporting for the child* functions
  210. typedef std::set<std::string> expected_members_list_t;
  211. mutable expected_members_list_t mExpectedMembers;
  212. mutable expected_members_list_t mNewExpectedMembers;
  213. std::string mRectControl;
  214. LLColor4 mBgColorAlpha;
  215. LLColor4 mBgColorOpaque;
  216. LLColor4 mDefaultBtnHighlight;
  217. LLViewBorder* mBorder;
  218. LLButton* mDefaultBtn;
  219. std::string mLabel;
  220. typedef std::map<std::string, std::string> ui_string_map_t;
  221. ui_string_map_t mUIStrings;
  222. S32 mLastTabGroup;
  223. bool mBgVisible;
  224. bool mBgOpaque;
  225. };
  226. class LLLayoutStack : public LLView
  227. {
  228. protected:
  229. LOG_CLASS(LLLayoutStack);
  230. public:
  231. typedef enum e_layout_orientation
  232. {
  233. HORIZONTAL,
  234. VERTICAL
  235. } eLayoutOrientation;
  236. LLLayoutStack(eLayoutOrientation orientation);
  237. ~LLLayoutStack() override;
  238. const std::string& getTag() const override;
  239. LLXMLNodePtr getXML(bool save_children = true) const override;
  240. void removeCtrl(LLUICtrl* ctrlp) override;
  241. static LLView* fromXML(LLXMLNodePtr nodep, LLView* parentp,
  242. LLUICtrlFactory* factoryp);
  243. void draw() override;
  244. LL_INLINE S32 getMinWidth() const { return mMinWidth; }
  245. LL_INLINE S32 getMinHeight() const { return mMinHeight; }
  246. typedef enum e_animate
  247. {
  248. NO_ANIMATE,
  249. ANIMATE
  250. } EAnimate;
  251. void addPanel(LLPanel* panelp, S32 min_width, S32 min_height,
  252. bool auto_resize, bool user_resize,
  253. EAnimate animate = NO_ANIMATE, S32 index = S32_MAX);
  254. void removePanel(LLPanel* panelp);
  255. void collapsePanel(LLPanel* panelp, bool collapsed = true);
  256. LL_INLINE S32 getNumPanels() { return mPanels.size(); }
  257. void deleteAllChildren() override;
  258. private:
  259. void updateLayout(bool force_resize = false);
  260. void calcMinExtents();
  261. S32 getDefaultHeight(S32 cur_height);
  262. S32 getDefaultWidth(S32 cur_width);
  263. struct LLEmbeddedPanel;
  264. LLEmbeddedPanel* findEmbeddedPanel(LLPanel* panelp) const;
  265. private:
  266. const eLayoutOrientation mOrientation;
  267. typedef std::vector<LLEmbeddedPanel*> e_panel_list_t;
  268. e_panel_list_t mPanels;
  269. S32 mMinWidth;
  270. S32 mMinHeight;
  271. S32 mPanelSpacing;
  272. };
  273. #endif