diff options
Diffstat (limited to 'indra/newview/llpanelpicks.cpp')
-rw-r--r-- | indra/newview/llpanelpicks.cpp | 267 |
1 files changed, 76 insertions, 191 deletions
diff --git a/indra/newview/llpanelpicks.cpp b/indra/newview/llpanelpicks.cpp index 973afae73b..c34038c672 100644 --- a/indra/newview/llpanelpicks.cpp +++ b/indra/newview/llpanelpicks.cpp @@ -46,6 +46,7 @@ #include "llpanelprofile.h" #include "llpanelpick.h" #include "llscrollcontainer.h" +#include "lllistctrl.h" static const std::string XML_BTN_NEW = "new_btn"; static const std::string XML_BTN_DELETE = "trash_btn"; @@ -53,9 +54,10 @@ static const std::string XML_BTN_INFO = "info_btn"; static const std::string XML_BTN_TELEPORT = "teleport_btn"; static const std::string XML_BTN_SHOW_ON_MAP = "show_on_map_btn"; -static const std::string XML_PICKS_LIST = "back_panel"; +static const std::string PICK_ID("pick_id"); +static const std::string PICK_CREATOR_ID("pick_creator_id"); +static const std::string PICK_NAME("pick_name"); -#define PICK_ITEMS_BETWEEN 5 static LLRegisterPanelClassWrapper<LLPanelPicks> t_panel_picks("panel_picks"); @@ -65,9 +67,9 @@ static LLRegisterPanelClassWrapper<LLPanelPicks> t_panel_picks("panel_picks"); LLPanelPicks::LLPanelPicks() : LLPanelProfileTab(), mPopupMenu(NULL), - mSelectedPickItem(NULL), mProfilePanel(NULL), - mPickPanel(NULL) + mPickPanel(NULL), + mPicksList(NULL) { } @@ -100,22 +102,8 @@ void LLPanelPicks::processProperties(void* data, EAvatarProcessorType type) gCacheName->getName(getAvatarId(),name,second_name); childSetTextArg("pick_title", "[NAME]",name); - LLView* picks_list = getPicksList(); - - // to restore selection of the same item later - LLUUID pick_id_selected(LLUUID::null); - if (mSelectedPickItem) pick_id_selected = mSelectedPickItem->getPickId(); - - clear(); - - //*TODO move it somewhere else? - picks_list->setEnabled(FALSE); - childSetEnabled(XML_BTN_NEW, false); - childSetEnabled(XML_BTN_DELETE, false); - childSetEnabled(XML_BTN_INFO, false); - childSetEnabled(XML_BTN_TELEPORT,!avatar_picks->picks_list.empty()); - childSetEnabled(XML_BTN_SHOW_ON_MAP,!avatar_picks->picks_list.empty()); - + mPicksList->clear(); + LLAvatarPicks::picks_list_t::const_iterator it = avatar_picks->picks_list.begin(); for(; avatar_picks->picks_list.end() != it; ++it) { @@ -124,109 +112,44 @@ void LLPanelPicks::processProperties(void* data, EAvatarProcessorType type) LLPickItem* picture = LLPickItem::create(); picture->childSetAction("info_chevron", boost::bind(&LLPanelPicks::onClickInfo, this)); - - picks_list->addChild(picture); - picture->setPickName(pick_name); picture->setPickId(pick_id); picture->setCreatorId(getAvatarId()); LLAvatarPropertiesProcessor::instance().addObserver(getAvatarId(), picture); picture->update(); - mPickItemList.push_back(picture); - if (pick_id_selected != LLUUID::null && - pick_id == pick_id_selected) setSelectedPickItem(picture); + + LLSD pick_value = LLSD(); + pick_value.insert(PICK_ID, pick_id); + pick_value.insert(PICK_NAME, pick_name); + pick_value.insert(PICK_CREATOR_ID, getAvatarId()); + + mPicksList->addItem(picture, pick_value); + + picture->setDoubleClickCallback(boost::bind(&LLPanelPicks::onDoubleClickItem, this, _1)); + picture->setRightMouseDownCallback(boost::bind(&LLPanelPicks::onRightMouseDownItem, this, _1, _2, _3, _4)); + picture->setRightMouseUpCallback(boost::bind(&LLPanelPicks::updateButtons, this)); + picture->setMouseUpCallback(boost::bind(&LLPanelPicks::updateButtons, this)); } - reshapePicksList(); LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(),this); - updateButtons(); - if (!mSelectedPickItem && mPickItemList.size()) setSelectedPickItem(mPickItemList.back()); - picks_list->setEnabled(TRUE); - } } } -void LLPanelPicks::clear() -{ - LLView* scroll = getPicksList(); - picture_list_t::const_iterator it = mPickItemList.begin(); - for(; mPickItemList.end() != it; ++it) - { - scroll->removeChild(*it); - delete *it; - } - mPickItemList.clear(); - mSelectedPickItem = NULL; -} - - LLPickItem* LLPanelPicks::getSelectedPickItem() { - return mSelectedPickItem; -} - - -void LLPanelPicks::removePickItem( LLPickItem* pick_item ) -{ - LLView* scroll = getPicksList(); - scroll->removeChild(pick_item); - mPickItemList.remove(pick_item); - if (mPickItemList.size() == 0) - { - mSelectedPickItem = NULL; - } - else - { - setSelectedPickItem(mPickItemList.back()); - } - - reshapePicksList(); -} - -void LLPanelPicks::reshapePicksList() -{ - if (!mPickItemList.size()) return; - LLView* pickList = getPicksList(); - - //We don't need to update size of the 'pick list' before reshaping pick items. Don't need to reshape the pick list - S32 height = mPickItemList.size() * (mPickItemList.front()->getRect().getHeight() + PICK_ITEMS_BETWEEN); - LLRect rc = pickList->getRect(); - rc.setLeftTopAndSize(rc.mLeft, rc.mTop, rc.getWidth(), height); - pickList->setRect(rc); + LLPanel* selected_item = mPicksList->getSelectedItem(); + if (!selected_item) return NULL; - S32 last_bottom = pickList->getRect().getHeight(); - std::list<LLPickItem*>::const_iterator pick_it, pick_first_it = mPickItemList.begin(); - for ( pick_it = pick_first_it; pick_it != mPickItemList.end(); ++pick_it) - { - LLView* const pick = *pick_it; - if(pick_it != pick_first_it) - { - last_bottom -= pick->getRect().getHeight(); - last_bottom -= PICK_ITEMS_BETWEEN; - } - reshapePickItem(pick, last_bottom,pickList->getRect().getWidth()); - } -} - -void LLPanelPicks::reshapePickItem(LLView* const pick_item, const S32 last_bottom, const S32 newWidth) -{ - LLRect rc = pick_item->getRect(); - rc.mBottom = last_bottom - rc.getHeight(); - rc.mTop = last_bottom; - pick_item->setRect(rc); - pick_item->reshape(newWidth, rc.getHeight()); -} - -LLView* LLPanelPicks::getPicksList() const -{ - return getChild<LLView>(XML_PICKS_LIST); + return dynamic_cast<LLPickItem*>(selected_item); } BOOL LLPanelPicks::postBuild() { + mPicksList = getChild<LLListCtrl>("picks_list"); + childSetAction(XML_BTN_DELETE, boost::bind(&LLPanelPicks::onClickDelete, this)); childSetAction("teleport_btn", boost::bind(&LLPanelPicks::onClickTeleport, this)); @@ -270,6 +193,10 @@ void LLPanelPicks::onOpen(const LLSD& key) { childSetVisible("pick_title", !self); childSetVisible("pick_title_agent", self); + + mPopupMenu->setItemVisible("pick_delete", TRUE); + mPopupMenu->setItemVisible("pick_edit", TRUE); + mPopupMenu->setItemVisible("pick_separator", TRUE); } LLPanelProfileTab::onOpen(key); @@ -278,11 +205,11 @@ void LLPanelPicks::onOpen(const LLSD& key) //static void LLPanelPicks::onClickDelete() { - LLPickItem* pick_item = getSelectedPickItem(); - if (!pick_item) return; + LLSD pick_value = mPicksList->getSelectedValue(); + if (pick_value.isUndefined()) return; LLSD args; - args["PICK"] = pick_item->getPickName(); + args["PICK"] = pick_value[PICK_NAME]; LLNotifications::instance().add("DeleteAvatarPick", args, LLSD(), boost::bind(&LLPanelPicks::callbackDelete, this, _1, _2)); } @@ -290,12 +217,12 @@ bool LLPanelPicks::callbackDelete(const LLSD& notification, const LLSD& response { S32 option = LLNotification::getSelectedOption(notification, response); - LLPickItem* pick_item = getSelectedPickItem(); + LLSD pick_value = mPicksList->getSelectedValue(); if (0 == option) { - LLAvatarPropertiesProcessor::instance().sendPickDelete(pick_item->getPickId()); - removePickItem(pick_item); + LLAvatarPropertiesProcessor::instance().sendPickDelete(pick_value[PICK_ID]); + mPicksList->removeItemByValue(pick_value); } updateButtons(); return false; @@ -329,101 +256,45 @@ void LLPanelPicks::onClickMap() } -BOOL LLPanelPicks::handleRightMouseDown(S32 x, S32 y, MASK mask) +void LLPanelPicks::onRightMouseDownItem(LLUICtrl* item, S32 x, S32 y, MASK mask) { - if (isMouseInPick(x, y)) + if (mPopupMenu) { - if (mPopupMenu) - { - mPopupMenu->buildDrawLabels(); - mPopupMenu->updateParent(LLMenuGL::sMenuContainer); - ((LLContextMenu*)mPopupMenu)->show(x, y); - LLMenuGL::showPopup(this, mPopupMenu, x, y); - } - return TRUE; + mPopupMenu->buildDrawLabels(); + mPopupMenu->updateParent(LLMenuGL::sMenuContainer); + ((LLContextMenu*)mPopupMenu)->show(x, y); + LLMenuGL::showPopup(item, mPopupMenu, x, y); } - return LLPanel::handleRightMouseDown(x, y, mask); } -BOOL LLPanelPicks::handleMouseDown( S32 x, S32 y, MASK mask ) +void LLPanelPicks::onDoubleClickItem(LLUICtrl* item) { - isMouseInPick(x, y); - return LLPanel::handleMouseDown(x, y, mask); -} - -BOOL LLPanelPicks::handleDoubleClick(S32 x, S32 y, MASK mask) -{ - if (isMouseInPick(x, y)) - { - LLPickItem* pick_item = getSelectedPickItem(); - if (pick_item) - { - LLSD args; - args["PICK"] = pick_item->getPickName(); - LLNotifications::instance().add("TeleportToPick", args, LLSD(), boost::bind(&LLPanelPicks::callbackTeleport, this, _1, _2)); - } - return TRUE; - } - return LLPanel::handleDoubleClick(x, y, mask); + LLSD pick_value = mPicksList->getSelectedValue(); + if (pick_value.isUndefined()) return; + + LLSD args; + args["PICK"] = pick_value[PICK_NAME]; + LLNotifications::instance().add("TeleportToPick", args, LLSD(), boost::bind(&LLPanelPicks::callbackTeleport, this, _1, _2)); } void LLPanelPicks::updateButtons() { - int picks_num = mPickItemList.size(); - childSetEnabled(XML_BTN_INFO, picks_num > 0); + int picks_num = mPicksList->size(); + bool has_selected = mPicksList->numSelected(); + + childSetEnabled(XML_BTN_INFO, has_selected); if (getAvatarId() == gAgentID) { childSetEnabled(XML_BTN_NEW, picks_num < MAX_AVATAR_PICKS); - childSetEnabled(XML_BTN_DELETE, picks_num > 0); - - //*TODO move somewhere this calls - // we'd better set them up earlier when a panel was being constructed - mPopupMenu->setItemVisible("pick_delete", TRUE); - mPopupMenu->setItemVisible("pick_edit", TRUE); - mPopupMenu->setItemVisible("pick_separator", TRUE); - } - - //*TODO update buttons like Show on Map, Teleport etc. - -} - -void LLPanelPicks::setSelectedPickItem(LLPickItem* item) -{ - if (!item) return; - if (mSelectedPickItem == item) return; - if (mSelectedPickItem && mSelectedPickItem->isBackgroundVisible()) - { - mSelectedPickItem->setBackgroundVisible(FALSE); + childSetEnabled(XML_BTN_DELETE, has_selected); } - item->setBackgroundVisible(TRUE); - mSelectedPickItem = item; -} -BOOL LLPanelPicks::isMouseInPick( S32 x, S32 y ) -{ - S32 x_l = x; - S32 y_l = y; - - if(!getChild<LLUICtrl>("profile_scroll")->getRect().pointInRect(x, y)) - { - return FALSE; - } - - picture_list_t::const_iterator it = mPickItemList.begin(); - for(; mPickItemList.end() != it; ++it) - { - localPointToOtherView(x, y, &x_l, &y_l, (*it)); - if ((*it)->pointInView(x_l, y_l)) - { - setSelectedPickItem(*it); - return TRUE; - } - } - return FALSE; + childSetEnabled(XML_BTN_INFO, has_selected); + childSetEnabled(XML_BTN_TELEPORT, has_selected); + childSetEnabled(XML_BTN_SHOW_ON_MAP, has_selected); } - void LLPanelPicks::setProfilePanel(LLPanelProfile* profile_panel) { mProfilePanel = profile_panel; @@ -449,12 +320,12 @@ void LLPanelPicks::onClickNew() void LLPanelPicks::onClickInfo() { - LLPickItem* pick = getSelectedPickItem(); - if (!pick) return; + LLSD selected_value = mPicksList->getSelectedValue(); + if (selected_value.isUndefined()) return; buildPickPanel(); mPickPanel->reset(); - mPickPanel->init(pick->getCreatorId(), pick->getPickId()); + mPickPanel->init(selected_value[PICK_CREATOR_ID], selected_value[PICK_ID]); getProfilePanel()->togglePanel(mPickPanel); } @@ -466,12 +337,12 @@ void LLPanelPicks::onClickBack() void LLPanelPicks::onClickMenuEdit() { //*TODO, refactor - most of that is similar to onClickInfo - LLPickItem* pick = getSelectedPickItem(); - if (!pick) return; + LLSD selected_value = mPicksList->getSelectedValue(); + if (selected_value.isUndefined()) return; buildPickPanel(); mPickPanel->reset(); - mPickPanel->init(pick->getCreatorId(), pick->getPickId()); + mPickPanel->init(selected_value[PICK_CREATOR_ID], selected_value[PICK_ID]); mPickPanel->setEditMode(TRUE); getProfilePanel()->togglePanel(mPickPanel); } @@ -601,3 +472,17 @@ void LLPanelPicks::onClose() getProfilePanel()->togglePanel(mPickPanel); } } + +BOOL LLPickItem::postBuild() +{ + setMouseEnterCallback(boost::bind(&LLPanelPick::childSetVisible, this, "hovered_icon", true)); + setMouseLeaveCallback(boost::bind(&LLPanelPick::childSetVisible, this, "hovered_icon", false)); + return TRUE; +} + +void LLPickItem::setValue(const LLSD& value) +{ + if (!value.isMap()) return;; + if (!value.has("selected")) return; + childSetVisible("selected_icon", value["selected"]); +} |