From cb01bbb8efbffddddcce05da395a21b9320a6065 Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Mon, 15 Jul 2013 22:24:34 -0400 Subject: [PATCH] Move tooltip hosting from llscrolllistitem to llscrolllistcell --- indra/llui/llcombobox.cpp | 2 +- indra/llui/llscrolllistcell.cpp | 25 ++++++++++++++++++++++++- indra/llui/llscrolllistcell.h | 7 +++++++ indra/llui/llscrolllistctrl.cpp | 13 +++---------- indra/llui/llscrolllistitem.h | 4 ---- indra/newview/llpanelnearbymedia.cpp | 2 +- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/indra/llui/llcombobox.cpp b/indra/llui/llcombobox.cpp index df3369e89..d1c8aceaf 100644 --- a/indra/llui/llcombobox.cpp +++ b/indra/llui/llcombobox.cpp @@ -187,7 +187,7 @@ LLView* LLComboBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory * { std::string tool_tip = label; child->getAttributeString("tool_tip", tool_tip); - item->setToolTip(tool_tip); + item->getColumn(0)->setToolTip(tool_tip); } } } diff --git a/indra/llui/llscrolllistcell.cpp b/indra/llui/llscrolllistcell.cpp index 2eb50d3b2..ce11ef2f2 100644 --- a/indra/llui/llscrolllistcell.cpp +++ b/indra/llui/llscrolllistcell.cpp @@ -33,7 +33,8 @@ LLScrollListCell::LLScrollListCell(S32 width) -: mWidth(width) +: mWidth(width), + mToolTip() {} // virtual @@ -159,6 +160,28 @@ BOOL LLScrollListText::isText() const return TRUE; } +//virtual +const std::string &LLScrollListText::getToolTip() const +{ + // If base class has a tooltip, return that + if (! LLScrollListCell::getToolTip().empty()) + return LLScrollListCell::getToolTip(); + + // ...otherwise, return the value itself as the tooltip + return mText.getString(); +} + +// virtual +BOOL LLScrollListText::needsToolTip() const +{ + // If base class has a tooltip, return that + if (LLScrollListCell::needsToolTip()) + return LLScrollListCell::needsToolTip(); + + // ...otherwise, show tooltips for truncated text + return mFont->getWidth(mText.getString()) > getWidth(); +} + //virtual BOOL LLScrollListText::getVisible() const { diff --git a/indra/llui/llscrolllistcell.h b/indra/llui/llscrolllistcell.h index e04635ad7..528166afd 100644 --- a/indra/llui/llscrolllistcell.h +++ b/indra/llui/llscrolllistcell.h @@ -57,10 +57,13 @@ public: virtual S32 getHeight() const { return 0; } virtual const LLSD getValue() const; virtual void setValue(const LLSD& value) { } + virtual const std::string &getToolTip() const { return mToolTip; } + virtual void setToolTip(const std::string &str) { mToolTip = str; } virtual BOOL getVisible() const { return TRUE; } virtual void setWidth(S32 width) { mWidth = width; } virtual void highlightText(S32 offset, S32 num_chars) {} virtual BOOL isText() const { return FALSE; } + virtual BOOL needsToolTip() const { return ! mToolTip.empty(); } virtual void setColor(const LLColor4&) {} virtual void onCommit() {}; @@ -69,6 +72,8 @@ public: private: S32 mWidth; + std::string mToolTip; +}; }; /* @@ -90,6 +95,8 @@ public: /*virtual*/ void setColor(const LLColor4&); /*virtual*/ BOOL isText() const; + /*virtual*/ const std::string & getToolTip() const; + /*virtual*/ BOOL needsToolTip() const; S32 getTextWidth() const { return mTextWidth;} void setTextWidth(S32 value) { mTextWidth = value;} diff --git a/indra/llui/llscrolllistctrl.cpp b/indra/llui/llscrolllistctrl.cpp index 65c5db893..6533085f5 100644 --- a/indra/llui/llscrolllistctrl.cpp +++ b/indra/llui/llscrolllistctrl.cpp @@ -1598,18 +1598,11 @@ BOOL LLScrollListCtrl::handleToolTip(S32 x, S32 y, std::string& msg, LLRect* sti LLScrollListItem* hit_item = hitItem(x, y); if (hit_item) { - // If the item has a specific tool tip set by XUI use that first - std::string tooltip=hit_item->getToolTip(); - if(!tooltip.empty()) - { - msg=tooltip; - return TRUE; - } - LLScrollListCell* hit_cell = hit_item->getColumn(column_index); if (!hit_cell) return FALSE; if (hit_cell - && hit_cell->isText()) + && hit_cell->isText() + && hit_cell->needsToolTip()) { S32 row_index = getItemIndex(hit_item); LLRect cell_rect = getCellRect(row_index, column_index); @@ -1617,7 +1610,7 @@ BOOL LLScrollListCtrl::handleToolTip(S32 x, S32 y, std::string& msg, LLRect* sti LLRect sticky_rect; localRectToScreen(cell_rect, sticky_rect_screen); - msg = hit_cell->getValue().asString(); + msg = hit_cell->getToolTip(); } handled = TRUE; } diff --git a/indra/llui/llscrolllistitem.h b/indra/llui/llscrolllistitem.h index f3f186acb..05c1f246e 100644 --- a/indra/llui/llscrolllistitem.h +++ b/indra/llui/llscrolllistitem.h @@ -53,9 +53,6 @@ public: void setUserdata( void* userdata ) { mUserdata = userdata; } void* getUserdata() const { return mUserdata; } - void setToolTip(const std::string tool_tip) { mToolTip=tool_tip; } - std::string getToolTip() { return mToolTip; } - virtual LLUUID getUUID() const { return mItemValue.asUUID(); } LLSD getValue() const { return mItemValue; } @@ -84,7 +81,6 @@ private: BOOL mEnabled; void* mUserdata; LLSD mItemValue; - std::string mToolTip; std::vector mColumns; LLRect mRectangle; }; diff --git a/indra/newview/llpanelnearbymedia.cpp b/indra/newview/llpanelnearbymedia.cpp index e5751ebd2..bd2575ea7 100644 --- a/indra/newview/llpanelnearbymedia.cpp +++ b/indra/newview/llpanelnearbymedia.cpp @@ -476,7 +476,7 @@ void LLPanelNearByMedia::updateListItem(LLScrollListItem* item, { cell->setValue(name); } - item->setToolTip(item_tooltip); + cell->setToolTip(item_tooltip); // *TODO: Make these font styles/colors configurable via XUI U8 font_style = LLFontGL::NORMAL;