PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 9ms RepoModel.GetById 1ms 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
  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
 27#ifndef LL_LLRADIOGROUP_H
 28#define LL_LLRADIOGROUP_H
 29
 30#include "lluictrl.h"
 31#include "llcheckboxctrl.h"
 32#include "llctrlselectioninterface.h"
 33
 34/*
 35 * An invisible view containing multiple mutually exclusive toggling 
 36 * buttons (usually radio buttons).  Automatically handles the mutex
 37 * condition by highlighting only one button at a time.
 38 */
 39class LLRadioGroup
 40:	public LLUICtrl, public LLCtrlSelectionInterface
 41{
 42public:
 43
 44	struct ItemParams : public LLInitParam::Block<ItemParams, LLCheckBoxCtrl::Params>
 45	{
 46		Optional<LLSD>	value;
 47		ItemParams();
 48	};
 49
 50	struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
 51	{
 52		Optional<bool>						allow_deselect;
 53		Multiple<ItemParams, AtLeast<1> >	items;
 54		Params();
 55	};
 56
 57protected:
 58	LLRadioGroup(const Params&);
 59	friend class LLUICtrlFactory;
 60
 61public:
 62
 63	/*virtual*/ void initFromParams(const Params&);
 64
 65	virtual ~LLRadioGroup();
 66	
 67	virtual BOOL postBuild();
 68	
 69	virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
 70	
 71	virtual BOOL handleKeyHere(KEY key, MASK mask);
 72
 73	void setIndexEnabled(S32 index, BOOL enabled);
 74	// return the index value of the selected item
 75	S32 getSelectedIndex() const { return mSelectedIndex; }
 76	// set the index value programatically
 77	BOOL setSelectedIndex(S32 index, BOOL from_event = FALSE);
 78
 79	// Accept and retrieve strings of the radio group control names
 80	virtual void	setValue(const LLSD& value );
 81	virtual LLSD	getValue() const;
 82
 83	// Update the control as needed.  Userdata must be a pointer to the button.
 84	void onClickButton(LLUICtrl* clicked_radio);
 85	
 86	//========================================================================
 87	LLCtrlSelectionInterface* getSelectionInterface()	{ return (LLCtrlSelectionInterface*)this; };
 88
 89	// LLCtrlSelectionInterface functions
 90	/*virtual*/ S32		getItemCount() const  				{ return mRadioButtons.size(); }
 91	/*virtual*/ BOOL	getCanSelect() const				{ return TRUE; }
 92	/*virtual*/ BOOL	selectFirstItem()					{ return setSelectedIndex(0); }
 93	/*virtual*/ BOOL	selectNthItem( S32 index )			{ return setSelectedIndex(index); }
 94	/*virtual*/ BOOL	selectItemRange( S32 first, S32 last ) { return setSelectedIndex(first); }
 95	/*virtual*/ S32		getFirstSelectedIndex() const		{ return getSelectedIndex(); }
 96	/*virtual*/ BOOL	setCurrentByID( const LLUUID& id );
 97	/*virtual*/ LLUUID	getCurrentID() const;				// LLUUID::null if no items in menu
 98	/*virtual*/ BOOL	setSelectedByValue(const LLSD& value, BOOL selected);
 99	/*virtual*/ LLSD	getSelectedValue();
100	/*virtual*/ BOOL	isSelected(const LLSD& value) const;
101	/*virtual*/ BOOL	operateOnSelection(EOperation op);
102	/*virtual*/ BOOL	operateOnAll(EOperation op);
103
104private:
105	const LLFontGL*		mFont;
106	S32					mSelectedIndex;
107
108	typedef std::vector<class LLRadioCtrl*> button_list_t;
109	button_list_t		mRadioButtons;
110
111	bool				mAllowDeselect;	// user can click on an already selected option to deselect it
112};
113
114#endif