llcheckboxctrl.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @file llcheckboxctrl.h
  3. * @brief LLCheckBoxCtrl base 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. #ifndef LL_LLCHECKBOXCTRL_H
  33. #define LL_LLCHECKBOXCTRL_H
  34. #include "stdtypes.h"
  35. #include "llbutton.h"
  36. #include "llrect.h"
  37. #include "lluictrl.h"
  38. #include "llcolor4.h"
  39. class LLFontGL;
  40. class LLTextBox;
  41. class LLViewBorder;
  42. // Constants
  43. constexpr S32 LLCHECKBOXCTRL_BTN_SIZE = 13;
  44. constexpr S32 LLCHECKBOXCTRL_VPAD = 2;
  45. constexpr S32 LLCHECKBOXCTRL_HPAD = 2;
  46. constexpr S32 LLCHECKBOXCTRL_SPACING = 5;
  47. constexpr S32 LLCHECKBOXCTRL_HEIGHT = 16;
  48. constexpr bool RADIO_STYLE = true;
  49. constexpr bool CHECK_STYLE = false;
  50. class LLCheckBoxCtrl : public LLUICtrl
  51. {
  52. public:
  53. LLCheckBoxCtrl(const std::string& name, const LLRect& rect,
  54. const std::string& label, const LLFontGL* font = NULL,
  55. void (*commit_callback)(LLUICtrl*, void*) = NULL,
  56. void* callback_userdata = NULL, bool initial_value = false,
  57. // If true, draw radio button style icons
  58. bool use_radio_style = false,
  59. const char* control_name = NULL);
  60. ~LLCheckBoxCtrl() override = default;
  61. // LLView interface
  62. const std::string& getTag() const override;
  63. LLXMLNodePtr getXML(bool save_children = true) const override;
  64. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  65. LLUICtrlFactory* factory);
  66. void setEnabled(bool b) override;
  67. void draw() override;
  68. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  69. void setControlName(const char* ctrl_name, LLView* context) override;
  70. const std::string& getControlName() const override;
  71. // LLUICtrl interface
  72. void setValue(const LLSD& value) override;
  73. LLSD getValue() const override;
  74. // Shortcuts to the above
  75. LL_INLINE bool get() { return getValue().asBoolean(); }
  76. LL_INLINE void set(bool value) { setValue(LLSD(value)); }
  77. LL_INLINE void setTentative(bool b) override { mButton->setTentative(b); }
  78. LL_INLINE bool getTentative() const override { return mButton->getTentative(); }
  79. bool setLabelArg(const std::string& key, const std::string& text) override;
  80. void clear() override;
  81. void onCommit() override;
  82. // Returns true if the user has modified this control
  83. bool isDirty() const override;
  84. // Clears dirty state
  85. void resetDirty() override;
  86. // LLCheckBoxCtrl interface
  87. // Returns the new state
  88. LL_INLINE virtual bool toggle() { return mButton->toggleState(); }
  89. LL_INLINE void setEnabledColor(const LLColor4& c) { mTextEnabledColor = c; }
  90. LL_INLINE void setDisabledColor(const LLColor4& c) { mTextDisabledColor = c; }
  91. void setLabel(const std::string& label);
  92. std::string getLabel() const;
  93. static void onButtonPress(void* userdata);
  94. protected:
  95. // Note: value is stored in toggle state of button
  96. LLButton* mButton;
  97. LLTextBox* mLabel;
  98. LLViewBorder* mBorder;
  99. const LLFontGL* mFont;
  100. LLColor4 mTextEnabledColor;
  101. LLColor4 mTextDisabledColor;
  102. bool mRadioStyle;
  103. bool mInitialValue; // Value set in constructor
  104. bool mSetValue; // Value set programmatically
  105. };
  106. #endif // LL_LLCHECKBOXCTRL_H