lluictrl.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * @file lluictrl.h
  3. * @author James Cook, Richard Nelson, Tom Yedwab
  4. * @brief Abstract base class for UI controls
  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_LLUICTRL_H
  34. #define LL_LLUICTRL_H
  35. #include "llview.h"
  36. class LLUICtrl : public LLView
  37. {
  38. protected:
  39. LOG_CLASS(LLUICtrl);
  40. public:
  41. typedef void (*LLUICtrlCallback)(LLUICtrl* ctrlp, void* userdata);
  42. LLUICtrl();
  43. LLUICtrl(const std::string& name, const LLRect& rect, bool mouse_opaque,
  44. LLUICtrlCallback callback, void* callback_userdata,
  45. U32 reshape = FOLLOWS_NONE);
  46. ~LLUICtrl() override;
  47. // LLView interface
  48. const std::string& getTag() const override;
  49. void initFromXML(LLXMLNodePtr nodep, LLView* parentp) override;
  50. LLXMLNodePtr getXML(bool save_children = true) const override;
  51. LL_INLINE bool setLabelArg(const std::string& key,
  52. const std::string& text) override { return false; }
  53. LL_INLINE bool isCtrl() const override { return true; }
  54. LL_INLINE void setTentative(bool b) override { mTentative = b; }
  55. LL_INLINE bool getTentative() const override { return mTentative; }
  56. bool getIsChrome() const override;
  57. // From LLFocusableElement
  58. LL_INLINE bool isFocusableCtrl() const override { return true; }
  59. void setFocus(bool b) override;
  60. bool hasFocus() const override;
  61. void onFocusReceived() override;
  62. void onFocusLost() override;
  63. // New virtuals
  64. LL_INLINE LLSD getValue() const override { return LLSD(); }
  65. LL_INLINE virtual bool setTextArg(const std::string& key,
  66. const std::string& text) { return false; }
  67. LL_INLINE virtual void setIsChrome(bool b) { mIsChrome = b; }
  68. LL_INLINE virtual bool acceptsTextInput() const { return false; }
  69. // A control is dirty if the user has modified its value. Editable controls
  70. // should override this.
  71. LL_INLINE virtual bool isDirty() const { return false; }
  72. LL_INLINE virtual void resetDirty() {}
  73. virtual void onCommit();
  74. // Called when registered as top ctrl and user clicks elsewhere:
  75. virtual void onLostTop();
  76. // Default to no-op:
  77. LL_INLINE virtual void onTabInto() {}
  78. LL_INLINE virtual void clear() {}
  79. LL_INLINE virtual void setDoubleClickCallback(void (*cb)(void*))
  80. {
  81. }
  82. LL_INLINE virtual void setColor(const LLColor4& color) {}
  83. LL_INLINE virtual void setAlpha(F32 alpha) {}
  84. LL_INLINE virtual void setMinValue(LLSD min_value) {}
  85. LL_INLINE virtual void setMaxValue(LLSD max_value) {}
  86. bool focusNextItem(bool text_entry_only);
  87. bool focusPrevItem(bool text_entry_only);
  88. bool focusFirstItem(bool prefer_text_fields = false,
  89. bool focus_flash = true);
  90. bool focusLastItem(bool prefer_text_fields = false);
  91. LL_INLINE void setTabStop(bool b) { mTabStop = b; }
  92. LL_INLINE bool hasTabStop() const { return mTabStop; }
  93. LLUICtrl* getParentUICtrl() const;
  94. LL_INLINE void* getCallbackUserData() const { return mCallbackUserData; }
  95. LL_INLINE void setCallbackUserData(void* data) { mCallbackUserData = data; }
  96. LL_INLINE void setCommitCallback(void (*cb)(LLUICtrl*, void*)) { mCommitCallback = cb; }
  97. LL_INLINE void setValidateBeforeCommit(bool (*cb)(LLUICtrl*, void*))
  98. {
  99. mValidateCallback = cb;
  100. }
  101. LL_INLINE void setLostTopCallback(void (*cb)(LLUICtrl*, void*)) { mLostTopCallback = cb; }
  102. static LLView* fromXML(LLXMLNodePtr nodep, LLView* parentp,
  103. class LLUICtrlFactory* factoryp);
  104. LLUICtrl* findRootMostFocusRoot();
  105. class LLTextInputFilter : public LLQueryFilter, public LLSingleton<LLTextInputFilter>
  106. {
  107. friend class LLSingleton<LLTextInputFilter>;
  108. filter_result_t operator()(const LLView* const view,
  109. const view_list_t & children) const override
  110. {
  111. return filter_result_t(view->isCtrl() &&
  112. static_cast<const LLUICtrl*>(view)->acceptsTextInput(),
  113. true);
  114. }
  115. };
  116. typedef void (*lua_reg_cmd_fn_t)(LLUICtrl* ctrlp, LLView* parentp,
  117. const std::string& cmd);
  118. LL_INLINE static void setRegisterLuaCommandFunc(lua_reg_cmd_fn_t fn)
  119. {
  120. sRegisterLuaCommand = fn;
  121. }
  122. protected:
  123. LLUICtrlCallback mCommitCallback;
  124. LLUICtrlCallback mLostTopCallback;
  125. typedef bool (*validate_cb_t)(LLUICtrl* ctrlp, void* userdata);
  126. validate_cb_t mValidateCallback;
  127. void* mCallbackUserData;
  128. private:
  129. class DefaultTabGroupFirstSorter;
  130. bool mTabStop;
  131. bool mIsChrome;
  132. bool mTentative;
  133. static lua_reg_cmd_fn_t sRegisterLuaCommand;
  134. };
  135. extern const std::string LL_UI_CRTL_TAG;
  136. #endif // LL_LLUICTRL_H