diff options
author | richard <none@none> | 2009-12-15 14:21:04 -0800 |
---|---|---|
committer | richard <none@none> | 2009-12-15 14:21:04 -0800 |
commit | 699e2e027bf241af6c0dec5a03a51422911b4e0f (patch) | |
tree | 5ea83cb688a362ddb3075b9f6b45d22748f8e558 | |
parent | 6d36fad38a15dcf1e39dab930a1c5ce5c1b7b5c3 (diff) |
added "value" attribute to radio_items to better support arbitrary data selection
moved LLRadioCtrl to internal implementation of LLRadioGroup
reviewed by Leyla
-rw-r--r-- | indra/llui/llradiogroup.cpp | 104 | ||||
-rw-r--r-- | indra/llui/llradiogroup.h | 47 | ||||
-rw-r--r-- | indra/llui/lluictrlfactory.cpp | 9 | ||||
-rw-r--r-- | indra/llui/lluictrlfactory.h | 75 | ||||
-rw-r--r-- | indra/llui/llview.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llfloatertools.h | 1 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/floater_customize.xml | 2 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/floater_settings_debug.xml | 43 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/panel_preferences_chat.xml | 7 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/panel_preferences_general.xml | 3 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml | 4 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/panel_preferences_setup.xml | 38 |
12 files changed, 176 insertions, 159 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) diff --git a/indra/newview/llfloatertools.h b/indra/newview/llfloatertools.h index 05a88a31d3..2ec7ec46af 100644 --- a/indra/newview/llfloatertools.h +++ b/indra/newview/llfloatertools.h @@ -46,7 +46,6 @@ class LLPanelVolume; class LLPanelContents; class LLPanelFace; class LLPanelLandInfo; -class LLRadioCtrl; class LLRadioGroup; class LLSlider; class LLTabContainer; diff --git a/indra/newview/skins/default/xui/en/floater_customize.xml b/indra/newview/skins/default/xui/en/floater_customize.xml index 275ab5bb8b..9d3694873e 100644 --- a/indra/newview/skins/default/xui/en/floater_customize.xml +++ b/indra/newview/skins/default/xui/en/floater_customize.xml @@ -167,6 +167,7 @@ left="1" name="radio" top="1" + value="0" width="82" /> <radio_item height="16" @@ -174,6 +175,7 @@ layout="topleft" left_delta="0" name="radio2" + value="1" top_delta="16" width="82" /> </radio_group> diff --git a/indra/newview/skins/default/xui/en/floater_settings_debug.xml b/indra/newview/skins/default/xui/en/floater_settings_debug.xml index ffb11f3f18..3ed2bd7206 100644 --- a/indra/newview/skins/default/xui/en/floater_settings_debug.xml +++ b/indra/newview/skins/default/xui/en/floater_settings_debug.xml @@ -30,26 +30,29 @@ top_pad="10" width="320" word_wrap="true" /> - <combo_box - follows="top|left" - height="20" - layout="topleft" - left_delta="0" - name="boolean_combo" - top_pad="10" - visible="false" - width="100"> - <combo_box.item - label="TRUE" - name="TRUE" - value="true" /> - <combo_box.item - label="FALSE" - name="FALSE" - value="" /> - <combo_box.commit_callback - function="CommitSettings" /> - </combo_box> + <radio_group + follows="top|left" + height="30" + layout="topleft" + left_delta="0" + name="boolean_combo" + top_pad="10" + visible="false" + tab_stop="true" + width="100"> + <radio_item + top_pad="5" + label="TRUE" + name="TRUE" + value="true" /> + <radio_item + top_pad="5" + label="FALSE" + name="FALSE" + value="" /> + <commit_callback + function="CommitSettings" /> + </radio_group> <line_editor height="20" layout="topleft" diff --git a/indra/newview/skins/default/xui/en/panel_preferences_chat.xml b/indra/newview/skins/default/xui/en/panel_preferences_chat.xml index fff53c1de2..d0e325b04e 100644 --- a/indra/newview/skins/default/xui/en/panel_preferences_chat.xml +++ b/indra/newview/skins/default/xui/en/panel_preferences_chat.xml @@ -16,13 +16,14 @@ control_name="ChatFontSize" name="chat_font_size" top="10" - width="331"> + width="440"> <radio_item height="16" label="Small" layout="topleft" left="0" name="radio" + value="0" top="10" width="125" /> <radio_item @@ -31,6 +32,7 @@ layout="topleft" left_delta="145" name="radio2" + value="1" top_delta="0" width="125" /> <radio_item @@ -39,6 +41,7 @@ layout="topleft" left_delta="170" name="radio3" + value="2" top_delta="0" width="125" /> </radio_group> @@ -340,6 +343,7 @@ layout="topleft" left="0" name="radio" + value="0" top="0" width="150" /> <radio_item @@ -348,6 +352,7 @@ layout="topleft" left_delta="145" name="radio2" + value="1" top_delta="0" width="150" /> </radio_group> diff --git a/indra/newview/skins/default/xui/en/panel_preferences_general.xml b/indra/newview/skins/default/xui/en/panel_preferences_general.xml index b5c6b637e5..3718a65b8c 100644 --- a/indra/newview/skins/default/xui/en/panel_preferences_general.xml +++ b/indra/newview/skins/default/xui/en/panel_preferences_general.xml @@ -217,6 +217,7 @@ layout="topleft" left="0" name="radio" + value="0" top_pad="0" width="98" /> <radio_item @@ -225,6 +226,7 @@ layout="topleft" left_pad="12" name="radio2" + value="1" top_delta="0" width="98" /> <radio_item @@ -233,6 +235,7 @@ layout="topleft" left_pad="12" name="radio3" + value="2" top_delta="0" width="98" /> </radio_group> diff --git a/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml b/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml index 04985d0fa9..f97ccafecc 100644 --- a/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml +++ b/indra/newview/skins/default/xui/en/panel_preferences_graphics1.xml @@ -28,7 +28,7 @@ follows="left|top" height="15" increment="0.025" - initial_valu="1" + initial_value="1" layout="topleft" left_delta="52" max_val="1.4" @@ -656,6 +656,7 @@ layout="topleft" left="3" name="SunMoon" + value="0" top="3" width="156" /> <radio_item @@ -664,6 +665,7 @@ layout="topleft" left_delta="0" name="LocalLights" + value="1" top_delta="16" width="156" /> </radio_group> diff --git a/indra/newview/skins/default/xui/en/panel_preferences_setup.xml b/indra/newview/skins/default/xui/en/panel_preferences_setup.xml index a7def5306e..e06c15502c 100644 --- a/indra/newview/skins/default/xui/en/panel_preferences_setup.xml +++ b/indra/newview/skins/default/xui/en/panel_preferences_setup.xml @@ -268,24 +268,26 @@ name="use_external_browser" top_pad="4" width="480"> - <radio_item - height="20" - label="Use built-in browser" - layout="topleft" - left="0" - name="internal" - tool_tip="Use the built-in web browser for help, web links, etc. This browser opens as a new window inside [APP_NAME]." - top="0" - width="480" /> - <radio_item - height="20" - label="Use my browser (IE, Firefox)" - layout="topleft" - left_delta="0" - name="external" - tool_tip="Use the default system web browser for help, web links, etc. Not recommended if running full screen." - top_delta="20" - width="480" /> + <radio_item + height="20" + label="Use built-in browser" + layout="topleft" + left="0" + name="internal" + value="0" + tool_tip="Use the built-in web browser for help, web links, etc. This browser opens as a new window inside [APP_NAME]." + top="0" + width="480" /> + <radio_item + height="20" + label="Use my browser (IE, Firefox)" + layout="topleft" + left_delta="0" + name="external" + value="1" + tool_tip="Use the default system web browser for help, web links, etc. Not recommended if running full screen." + top_delta="20" + width="480" /> </radio_group> <check_box |