summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorrichard <none@none>2009-12-15 14:21:04 -0800
committerrichard <none@none>2009-12-15 14:21:04 -0800
commit699e2e027bf241af6c0dec5a03a51422911b4e0f (patch)
tree5ea83cb688a362ddb3075b9f6b45d22748f8e558 /indra/llui
parent6d36fad38a15dcf1e39dab930a1c5ce5c1b7b5c3 (diff)
added "value" attribute to radio_items to better support arbitrary data selection
moved LLRadioCtrl to internal implementation of LLRadioGroup reviewed by Leyla
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llradiogroup.cpp104
-rw-r--r--indra/llui/llradiogroup.h47
-rw-r--r--indra/llui/lluictrlfactory.cpp9
-rw-r--r--indra/llui/lluictrlfactory.h75
-rw-r--r--indra/llui/llview.cpp2
5 files changed, 119 insertions, 118 deletions
diff --git a/indra/llui/llradiogroup.cpp b/indra/llui/llradiogroup.cpp
index 86bd2f05ce..74e30cd633 100644
--- a/indra/llui/llradiogroup.cpp
+++ b/indra/llui/llradiogroup.cpp
@@ -43,15 +43,43 @@
#include "llui.h"
#include "llfocusmgr.h"
#include "lluictrlfactory.h"
+#include "llsdutil.h"
static LLDefaultChildRegistry::Register<LLRadioGroup> r1("radio_group");
-static RadioGroupRegistry::Register<LLRadioCtrl> register_radio_ctrl("radio_item");
+/*
+ * An invisible view containing multiple mutually exclusive toggling
+ * buttons (usually radio buttons). Automatically handles the mutex
+ * condition by highlighting only one button at a time.
+ */
+class LLRadioCtrl : public LLCheckBoxCtrl
+{
+public:
+ typedef LLRadioGroup::ItemParams Params;
+ /*virtual*/ ~LLRadioCtrl();
+ /*virtual*/ void setValue(const LLSD& value);
+
+ /*virtual*/ BOOL postBuild();
+
+ LLSD getPayload() { return mPayload; }
+ // Ensure label is in an attribute, not the contents
+ static void setupParamsForExport(Params& p, LLView* parent);
+
+protected:
+ LLRadioCtrl(const LLRadioGroup::ItemParams& p);
+ friend class LLUICtrlFactory;
+
+ LLSD mPayload; // stores data that this item represents in the radio group
+};
+static LLWidgetNameRegistry::StaticRegistrar register_radio_item(&typeid(LLRadioGroup::ItemParams), "radio_item");
LLRadioGroup::Params::Params()
-: has_border("draw_border")
+: has_border("draw_border"),
+ items("item")
{
+ addSynonym(items, "radio_item");
+
name = "radio_group";
mouse_opaque = true;
follows.flags = FOLLOWS_LEFT | FOLLOWS_TOP;
@@ -76,6 +104,24 @@ LLRadioGroup::LLRadioGroup(const LLRadioGroup::Params& p)
}
}
+void LLRadioGroup::initFromParams(const Params& p)
+{
+ LLUICtrl::initFromParams(p);
+ for (LLInitParam::ParamIterator<ItemParams>::const_iterator it = p.items().begin();
+ it != p.items().end();
+ ++it)
+ {
+ LLRadioGroup::ItemParams item_params(*it);
+ item_params.font.setIfNotProvided(mFont); // apply radio group font by default
+ item_params.commit_callback.function = boost::bind(&LLRadioGroup::onClickButton, this, _1);
+ item_params.from_xui = p.from_xui;
+
+ LLRadioCtrl* item = LLUICtrlFactory::create<LLRadioCtrl>(item_params, this);
+ mRadioButtons.push_back(item);
+ }
+}
+
+
LLRadioGroup::~LLRadioGroup()
{
}
@@ -141,7 +187,7 @@ void LLRadioGroup::setIndexEnabled(S32 index, BOOL enabled)
BOOL LLRadioGroup::setSelectedIndex(S32 index, BOOL from_event)
{
- if (index < 0 || index >= (S32)mRadioButtons.size())
+ if (index < 0 || (S32)mRadioButtons.size() <= index )
{
return FALSE;
}
@@ -170,7 +216,7 @@ BOOL LLRadioGroup::setSelectedIndex(S32 index, BOOL from_event)
if (!from_event)
{
- setControlValue(getSelectedIndex());
+ setControlValue(getValue());
}
return TRUE;
@@ -235,27 +281,6 @@ BOOL LLRadioGroup::handleKeyHere(KEY key, MASK mask)
return handled;
}
-
-// When adding a child button, we need to ensure that the radio
-// group gets a message when the button is clicked.
-
-/*virtual*/
-bool LLRadioGroup::addChild(LLView* view, S32 tab_group)
-{
- bool res = LLView::addChild(view, tab_group);
- if (res)
- {
- LLRadioCtrl* radio_ctrl = dynamic_cast<LLRadioCtrl*>(view);
- if (radio_ctrl)
- {
- radio_ctrl->setFont(mFont);
- radio_ctrl->setCommitCallback(boost::bind(&LLRadioGroup::onClickButton, this, _1));
- mRadioButtons.push_back(radio_ctrl);
- }
- }
- return res;
-}
-
BOOL LLRadioGroup::handleMouseDown(S32 x, S32 y, MASK mask)
{
// grab focus preemptively, before child button takes mousecapture
@@ -302,13 +327,12 @@ void LLRadioGroup::onClickButton(LLUICtrl* ctrl)
void LLRadioGroup::setValue( const LLSD& value )
{
- std::string value_name = value.asString();
int idx = 0;
for (button_list_t::const_iterator iter = mRadioButtons.begin();
iter != mRadioButtons.end(); ++iter)
{
LLRadioCtrl* radio = *iter;
- if (radio->getName() == value_name)
+ if (llsd_equals(radio->getPayload(), value))
{
setSelectedIndex(idx);
idx = -1;
@@ -325,7 +349,7 @@ void LLRadioGroup::setValue( const LLSD& value )
}
else
{
- llwarns << "LLRadioGroup::setValue: value not found: " << value_name << llendl;
+ llwarns << "LLRadioGroup::setValue: value not found: " << value.asString() << llendl;
}
}
}
@@ -337,7 +361,7 @@ LLSD LLRadioGroup::getValue() const
for (button_list_t::const_iterator iter = mRadioButtons.begin();
iter != mRadioButtons.end(); ++iter)
{
- if (idx == index) return LLSD((*iter)->getName());
+ if (idx == index) return LLSD((*iter)->getPayload());
++idx;
}
return LLSD();
@@ -357,11 +381,10 @@ LLUUID LLRadioGroup::getCurrentID() const
BOOL LLRadioGroup::setSelectedByValue(const LLSD& value, BOOL selected)
{
S32 idx = 0;
- std::string value_string = value.asString();
for (button_list_t::const_iterator iter = mRadioButtons.begin();
iter != mRadioButtons.end(); ++iter)
{
- if((*iter)->getName() == value_string)
+ if(llsd_equals((*iter)->getPayload(), value))
{
setSelectedIndex(idx);
return TRUE;
@@ -380,11 +403,10 @@ LLSD LLRadioGroup::getSelectedValue()
BOOL LLRadioGroup::isSelected(const LLSD& value) const
{
S32 idx = 0;
- std::string value_string = value.asString();
for (button_list_t::const_iterator iter = mRadioButtons.begin();
iter != mRadioButtons.end(); ++iter)
{
- if((*iter)->getName() == value_string)
+ if(llsd_equals((*iter)->getPayload(), value))
{
if (idx == mSelectedIndex)
{
@@ -406,9 +428,21 @@ BOOL LLRadioGroup::operateOnAll(EOperation op)
return FALSE;
}
-LLRadioCtrl::LLRadioCtrl(const LLRadioCtrl::Params& p)
- : LLCheckBoxCtrl(p)
+LLRadioGroup::ItemParams::ItemParams()
+: value("value")
{
+ addSynonym(value, "initial_value");
+}
+
+LLRadioCtrl::LLRadioCtrl(const LLRadioGroup::ItemParams& p)
+: LLCheckBoxCtrl(p),
+ mPayload(p.value)
+{
+ // use name as default "Value" for backwards compatibility
+ if (!p.value.isProvided())
+ {
+ mPayload = p.name();
+ }
}
BOOL LLRadioCtrl::postBuild()
diff --git a/indra/llui/llradiogroup.h b/indra/llui/llradiogroup.h
index 1e9b5115f8..2edfd7c2ca 100644
--- a/indra/llui/llradiogroup.h
+++ b/indra/llui/llradiogroup.h
@@ -37,35 +37,6 @@
#include "llcheckboxctrl.h"
#include "llctrlselectioninterface.h"
-
-/*
- * An invisible view containing multiple mutually exclusive toggling
- * buttons (usually radio buttons). Automatically handles the mutex
- * condition by highlighting only one button at a time.
- */
-class LLRadioCtrl : public LLCheckBoxCtrl
-{
-public:
- struct Params : public LLInitParam::Block<Params, LLCheckBoxCtrl::Params>
- {};
-
- /*virtual*/ ~LLRadioCtrl();
- /*virtual*/ void setValue(const LLSD& value);
-
- /*virtual*/ BOOL postBuild();
-
- // Ensure label is in an attribute, not the contents
- static void setupParamsForExport(Params& p, LLView* parent);
-
-protected:
- LLRadioCtrl(const Params& p);
- friend class LLUICtrlFactory;
-};
-
-
-struct RadioGroupRegistry : public LLChildRegistry<RadioGroupRegistry>
-{};
-
/*
* An invisible view containing multiple mutually exclusive toggling
* buttons (usually radio buttons). Automatically handles the mutex
@@ -76,25 +47,31 @@ class LLRadioGroup
{
public:
+ struct ItemParams : public LLInitParam::Block<ItemParams, LLCheckBoxCtrl::Params>
+ {
+ Optional<LLSD> value;
+ ItemParams();
+ };
+
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
{
- Optional<bool> has_border;
+ Optional<bool> has_border;
+ Multiple<ItemParams, LLInitParam::AtLeast<1> > items;
Params();
};
- // my valid children are stored in this registry
- typedef RadioGroupRegistry child_registry_t;
-
protected:
LLRadioGroup(const Params&);
friend class LLUICtrlFactory;
public:
+
+ /*virtual*/ void initFromParams(const Params&);
+
virtual ~LLRadioGroup();
virtual BOOL postBuild();
- virtual bool addChild(LLView* view, S32 tab_group = 0);
virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
virtual BOOL handleKeyHere(KEY key, MASK mask);
@@ -134,7 +111,7 @@ public:
private:
const LLFontGL* mFont;
S32 mSelectedIndex;
- typedef std::vector<LLRadioCtrl*> button_list_t;
+ typedef std::vector<class LLRadioCtrl*> button_list_t;
button_list_t mRadioButtons;
BOOL mHasBorder;
diff --git a/indra/llui/lluictrlfactory.cpp b/indra/llui/lluictrlfactory.cpp
index 3643bf44f7..6a7879c8c2 100644
--- a/indra/llui/lluictrlfactory.cpp
+++ b/indra/llui/lluictrlfactory.cpp
@@ -393,7 +393,6 @@ BOOL LLUICtrlFactory::getAttributeColor(LLXMLNodePtr node, const std::string& na
//static
void LLUICtrlFactory::setCtrlParent(LLView* view, LLView* parent, S32 tab_group)
{
- if (tab_group < 0) tab_group = parent->getLastTabGroup();
parent->addChild(view, tab_group);
}
@@ -452,10 +451,4 @@ dummy_widget_creator_func_t* LLUICtrlFactory::getDefaultWidgetFunc(const std::ty
const std::string* LLUICtrlFactory::getWidgetTag(const std::type_info* widget_type)
{
return LLWidgetNameRegistry::instance().getValue(widget_type);
-}
-
-// static
-void LLUICtrlFactory::connect(LLView* parent, LLView* child)
-{
- parent->addChild(child);
-}
+} \ No newline at end of file
diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h
index 55d7d745eb..e4bac48fd3 100644
--- a/indra/llui/lluictrlfactory.h
+++ b/indra/llui/lluictrlfactory.h
@@ -180,34 +180,55 @@ public:
void popFactoryFunctions();
template<typename T>
- static T* create(typename T::Params& params, LLView* parent = NULL)
+ static T* createWidget(typename T::Params& params, LLView* parent = NULL)
{
- //#pragma message("Generating LLUICtrlFactory::create")
- params.fillFrom(ParamDefaults<typename T::Params, 0>::instance().get());
- //S32 foo = "test";
+ // Apply layout transformations, usually munging rect
+ T::setupParams(params, parent);
+
+ T* widget = NULL;
if (!params.validateBlock())
{
llwarns << getInstance()->getCurFileName() << ": Invalid parameter block for " << typeid(T).name() << llendl;
+ //return NULL;
}
- T* widget = new T(params);
- widget->initFromParams(params);
+
+ {
+ LLFastTimer timer(FTM_WIDGET_CONSTRUCTION);
+ widget = new T(params);
+ }
+ {
+ LLFastTimer timer(FTM_INIT_FROM_PARAMS);
+ widget->initFromParams(params);
+ }
+
if (parent)
{
- connect(parent, widget);
+ S32 tab_group = params.tab_group.isProvided() ? params.tab_group() : parent->getLastTabGroup();
+ setCtrlParent(widget, parent, tab_group);
}
return widget;
}
- // fix for gcc template instantiation annoyance
- static void connect(LLView* parent, LLView* child);
-
+ template<typename T>
+ static T* create(typename T::Params& params, LLView* parent = NULL)
+ {
+ params.fillFrom(ParamDefaults<typename T::Params, 0>::instance().get());
+
+ T* widget = createWidget<T>(params, parent);
+ if (widget)
+ {
+ widget->postBuild();
+ }
+
+ return widget;
+ }
+
LLView* createFromXML(LLXMLNodePtr node, LLView* parent, const std::string& filename, const widget_registry_t&, LLXMLNodePtr output_node );
template<typename T>
static T* createFromFile(const std::string &filename, LLView *parent, const widget_registry_t& registry, LLXMLNodePtr output_node = NULL)
{
- //#pragma message("Generating LLUICtrlFactory::createFromFile")
T* widget = NULL;
std::string skinned_filename = findSkinnedFilename(filename);
@@ -272,7 +293,6 @@ fail:
{
LLFastTimer timer(FTM_WIDGET_SETUP);
- //#pragma message("Generating LLUICtrlFactory::defaultBuilder")
typename T::Params params(getDefaultParams<T>());
LLXUIParser::instance().readXUI(node, params, LLUICtrlFactory::getInstance()->getCurFileName());
@@ -289,37 +309,16 @@ fail:
output_node, output_params, &default_params);
}
- // Apply layout transformations, usually munging rect
- T::setupParams(params, parent);
-
- if (!params.validateBlock())
- {
- llwarns << getInstance()->getCurFileName() << ": Invalid parameter block for " << typeid(T).name() << llendl;
- }
- T* widget;
- {
- LLFastTimer timer(FTM_WIDGET_CONSTRUCTION);
- widget = new T(params);
- }
- {
- LLFastTimer timer(FTM_INIT_FROM_PARAMS);
- widget->initFromParams(params);
- }
+ params.from_xui = true;
- if (parent)
- {
- S32 tab_group = params.tab_group.isProvided() ? params.tab_group() : -1;
- setCtrlParent(widget, parent, tab_group);
- }
-
- typedef typename T::child_registry_t registry_t;
+ T* widget = createWidget<T>(params, parent);
- createChildren(widget, node, registry_t::instance(), output_node);
+ createChildren(widget, node, typename T::child_registry_t::instance(), output_node);
- if (!widget->postBuild())
+ if (widget && !widget->postBuild())
{
delete widget;
- return NULL;
+ widget = NULL;
}
return widget;
diff --git a/indra/llui/llview.cpp b/indra/llui/llview.cpp
index 8917e4b813..7932b749a8 100644
--- a/indra/llui/llview.cpp
+++ b/indra/llui/llview.cpp
@@ -2494,8 +2494,6 @@ void LLView::setupParams(LLView::Params& p, LLView* parent)
const S32 VPAD = 4;
const S32 MIN_WIDGET_HEIGHT = 10;
- p.from_xui(true);
-
// *NOTE: This will confuse export of floater/panel coordinates unless
// the default is also "topleft". JC
if (p.layout().empty() && parent)