PageRenderTime 101ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llradiogroup.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 114 lines | 57 code | 21 blank | 36 comment | 0 complexity | 0663d5256740da1189d461894fbd45fe MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llradiogroup.h
  3. * @brief LLRadioGroup base class
  4. *
  5. * $LicenseInfo:firstyear=2001&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 LL_LLRADIOGROUP_H
  27. #define LL_LLRADIOGROUP_H
  28. #include "lluictrl.h"
  29. #include "llcheckboxctrl.h"
  30. #include "llctrlselectioninterface.h"
  31. /*
  32. * An invisible view containing multiple mutually exclusive toggling
  33. * buttons (usually radio buttons). Automatically handles the mutex
  34. * condition by highlighting only one button at a time.
  35. */
  36. class LLRadioGroup
  37. : public LLUICtrl, public LLCtrlSelectionInterface
  38. {
  39. public:
  40. struct ItemParams : public LLInitParam::Block<ItemParams, LLCheckBoxCtrl::Params>
  41. {
  42. Optional<LLSD> value;
  43. ItemParams();
  44. };
  45. struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
  46. {
  47. Optional<bool> allow_deselect;
  48. Multiple<ItemParams, AtLeast<1> > items;
  49. Params();
  50. };
  51. protected:
  52. LLRadioGroup(const Params&);
  53. friend class LLUICtrlFactory;
  54. public:
  55. /*virtual*/ void initFromParams(const Params&);
  56. virtual ~LLRadioGroup();
  57. virtual BOOL postBuild();
  58. virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
  59. virtual BOOL handleKeyHere(KEY key, MASK mask);
  60. void setIndexEnabled(S32 index, BOOL enabled);
  61. // return the index value of the selected item
  62. S32 getSelectedIndex() const { return mSelectedIndex; }
  63. // set the index value programatically
  64. BOOL setSelectedIndex(S32 index, BOOL from_event = FALSE);
  65. // Accept and retrieve strings of the radio group control names
  66. virtual void setValue(const LLSD& value );
  67. virtual LLSD getValue() const;
  68. // Update the control as needed. Userdata must be a pointer to the button.
  69. void onClickButton(LLUICtrl* clicked_radio);
  70. //========================================================================
  71. LLCtrlSelectionInterface* getSelectionInterface() { return (LLCtrlSelectionInterface*)this; };
  72. // LLCtrlSelectionInterface functions
  73. /*virtual*/ S32 getItemCount() const { return mRadioButtons.size(); }
  74. /*virtual*/ BOOL getCanSelect() const { return TRUE; }
  75. /*virtual*/ BOOL selectFirstItem() { return setSelectedIndex(0); }
  76. /*virtual*/ BOOL selectNthItem( S32 index ) { return setSelectedIndex(index); }
  77. /*virtual*/ BOOL selectItemRange( S32 first, S32 last ) { return setSelectedIndex(first); }
  78. /*virtual*/ S32 getFirstSelectedIndex() const { return getSelectedIndex(); }
  79. /*virtual*/ BOOL setCurrentByID( const LLUUID& id );
  80. /*virtual*/ LLUUID getCurrentID() const; // LLUUID::null if no items in menu
  81. /*virtual*/ BOOL setSelectedByValue(const LLSD& value, BOOL selected);
  82. /*virtual*/ LLSD getSelectedValue();
  83. /*virtual*/ BOOL isSelected(const LLSD& value) const;
  84. /*virtual*/ BOOL operateOnSelection(EOperation op);
  85. /*virtual*/ BOOL operateOnAll(EOperation op);
  86. private:
  87. const LLFontGL* mFont;
  88. S32 mSelectedIndex;
  89. typedef std::vector<class LLRadioCtrl*> button_list_t;
  90. button_list_t mRadioButtons;
  91. bool mAllowDeselect; // user can click on an already selected option to deselect it
  92. };
  93. #endif