diff options
Diffstat (limited to 'indra/newview/lllocationinputctrl.cpp')
-rw-r--r-- | indra/newview/lllocationinputctrl.cpp | 251 |
1 files changed, 203 insertions, 48 deletions
diff --git a/indra/newview/lllocationinputctrl.cpp b/indra/newview/lllocationinputctrl.cpp index 1b7ad6ab7e..53a11eff04 100644 --- a/indra/newview/lllocationinputctrl.cpp +++ b/indra/newview/lllocationinputctrl.cpp @@ -38,6 +38,7 @@ // common includes #include "llbutton.h" #include "llfocusmgr.h" +#include "llhelp.h" #include "llmenugl.h" #include "llparcel.h" #include "llstring.h" @@ -52,7 +53,6 @@ #include "llinventoryobserver.h" #include "lllandmarkactions.h" #include "lllandmarklist.h" -#include "lllocationhistory.h" #include "llteleporthistory.h" #include "llsidetray.h" #include "llslurl.h" @@ -109,7 +109,7 @@ public: private: /*virtual*/ void done() { - std::vector<LLUUID>::const_iterator it = mAdded.begin(), end = mAdded.end(); + uuid_vec_t::const_iterator it = mAdded.begin(), end = mAdded.end(); for(; it != end; ++it) { LLInventoryItem* item = gInventory.getItem(*it); @@ -176,7 +176,10 @@ private: static LLDefaultChildRegistry::Register<LLLocationInputCtrl> r("location_input"); LLLocationInputCtrl::Params::Params() -: add_landmark_image_enabled("add_landmark_image_enabled"), +: icon_maturity_general("icon_maturity_general"), + icon_maturity_adult("icon_maturity_adult"), + icon_maturity_moderate("icon_maturity_moderate"), + add_landmark_image_enabled("add_landmark_image_enabled"), add_landmark_image_disabled("add_landmark_image_disabled"), add_landmark_image_hover("add_landmark_image_hover"), add_landmark_image_selected("add_landmark_image_selected"), @@ -185,13 +188,15 @@ LLLocationInputCtrl::Params::Params() add_landmark_button("add_landmark_button"), for_sale_button("for_sale_button"), info_button("info_button"), + maturity_button("maturity_button"), voice_icon("voice_icon"), fly_icon("fly_icon"), push_icon("push_icon"), build_icon("build_icon"), scripts_icon("scripts_icon"), damage_icon("damage_icon"), - damage_text("damage_text") + damage_text("damage_text"), + maturity_help_topic("maturity_help_topic") { } @@ -204,7 +209,11 @@ LLLocationInputCtrl::LLLocationInputCtrl(const LLLocationInputCtrl::Params& p) mForSaleBtn(NULL), mInfoBtn(NULL), mLandmarkImageOn(NULL), - mLandmarkImageOff(NULL) + mLandmarkImageOff(NULL), + mIconMaturityGeneral(NULL), + mIconMaturityAdult(NULL), + mIconMaturityModerate(NULL), + mMaturityHelpTopic(p.maturity_help_topic) { // Lets replace default LLLineEditor with LLLocationLineEditor // to make needed escaping while copying and cutting url @@ -223,7 +232,6 @@ LLLocationInputCtrl::LLLocationInputCtrl(const LLLocationInputCtrl::Params& p) params.default_text(LLStringUtil::null); params.max_length_bytes(p.max_chars); params.keystroke_callback(boost::bind(&LLComboBox::onTextEntry, this, _1)); - params.handle_edit_keys_directly(true); params.commit_on_focus_lost(false); params.follows.flags(FOLLOWS_ALL); mTextEntry = LLUICtrlFactory::create<LLURLLineEditor>(params); @@ -264,7 +272,25 @@ LLLocationInputCtrl::LLLocationInputCtrl(const LLLocationInputCtrl::Params& p) mAddLandmarkBtn = LLUICtrlFactory::create<LLButton>(al_params); enableAddLandmarkButton(true); addChild(mAddLandmarkBtn); - + + if (p.icon_maturity_general()) + { + mIconMaturityGeneral = p.icon_maturity_general; + } + if (p.icon_maturity_adult()) + { + mIconMaturityAdult = p.icon_maturity_adult; + } + if(p.icon_maturity_moderate()) + { + mIconMaturityModerate = p.icon_maturity_moderate; + } + + LLButton::Params maturity_button = p.maturity_button; + mMaturityButton = LLUICtrlFactory::create<LLButton>(maturity_button); + addChild(mMaturityButton); + mMaturityButton->setClickedCallback(boost::bind(&LLLocationInputCtrl::onMaturityButtonClicked, this)); + LLButton::Params for_sale_button = p.for_sale_button; for_sale_button.tool_tip = LLTrans::getString("LocationCtrlForSaleTooltip"); for_sale_button.click_callback.function( @@ -340,14 +366,29 @@ LLLocationInputCtrl::LLLocationInputCtrl(const LLLocationInputCtrl::Params& p) getTextEntry()->setRightMouseUpCallback(boost::bind(&LLLocationInputCtrl::onTextEditorRightClicked,this,_2,_3,_4)); updateWidgetlayout(); + // Connecting signal for updating location on "Show Coordinates" setting change. + LLControlVariable* coordinates_control = gSavedSettings.getControl("NavBarShowCoordinates").get(); + if (coordinates_control) + { + mCoordinatesControlConnection = coordinates_control->getSignal()->connect(boost::bind(&LLLocationInputCtrl::refreshLocation, this)); + } + + // Connecting signal for updating parcel icons on "Show Parcel Properties" setting change. + LLControlVariable* parcel_properties_control = gSavedSettings.getControl("NavBarShowParcelProperties").get(); + if (parcel_properties_control) + { + mParcelPropertiesControlConnection = parcel_properties_control->getSignal()->connect(boost::bind(&LLLocationInputCtrl::refreshParcelIcons, this)); + } + // - Make the "Add landmark" button updated when either current parcel gets changed // or a landmark gets created or removed from the inventory. // - Update the location string on parcel change. mParcelMgrConnection = LLViewerParcelMgr::getInstance()->addAgentParcelChangedCallback( boost::bind(&LLLocationInputCtrl::onAgentParcelChange, this)); - - mLocationHistoryConnection = LLLocationHistory::getInstance()->setLoadedCallback( - boost::bind(&LLLocationInputCtrl::onLocationHistoryLoaded, this)); + // LLLocationHistory instance is being created before the location input control, so we have to update initial state of button manually. + mButton->setEnabled(LLLocationHistory::instance().getItemCount() > 0); + mLocationHistoryConnection = LLLocationHistory::getInstance()->setChangedCallback( + boost::bind(&LLLocationInputCtrl::onLocationHistoryChanged, this,_1)); mRemoveLandmarkObserver = new LLRemoveLandmarkObserver(this); mAddLandmarkObserver = new LLAddLandmarkObserver(this); @@ -359,8 +400,8 @@ LLLocationInputCtrl::LLLocationInputCtrl(const LLLocationInputCtrl::Params& p) mAddLandmarkTooltip = LLTrans::getString("LocationCtrlAddLandmarkTooltip"); mEditLandmarkTooltip = LLTrans::getString("LocationCtrlEditLandmarkTooltip"); - getChild<LLView>("Location History")->setToolTip(LLTrans::getString("LocationCtrlComboBtnTooltip")); - getChild<LLView>("Place Information")->setToolTip(LLTrans::getString("LocationCtrlInfoBtnTooltip")); + mButton->setToolTip(LLTrans::getString("LocationCtrlComboBtnTooltip")); + mInfoBtn->setToolTip(LLTrans::getString("LocationCtrlInfoBtnTooltip")); } LLLocationInputCtrl::~LLLocationInputCtrl() @@ -373,6 +414,8 @@ LLLocationInputCtrl::~LLLocationInputCtrl() LLViewerParcelMgr::getInstance()->removeObserver(mParcelChangeObserver); delete mParcelChangeObserver; + mCoordinatesControlConnection.disconnect(); + mParcelPropertiesControlConnection.disconnect(); mParcelMgrConnection.disconnect(); mLocationHistoryConnection.disconnect(); } @@ -439,6 +482,7 @@ BOOL LLLocationInputCtrl::handleKeyHere(KEY key, MASK mask) void LLLocationInputCtrl::onTextEntry(LLLineEditor* line_editor) { KEY key = gKeyboard->currentKey(); + MASK mask = gKeyboard->currentMask(TRUE); if (line_editor->getText().empty()) { @@ -446,7 +490,7 @@ void LLLocationInputCtrl::onTextEntry(LLLineEditor* line_editor) hideList(); } // Typing? (moving cursor should not affect showing the list) - else if (key != KEY_LEFT && key != KEY_RIGHT && key != KEY_HOME && key != KEY_END) + else if (mask != MASK_CONTROL && key != KEY_LEFT && key != KEY_RIGHT && key != KEY_HOME && key != KEY_END) { prearrangeList(line_editor->getText()); if (mList->getItemCount() != 0) @@ -471,7 +515,10 @@ void LLLocationInputCtrl::onTextEntry(LLLineEditor* line_editor) */ void LLLocationInputCtrl::setText(const LLStringExplicit& text) { - mTextEntry->setText(text); + if (mTextEntry) + { + mTextEntry->setText(text); + } mHasAutocompletedText = FALSE; } @@ -480,7 +527,9 @@ void LLLocationInputCtrl::setFocus(BOOL b) LLComboBox::setFocus(b); if (mTextEntry && b && !mList->getVisible()) + { mTextEntry->setFocus(TRUE); + } } void LLLocationInputCtrl::handleLoginComplete() @@ -522,6 +571,25 @@ void LLLocationInputCtrl::draw() LLComboBox::draw(); } +void LLLocationInputCtrl::reshape(S32 width, S32 height, BOOL called_from_parent) +{ + LLComboBox::reshape(width, height, called_from_parent); + + // Setting cursor to 0 to show the left edge of the text. See EXT-4967. + mTextEntry->setCursor(0); + if (mTextEntry->hasSelection()) + { + // Deselecting because selection position is changed together with + // cursor position change. + mTextEntry->deselect(); + } + + if (isHumanReadableLocationVisible) + { + refreshMaturityButton(); + } +} + void LLLocationInputCtrl::onInfoButtonClicked() { LLSideTray::getInstance()->showPanel("panel_places", LLSD().with("type", "agent")); @@ -555,15 +623,24 @@ void LLLocationInputCtrl::onAgentParcelChange() refresh(); } +void LLLocationInputCtrl::onMaturityButtonClicked() +{ + LLUI::sHelpImpl->showTopic(mMaturityHelpTopic); +} + void LLLocationInputCtrl::onLandmarkLoaded(LLLandmark* lm) { (void) lm; updateAddLandmarkButton(); } -void LLLocationInputCtrl::onLocationHistoryLoaded() +void LLLocationInputCtrl::onLocationHistoryChanged(LLLocationHistory::EChangeType event) { - rebuildLocationHistory(); + if(event == LLLocationHistory::LOAD) + { + rebuildLocationHistory(); + } + mButton->setEnabled(LLLocationHistory::instance().getItemCount() > 0); } void LLLocationInputCtrl::onLocationPrearrange(const LLSD& data) @@ -607,8 +684,7 @@ void LLLocationInputCtrl::onLocationPrearrange(const LLSD& data) value["global_pos"] = result->mGlobalPos.getValue(); std::string region_name = result->mTitle.substr(0, result->mTitle.find(',')); //TODO*: add Surl to teleportitem or parse region name from title - value["tooltip"] = LLSLURL::buildSLURLfromPosGlobal(region_name, - result->mGlobalPos, false); + value["tooltip"] = LLSLURL(region_name, result->mGlobalPos).getSLURLString(); add(result->getTitle(), value); } result = std::find_if(result + 1, th_items.end(), boost::bind( @@ -651,8 +727,8 @@ void LLLocationInputCtrl::refreshLocation() { // Is one of our children focused? if (LLUICtrl::hasFocus() || mButton->hasFocus() || mList->hasFocus() || - (mTextEntry && mTextEntry->hasFocus()) || (mAddLandmarkBtn->hasFocus())) - + (mTextEntry && mTextEntry->hasFocus()) || + (mAddLandmarkBtn->hasFocus())) { llwarns << "Location input should not be refreshed when having focus" << llendl; return; @@ -672,6 +748,9 @@ void LLLocationInputCtrl::refreshLocation() // store human-readable location to compare it in changeLocationPresentation() mHumanReadableLocation = location_name; setText(location_name); + isHumanReadableLocationVisible = true; + + refreshMaturityButton(); } // returns new right edge @@ -692,17 +771,20 @@ void LLLocationInputCtrl::refreshParcelIcons() { // Our "cursor" moving right to left S32 x = mAddLandmarkBtn->getRect().mLeft; - - static LLUICachedControl<bool> show_properties("NavBarShowParcelProperties", false); - if (show_properties) - { - LLViewerParcelMgr* vpm = LLViewerParcelMgr::getInstance(); - LLViewerRegion* agent_region = gAgent.getRegion(); - LLParcel* agent_parcel = vpm->getAgentParcel(); - if (!agent_region || !agent_parcel) - return; + LLViewerParcelMgr* vpm = LLViewerParcelMgr::getInstance(); + LLViewerRegion* agent_region = gAgent.getRegion(); + LLParcel* agent_parcel = vpm->getAgentParcel(); + if (!agent_region || !agent_parcel) + return; + + mForSaleBtn->setVisible(vpm->canAgentBuyParcel(agent_parcel, false)); + + x = layout_widget(mForSaleBtn, x); + + if (gSavedSettings.getBOOL("NavBarShowParcelProperties")) + { LLParcel* current_parcel; LLViewerRegion* selection_region = vpm->getSelectionRegion(); LLParcel* selected_parcel = vpm->getParcelSelection()->getParcel(); @@ -722,7 +804,6 @@ void LLLocationInputCtrl::refreshParcelIcons() current_parcel = agent_parcel; } - bool allow_buy = vpm->canAgentBuyParcel(current_parcel, false); bool allow_voice = vpm->allowAgentVoice(agent_region, current_parcel); bool allow_fly = vpm->allowAgentFly(agent_region, current_parcel); bool allow_push = vpm->allowAgentPush(agent_region, current_parcel); @@ -731,7 +812,6 @@ void LLLocationInputCtrl::refreshParcelIcons() bool allow_damage = vpm->allowAgentDamage(agent_region, current_parcel); // Most icons are "block this ability" - mForSaleBtn->setVisible(allow_buy); mParcelIcon[VOICE_ICON]->setVisible( !allow_voice ); mParcelIcon[FLY_ICON]->setVisible( !allow_fly ); mParcelIcon[PUSH_ICON]->setVisible( !allow_push ); @@ -739,11 +819,10 @@ void LLLocationInputCtrl::refreshParcelIcons() mParcelIcon[SCRIPTS_ICON]->setVisible( !allow_scripts ); mParcelIcon[DAMAGE_ICON]->setVisible( allow_damage ); mDamageText->setVisible(allow_damage); - - x = layout_widget(mForSaleBtn, x); + // Padding goes to left of both landmark star and for sale btn x -= mAddLandmarkHPad; - + // Slide the parcel icons rect from right to left, adjusting rectangles for (S32 i = 0; i < ICON_COUNT; ++i) { @@ -755,18 +834,20 @@ void LLLocationInputCtrl::refreshParcelIcons() } else { - mForSaleBtn->setVisible(false); for (S32 i = 0; i < ICON_COUNT; ++i) { mParcelIcon[i]->setVisible(false); } mDamageText->setVisible(false); } - - S32 left_pad, right_pad; - mTextEntry->getTextPadding(&left_pad, &right_pad); - right_pad = mTextEntry->getRect().mRight - x; - mTextEntry->setTextPadding(left_pad, right_pad); + + if (mTextEntry) + { + S32 left_pad, right_pad; + mTextEntry->getTextPadding(&left_pad, &right_pad); + right_pad = mTextEntry->getRect().mRight - x; + mTextEntry->setTextPadding(left_pad, right_pad); + } } void LLLocationInputCtrl::refreshHealth() @@ -785,7 +866,73 @@ void LLLocationInputCtrl::refreshHealth() } } -void LLLocationInputCtrl::rebuildLocationHistory(std::string filter) +void LLLocationInputCtrl::refreshMaturityButton() +{ + // Updating maturity rating icon. + LLViewerRegion* region = gAgent.getRegion(); + if (!region) + return; + + bool button_visible = true; + LLPointer<LLUIImage> rating_image = NULL; + std::string rating_tooltip; + + U8 sim_access = region->getSimAccess(); + switch(sim_access) + { + case SIM_ACCESS_PG: + rating_image = mIconMaturityGeneral; + rating_tooltip = LLTrans::getString("LocationCtrlGeneralIconTooltip"); + break; + + case SIM_ACCESS_ADULT: + rating_image = mIconMaturityAdult; + rating_tooltip = LLTrans::getString("LocationCtrlAdultIconTooltip"); + break; + + case SIM_ACCESS_MATURE: + rating_image = mIconMaturityModerate; + rating_tooltip = LLTrans::getString("LocationCtrlModerateIconTooltip"); + break; + + default: + button_visible = false; + break; + } + + mMaturityButton->setVisible(button_visible); + mMaturityButton->setToolTip(rating_tooltip); + if(rating_image) + { + mMaturityButton->setImageUnselected(rating_image); + mMaturityButton->setImagePressed(rating_image); + } + if (mMaturityButton->getVisible()) + { + positionMaturityButton(); + } +} + +void LLLocationInputCtrl::positionMaturityButton() +{ + const LLFontGL* font = mTextEntry->getFont(); + if (!font) + return; + + S32 left_pad, right_pad; + mTextEntry->getTextPadding(&left_pad, &right_pad); + + // Calculate the right edge of rendered text + a whitespace. + left_pad = left_pad + font->getWidth(mTextEntry->getText()) + font->getWidth(" "); + + LLRect rect = mMaturityButton->getRect(); + mMaturityButton->setRect(rect.setOriginAndSize(left_pad, rect.mBottom, rect.getWidth(), rect.getHeight())); + + // Hide icon if it text area is not width enough to display it, show otherwise. + mMaturityButton->setVisible(rect.mRight < mTextEntry->getRect().getWidth() - right_pad); +} + +void LLLocationInputCtrl::rebuildLocationHistory(const std::string& filter) { LLLocationHistory::location_list_t filtered_items; const LLLocationHistory::location_list_t* itemsp = NULL; @@ -807,7 +954,7 @@ void LLLocationInputCtrl::rebuildLocationHistory(std::string filter) LLSD value; value["tooltip"] = it->getToolTip(); //location history can contain only typed locations - value["item_type"] = TYPED_REGION_SURL; + value["item_type"] = TYPED_REGION_SLURL; value["global_pos"] = it->mGlobalPos.getValue(); add(it->getLocation(), value); } @@ -885,16 +1032,25 @@ void LLLocationInputCtrl::updateWidgetlayout() void LLLocationInputCtrl::changeLocationPresentation() { - //change location presentation only if user does not select/past anything and - //human-readable region name is being displayed + if (!mTextEntry) + return; + + //change location presentation only if user does not select/paste anything and + //human-readable region name is being displayed std::string text = mTextEntry->getText(); LLStringUtil::trim(text); - if(mTextEntry && !mTextEntry->hasSelection() && text == mHumanReadableLocation ) + if(!mTextEntry->hasSelection() && text == mHumanReadableLocation) { //needs unescaped one - mTextEntry->setText(LLAgentUI::buildSLURL(false)); + LLSLURL slurl; + LLAgentUI::buildSLURL(slurl, false); + mTextEntry->setText(slurl.getSLURLString()); mTextEntry->selectAll(); - } + + mMaturityButton->setVisible(FALSE); + + isHumanReadableLocationVisible = false; + } } void LLLocationInputCtrl::onLocationContextMenuItemClicked(const LLSD& userdata) @@ -909,7 +1065,6 @@ void LLLocationInputCtrl::onLocationContextMenuItemClicked(const LLSD& userdata) { gSavedSettings.setBOOL("NavBarShowParcelProperties", !gSavedSettings.getBOOL("NavBarShowParcelProperties")); - refreshParcelIcons(); } else if (item == "landmark") { |