From d89793616e32cace99b5b76e47d51d141b20c7f2 Mon Sep 17 00:00:00 2001 From: Denis Serdjuk Date: Mon, 28 Dec 2009 17:44:54 +0200 Subject: implemented minor task EXT-3454 Code improvements: Replace old-style calback with boost::function in the LLFloaterAvatarPicker --HG-- branch : product-engine --- indra/newview/llfloateravatarpicker.cpp | 108 +++++++++++++------------------- 1 file changed, 45 insertions(+), 63 deletions(-) (limited to 'indra/newview/llfloateravatarpicker.cpp') diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp index 6e3d5499a2..a0b2de85f0 100644 --- a/indra/newview/llfloateravatarpicker.cpp +++ b/indra/newview/llfloateravatarpicker.cpp @@ -51,8 +51,7 @@ #include "lluictrlfactory.h" #include "message.h" -LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(callback_t callback, - void* userdata, +LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(select_callback_t callback, BOOL allow_multiple, BOOL closeOnSelect) { @@ -60,8 +59,7 @@ LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(callback_t callback, LLFloaterAvatarPicker* floater = LLFloaterReg::showTypedInstance("avatar_picker"); - floater->mCallback = callback; - floater->mCallbackUserdata = userdata; + floater->mSelectionCallback = callback; floater->setAllowMultiple(allow_multiple); floater->mNearMeListComplete = FALSE; floater->mCloseOnSelect = closeOnSelect; @@ -82,8 +80,6 @@ LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(callback_t callback, LLFloaterAvatarPicker::LLFloaterAvatarPicker(const LLSD& key) : LLFloater(key), mNumResultsReturned(0), - mCallback(NULL), - mCallbackUserdata(NULL), mNearMeListComplete(FALSE), mCloseOnSelect(FALSE) { @@ -93,29 +89,29 @@ LLFloaterAvatarPicker::LLFloaterAvatarPicker(const LLSD& key) BOOL LLFloaterAvatarPicker::postBuild() { - getChild("Edit")->setKeystrokeCallback(editKeystroke, this); + getChild("Edit")->setKeystrokeCallback( boost::bind(&LLFloaterAvatarPicker::editKeystroke, this, _1, _2),NULL); - childSetAction("Find", onBtnFind, this); + childSetAction("Find", boost::bind(&LLFloaterAvatarPicker::onBtnFind, this)); childDisable("Find"); - childSetAction("Refresh", onBtnRefresh, this); - childSetCommitCallback("near_me_range", onRangeAdjust, this); + childSetAction("Refresh", boost::bind(&LLFloaterAvatarPicker::onBtnRefresh, this)); + getChild("near_me_range")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onRangeAdjust, this)); LLScrollListCtrl* searchresults = getChild("SearchResults"); - searchresults->setDoubleClickCallback(onBtnSelect, this); - childSetCommitCallback("SearchResults", onList, this); + searchresults->setDoubleClickCallback( boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + searchresults->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); childDisable("SearchResults"); LLScrollListCtrl* nearme = getChild("NearMe"); - nearme->setDoubleClickCallback(onBtnSelect, this); - childSetCommitCallback("NearMe", onList, this); + nearme->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + nearme->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); LLScrollListCtrl* friends = getChild("Friends"); - friends->setDoubleClickCallback(onBtnSelect, this); - childSetCommitCallback("Friends", onList, this); + friends->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + getChild("Friends")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); - childSetAction("ok_btn", onBtnSelect, this); + childSetAction("ok_btn", boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); childDisable("ok_btn"); - childSetAction("cancel_btn", onBtnClose, this); + childSetAction("cancel_btn", boost::bind(&LLFloaterAvatarPicker::onBtnClose, this)); childSetFocus("Edit"); @@ -156,10 +152,9 @@ LLFloaterAvatarPicker::~LLFloaterAvatarPicker() gFocusMgr.releaseFocusIfNeeded( this ); } -void LLFloaterAvatarPicker::onBtnFind(void* userdata) +void LLFloaterAvatarPicker::onBtnFind() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if(self) self->find(); + find(); } static void getSelectedAvatarData(const LLScrollListCtrl* from, std::vector& avatar_names, std::vector& avatar_ids) @@ -176,34 +171,33 @@ static void getSelectedAvatarData(const LLScrollListCtrl* from, std::vectorisSelectBtnEnabled()) + if (!isSelectBtnEnabled()) return; - if(self->mCallback) + if(mSelectionCallback) { std::string acvtive_panel_name; LLScrollListCtrl* list = NULL; - LLPanel* active_panel = self->childGetVisibleTab("ResidentChooserTabs"); + LLPanel* active_panel = childGetVisibleTab("ResidentChooserTabs"); if(active_panel) { acvtive_panel_name = active_panel->getName(); } if(acvtive_panel_name == "SearchPanel") { - list = self->getChild("SearchResults"); + list = getChild("SearchResults"); } else if(acvtive_panel_name == "NearMePanel") { - list =self->getChild("NearMe"); + list = getChild("NearMe"); } else if (acvtive_panel_name == "FriendsPanel") { - list =self->getChild("Friends"); + list = getChild("Friends"); } if(list) @@ -211,50 +205,39 @@ void LLFloaterAvatarPicker::onBtnSelect(void* userdata) std::vector avatar_names; std::vector avatar_ids; getSelectedAvatarData(list, avatar_names, avatar_ids); - self->mCallback(avatar_names, avatar_ids, self->mCallbackUserdata); + mSelectionCallback(avatar_names, avatar_ids); } } - self->getChild("SearchResults")->deselectAllItems(TRUE); - self->getChild("NearMe")->deselectAllItems(TRUE); - self->getChild("Friends")->deselectAllItems(TRUE); - if(self->mCloseOnSelect) + getChild("SearchResults")->deselectAllItems(TRUE); + getChild("NearMe")->deselectAllItems(TRUE); + getChild("Friends")->deselectAllItems(TRUE); + if(mCloseOnSelect) { - self->mCloseOnSelect = FALSE; - self->closeFloater(); + mCloseOnSelect = FALSE; + closeFloater(); } } -void LLFloaterAvatarPicker::onBtnRefresh(void* userdata) +void LLFloaterAvatarPicker::onBtnRefresh() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if (!self) - { - return; - } - - self->getChild("NearMe")->deleteAllItems(); - self->getChild("NearMe")->setCommentText(self->getString("searching")); - self->mNearMeListComplete = FALSE; + getChild("NearMe")->deleteAllItems(); + getChild("NearMe")->setCommentText(getString("searching")); + mNearMeListComplete = FALSE; } -void LLFloaterAvatarPicker::onBtnClose(void* userdata) +void LLFloaterAvatarPicker::onBtnClose() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if(self) self->closeFloater(); + closeFloater(); } -void LLFloaterAvatarPicker::onRangeAdjust(LLUICtrl* source, void* data) +void LLFloaterAvatarPicker::onRangeAdjust() { - LLFloaterAvatarPicker::onBtnRefresh(data); + onBtnRefresh(); } -void LLFloaterAvatarPicker::onList(LLUICtrl* ctrl, void* userdata) +void LLFloaterAvatarPicker::onList() { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)userdata; - if (self) - { - self->childSetEnabled("ok_btn", self->isSelectBtnEnabled()); - } + childSetEnabled("ok_btn", isSelectBtnEnabled()); } void LLFloaterAvatarPicker::populateNearMe() @@ -297,7 +280,7 @@ void LLFloaterAvatarPicker::populateNearMe() childEnable("NearMe"); childEnable("ok_btn"); near_me_scroller->selectFirstItem(); - onList(near_me_scroller, this); + onList(); near_me_scroller->setFocus(TRUE); } @@ -451,7 +434,7 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void* { floater->childEnable("ok_btn"); search_results->selectFirstItem(); - floater->onList(search_results, floater); + floater->onList(); search_results->setFocus(TRUE); } } @@ -459,8 +442,7 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void* //static void LLFloaterAvatarPicker::editKeystroke(LLLineEditor* caller, void* user_data) { - LLFloaterAvatarPicker* self = (LLFloaterAvatarPicker*)user_data; - self->childSetEnabled("Find", caller->getText().size() >= 3); + childSetEnabled("Find", caller->getText().size() >= 3); } // virtual @@ -470,11 +452,11 @@ BOOL LLFloaterAvatarPicker::handleKeyHere(KEY key, MASK mask) { if (childHasFocus("Edit")) { - onBtnFind(this); + onBtnFind(); } else { - onBtnSelect(this); + onBtnSelect(); } return TRUE; } -- cgit v1.2.3