summaryrefslogtreecommitdiff
path: root/indra/llui/llscrolllistctrl.h
diff options
context:
space:
mode:
authorSteven Bennetts <steve@lindenlab.com>2009-06-21 08:04:56 +0000
committerSteven Bennetts <steve@lindenlab.com>2009-06-21 08:04:56 +0000
commit9ec432034dc3c45d7ce763eb02dae4cc7f6b8da8 (patch)
tree4a505c1e0919af52800b3ffb3eaf135e7d6f9ce6 /indra/llui/llscrolllistctrl.h
parent351ebe9fcb76f3b99c2957004bb8493a904869ee (diff)
merge -r 122421-124917 viewer-2.0.0-2 -> viewer-2.0.0-3
ignore-dead-branch
Diffstat (limited to 'indra/llui/llscrolllistctrl.h')
-rw-r--r--indra/llui/llscrolllistctrl.h433
1 files changed, 106 insertions, 327 deletions
diff --git a/indra/llui/llscrolllistctrl.h b/indra/llui/llscrolllistctrl.h
index 72d8894afa..461df6760f 100644
--- a/indra/llui/llscrolllistctrl.h
+++ b/indra/llui/llscrolllistctrl.h
@@ -1,5 +1,8 @@
/**
* @file llscrolllistctrl.h
+ * @brief A scrolling list of items. This is the one you want to use
+ * in UI code. LLScrollListCell, LLScrollListItem, etc. are utility
+ * classes.
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
@@ -37,346 +40,109 @@
#include "lluictrl.h"
#include "llctrlselectioninterface.h"
-#include "lldarray.h"
+//#include "lldarray.h"
#include "llfontgl.h"
#include "llui.h"
-#include "llstring.h"
-#include "llimagegl.h"
+#include "llstring.h" // LLWString
+//#include "llimagegl.h"
#include "lleditmenuhandler.h"
#include "llframetimer.h"
-#include "llcheckboxctrl.h"
-#include "llcombobox.h"
+
#include "llscrollbar.h"
-#include "llresizebar.h"
#include "lldate.h"
+#include "llscrolllistitem.h"
+#include "llscrolllistcolumn.h"
-/*
- * Represents a cell in a scrollable table.
- *
- * Sub-classes must return height and other properties
- * though width accessors are implemented by the base class.
- * It is therefore important for sub-class constructors to call
- * setWidth() with realistic values.
- */
-class LLScrollListCell
-{
-public:
- LLScrollListCell(S32 width = 0) : mWidth(width) {};
- virtual ~LLScrollListCell() {};
- virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const = 0; // truncate to given width, if possible
- virtual S32 getWidth() const {return mWidth;}
- virtual S32 getContentWidth() const { return 0; }
- virtual S32 getHeight() const = 0;
- virtual const LLSD getValue() const { return LLStringUtil::null; }
- virtual void setValue(const LLSD& value) { }
- 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 = 0;
- virtual void setColor(const LLColor4&) {}
- virtual void onCommit() {};
-
- virtual BOOL handleClick() { return FALSE; }
- virtual void setEnabled(BOOL enable) { }
-
-private:
- S32 mWidth;
-};
-
-/*
- * Draws a horizontal line.
- */
-class LLScrollListSeparator : public LLScrollListCell
-{
-public:
- LLScrollListSeparator(S32 width);
- virtual ~LLScrollListSeparator() {};
- virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const; // truncate to given width, if possible
- virtual S32 getHeight() const;
- virtual BOOL isText() const { return FALSE; }
-};
-
-/*
- * Cell displaying a text label.
- */
-class LLScrollListText : public LLScrollListCell
-{
-public:
- LLScrollListText( const std::string& text, const LLFontGL* font, S32 width = 0, U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, LLColor4& color = LLColor4::black, BOOL use_color = FALSE, BOOL visible = TRUE);
- /*virtual*/ ~LLScrollListText();
-
- virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const;
- virtual S32 getContentWidth() const;
- virtual S32 getHeight() const;
- virtual void setValue(const LLSD& value);
- virtual const LLSD getValue() const;
- virtual BOOL getVisible() const;
- virtual void highlightText(S32 offset, S32 num_chars);
-
- virtual void setColor(const LLColor4&);
- virtual BOOL isText() const;
-
- void setText(const LLStringExplicit& text);
- void setFontStyle(const U8 font_style) { mFontStyle = font_style; }
-
-private:
- LLUIString mText;
- const LLFontGL* mFont;
- LLColor4 mColor;
- U8 mUseColor;
- U8 mFontStyle;
- LLFontGL::HAlign mFontAlignment;
- BOOL mVisible;
- S32 mHighlightCount;
- S32 mHighlightOffset;
-
- LLPointer<LLUIImage> mRoundedRectImage;
-
- static U32 sCount;
-};
-
+class LLScrollListCell;
+class LLTextBox;
-class LLScrollListDate : public LLScrollListText
-{
-public:
- LLScrollListDate( const LLDate& date, const LLFontGL* font, S32 width=0, U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, LLColor4& color = LLColor4::black, BOOL use_color = FALSE, BOOL visible = TRUE);
- virtual void setValue(const LLSD& value);
- virtual const LLSD getValue() const;
-
-private:
- LLDate mDate;
-};
-
-/*
- * Cell displaying an image.
- */
-class LLScrollListIcon : public LLScrollListCell
-{
-public:
- LLScrollListIcon( LLUIImagePtr icon, S32 width = 0);
- LLScrollListIcon(const LLSD& value, S32 width = 0);
- /*virtual*/ ~LLScrollListIcon();
- virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const;
- virtual S32 getWidth() const;
- virtual S32 getHeight() const { return mIcon ? mIcon->getHeight() : 0; }
- virtual const LLSD getValue() const { return mIcon.isNull() ? LLStringUtil::null : mIcon->getName(); }
- virtual void setColor(const LLColor4&);
- virtual BOOL isText()const { return FALSE; }
- virtual void setValue(const LLSD& value);
-
-private:
- LLUIImagePtr mIcon;
- LLColor4 mColor;
-};
-
-/*
- * An interactive cell containing a check box.
- */
-class LLScrollListCheck : public LLScrollListCell
-{
-public:
- LLScrollListCheck( LLCheckBoxCtrl* check_box, S32 width = 0);
- /*virtual*/ ~LLScrollListCheck();
- virtual void draw(const LLColor4& color, const LLColor4& highlight_color) const;
- virtual S32 getHeight() const { return 0; }
- virtual const LLSD getValue() const { return mCheckBox->getValue(); }
- virtual void setValue(const LLSD& value) { mCheckBox->setValue(value); }
- virtual void onCommit() { mCheckBox->onCommit(); }
-
- virtual BOOL handleClick();
- virtual void setEnabled(BOOL enable) { mCheckBox->setEnabled(enable); }
-
- LLCheckBoxCtrl* getCheckBox() { return mCheckBox; }
- virtual BOOL isText() const { return FALSE; }
-
-private:
- LLCheckBoxCtrl* mCheckBox;
-};
-
-/*
- * A simple data class describing a column within a scroll list.
- */
-class LLScrollListColumn
-{
-public:
- LLScrollListColumn();
- LLScrollListColumn(const LLSD &sd, LLScrollListCtrl* parent);
-
- void setWidth(S32 width);
- S32 getWidth() const { return mWidth; }
-
- // Public data is fine so long as this remains a simple struct-like data class.
- // If it ever gets any smarter than that, these should all become private
- // with protected or public accessor methods added as needed. -MG
- std::string mName;
- std::string mSortingColumn;
- BOOL mSortAscending;
- std::string mLabel;
- F32 mRelWidth;
- BOOL mDynamicWidth;
- S32 mMaxContentWidth;
- S32 mIndex;
- LLScrollListCtrl* mParentCtrl;
- class LLColumnHeader* mHeader;
- LLFontGL::HAlign mFontAlignment;
-
-private:
- S32 mWidth;
-
-};
-
-class LLColumnHeader : public LLComboBox
-{
-public:
- LLColumnHeader(const std::string& label, const LLRect &rect, LLScrollListColumn* column, const LLFontGL *font = NULL);
- ~LLColumnHeader();
-
- /*virtual*/ void draw();
- /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask);
-
- /*virtual*/ void showList();
- /*virtual*/ LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESnapEdge snap_edge, ESnapType snap_type, S32 threshold, S32 padding);
- /*virtual*/ void userSetShape(const LLRect& new_rect);
-
- void setImage(const std::string &image_name);
- LLScrollListColumn* getColumn() { return mColumn; }
- void setHasResizableElement(BOOL resizable);
- void updateResizeBars();
- BOOL canResize();
- void enableResizeBar(BOOL enable);
- std::string getLabel() { return mOrigLabel; }
-
- static void onSelectSort(LLUICtrl* ctrl, void* user_data);
- static void onClick(void* user_data);
- static void onMouseDown(void* user_data);
- static void onHeldDown(void* user_data);
-
-private:
- LLScrollListColumn* mColumn;
- LLResizeBar* mResizeBar;
- std::string mOrigLabel;
- LLUIString mAscendingText;
- LLUIString mDescendingText;
- BOOL mShowSortOptions;
- BOOL mHasResizableElement;
-};
-
-class LLScrollListItem
+class LLScrollListCtrl : public LLUICtrl, public LLEditMenuHandler,
+ public LLCtrlListInterface, public LLCtrlScrollInterface
{
public:
- LLScrollListItem( BOOL enabled = TRUE, void* userdata = NULL, const LLUUID& uuid = LLUUID::null )
- : mSelected(FALSE), mEnabled( enabled ), mUserdata( userdata ), mItemValue( uuid ), mColumns() {}
- LLScrollListItem( LLSD item_value, void* userdata = NULL )
- : mSelected(FALSE), mEnabled( TRUE ), mUserdata( userdata ), mItemValue( item_value ), mColumns() {}
-
- virtual ~LLScrollListItem();
-
- void setSelected( BOOL b ) { mSelected = b; }
- BOOL getSelected() const { return mSelected; }
-
- void setEnabled( BOOL b );
- BOOL getEnabled() const { return mEnabled; }
-
- void setUserdata( void* userdata ) { mUserdata = userdata; }
- void* getUserdata() const { return mUserdata; }
+ struct Contents : public LLInitParam::Block<Contents>
+ {
+ Multiple<LLScrollListColumn::Params> columns;
+ Multiple<LLScrollListItem::Params> rows;
- LLUUID getUUID() const { return mItemValue.asUUID(); }
- LLSD getValue() const { return mItemValue; }
+ //Multiple<Contents> groups;
- // If width = 0, just use the width of the text. Otherwise override with
- // specified width in pixels.
- void addColumn( const std::string& text, const LLFontGL* font, S32 width = 0 , U8 font_style = LLFontGL::NORMAL, LLFontGL::HAlign font_alignment = LLFontGL::LEFT, BOOL visible = TRUE)
- { mColumns.push_back( new LLScrollListText(text, font, width, font_style, font_alignment, LLColor4::black, FALSE, visible) ); }
+ Contents();
+ };
- void addColumn( LLUIImagePtr icon, S32 width = 0 )
- { mColumns.push_back( new LLScrollListIcon(icon, width) ); }
-
- void addColumn( LLCheckBoxCtrl* check, S32 width = 0 )
- { mColumns.push_back( new LLScrollListCheck(check,width) ); }
-
- void setNumColumns(S32 columns);
-
- void setColumn( S32 column, LLScrollListCell *cell );
+ // *TODO: Add callbacks to Params
+ typedef boost::function<void (void)> callback_t;
- S32 getNumColumns() const { return mColumns.size(); }
-
- LLScrollListCell *getColumn(const S32 i) const { if (0 <= i && i < (S32)mColumns.size()) { return mColumns[i]; } return NULL; }
-
- std::string getContentsCSV() const;
+ struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
+ {
+ // behavioral flags
+ Optional<bool> multi_select,
+ commit_on_keyboard_movement;
+
+ // display flags
+ Optional<bool> has_border,
+ draw_heading,
+ draw_stripes,
+ background_visible;
+
+ // layout
+ Optional<S32> column_padding,
+ heading_height;
+
+ // sort and search behavior
+ Optional<S32> search_column,
+ sort_column;
+ Optional<bool> sort_ascending;
+
+ // colors
+ Optional<LLUIColor> fg_unselected_color,
+ fg_selected_color,
+ bg_selected_color,
+ fg_disable_color,
+ bg_writeable_color,
+ bg_read_only_color,
+ bg_stripe_color,
+ hovered_color,
+ highlighted_color;
+
+ Optional<Contents> contents;
+
+ Params();
+ };
- virtual void draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding);
+protected:
+ friend class LLUICtrlFactory;
-private:
- BOOL mSelected;
- BOOL mEnabled;
- void* mUserdata;
- LLSD mItemValue;
- std::vector<LLScrollListCell *> mColumns;
-};
-
-/*
- * A graphical control representing a scrollable table.
- * Cells in the table can be simple text or more complicated things
- * such as icons or even interactive elements like check boxes.
- */
-class LLScrollListItemComment : public LLScrollListItem
-{
-public:
- LLScrollListItemComment(const std::string& comment_string, const LLColor4& color);
+ LLScrollListCtrl(const Params&);
- /*virtual*/ void draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding);
-private:
- LLColor4 mColor;
-};
-
-class LLScrollListItemSeparator : public LLScrollListItem
-{
public:
- LLScrollListItemSeparator();
-
- /*virtual*/ void draw(const LLRect& rect, const LLColor4& fg_color, const LLColor4& bg_color, const LLColor4& highlight_color, S32 column_padding);
-};
-
-class LLScrollListCtrl : public LLUICtrl, public LLEditMenuHandler,
- public LLCtrlListInterface, public LLCtrlScrollInterface
-{
-public:
- LLScrollListCtrl(
- const std::string& name,
- const LLRect& rect,
- void (*commit_callback)(LLUICtrl*, void*),
- void* callback_userdata,
- BOOL allow_multiple_selection,
- BOOL draw_border = TRUE);
-
virtual ~LLScrollListCtrl();
- virtual LLXMLNodePtr getXML(bool save_children = true) const;
- void setScrollListParameters(LLXMLNodePtr node);
- static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
-
S32 isEmpty() const;
void deleteAllItems() { clearRows(); }
// Sets an array of column descriptors
- void setColumnHeadings(LLSD headings);
+ void setColumnHeadings(const LLSD& headings);
void sortByColumnIndex(U32 column, BOOL ascending);
// LLCtrlListInterface functions
virtual S32 getItemCount() const;
// Adds a single column descriptor: ["name" : string, "label" : string, "width" : integer, "relwidth" : integer ]
- virtual void addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
+ virtual void addColumn(const LLScrollListColumn::Params& column, EAddPosition pos = ADD_BOTTOM);
+ virtual void addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
virtual void clearColumns();
virtual void setColumnLabel(const std::string& column, const std::string& label);
-
+ virtual bool preProcessChildNode(LLXMLNodePtr child);
virtual LLScrollListColumn* getColumn(S32 index);
+ virtual LLScrollListColumn* getColumn(const std::string& name);
virtual S32 getNumColumns() const { return mColumnsIndexed.size(); }
// Adds a single element, from an array of:
// "columns" => [ "column" => column name, "value" => value, "type" => type, "font" => font, "font-style" => style ], "id" => uuid
// Creates missing columns automatically.
- virtual LLScrollListItem* addElement(const LLSD& value, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
+ virtual LLScrollListItem* addElement(const LLSD& element, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
+ virtual LLScrollListItem* addRow(const LLScrollListItem::Params& value, EAddPosition pos = ADD_BOTTOM);
// Simple add element. Takes a single array of:
// [ "value" => value, "font" => font, "font-style" => style ]
virtual void clearRows(); // clears all elements
@@ -421,10 +187,14 @@ public:
void deleteSelectedItems();
void deselectAllItems(BOOL no_commit_on_change = FALSE); // by default, go ahead and commit on selection change
- void highlightNthItem( S32 index );
- void setDoubleClickCallback( void (*cb)(void*) ) { mOnDoubleClickCallback = cb; }
- void setMaximumSelectCallback( void (*cb)(void*) ) { mOnMaximumSelectCallback = cb; }
- void setSortChangedCallback( void (*cb)(void*) ) { mOnSortChangedCallback = cb; }
+ void clearHighlightedItems();
+ void mouseOverHighlightNthItem( S32 index );
+
+ void setDoubleClickCallback( callback_t cb ) { mOnDoubleClickCallback = cb; }
+ void setMaximumSelectCallback( callback_t cb) { mOnMaximumSelectCallback = cb; }
+ void setSortChangedCallback( callback_t cb) { mOnSortChangedCallback = cb; }
+ // Convenience function; *TODO: replace with setter above + boost::bind() in calling code
+ void setDoubleClickCallback( boost::function<void (void* userdata)> cb, void* userdata) { mOnDoubleClickCallback = boost::bind(cb, userdata); }
void swapWithNext(S32 index);
void swapWithPrevious(S32 index);
@@ -435,21 +205,21 @@ public:
S32 getItemIndex( LLScrollListItem* item ) const;
S32 getItemIndex( const LLUUID& item_id ) const;
- LLScrollListItem* addCommentText( const std::string& comment_text, EAddPosition pos = ADD_BOTTOM);
+ void setCommentText( const std::string& comment_text);
LLScrollListItem* addSeparator(EAddPosition pos);
// "Simple" interface: use this when you're creating a list that contains only unique strings, only
// one of which can be selected at a time.
virtual LLScrollListItem* addSimpleElement(const std::string& value, EAddPosition pos = ADD_BOTTOM, const LLSD& id = LLSD());
-
BOOL selectItemByLabel( const std::string& item, BOOL case_sensitive = TRUE ); // FALSE if item not found
BOOL selectItemByPrefix(const std::string& target, BOOL case_sensitive = TRUE);
BOOL selectItemByPrefix(const LLWString& target, BOOL case_sensitive = TRUE);
+ LLScrollListItem* getItemByLabel( const std::string& item, BOOL case_sensitive = TRUE, S32 column = 0 );
const std::string getSelectedItemLabel(S32 column = 0) const;
LLSD getSelectedValue();
- // DEPRECATED: Use LLSD versions of addCommentText() and getSelectedValue().
+ // DEPRECATED: Use LLSD versions of setCommentText() and getSelectedValue().
// "StringUUID" interface: use this when you're creating a list that contains non-unique strings each of which
// has an associated, unique UUID, and only one of which can be selected at a time.
LLScrollListItem* addStringUUIDItem(const std::string& item_text, const LLUUID& id, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE, S32 column_width = 0);
@@ -475,7 +245,8 @@ public:
void setBgStripeColor(const LLColor4& c) { mBgStripeColor = c; }
void setFgSelectedColor(const LLColor4 &c) { mFgSelectedColor = c; }
void setFgUnselectedColor(const LLColor4 &c){ mFgUnselectedColor = c; }
- void setHighlightedColor(const LLColor4 &c) { mHighlightedColor = c; }
+ void setHoveredColor(const LLColor4 &c) { mHoveredColor = c; }
+ void setHighlightedColor(const LLColor4 &c) { mHighlightedColor = c; }
void setFgDisableColor(const LLColor4 &c) { mFgDisabledColor = c; }
void setBackgroundVisible(BOOL b) { mBackgroundVisible = b; }
@@ -514,6 +285,7 @@ public:
/*virtual*/ void setFocus( BOOL b );
/*virtual*/ void onFocusReceived();
/*virtual*/ void onFocusLost();
+ /*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask);
/*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
virtual BOOL isDirty() const;
@@ -528,15 +300,14 @@ public:
LLRect getItemListRect() { return mItemListRect; }
// Used "internally" by the scroll bar.
- static void onScrollChange( S32 new_pos, LLScrollbar* src, void* userdata );
+ void onScrollChange( S32 new_pos, LLScrollbar* src );
static void onClickColumn(void *userdata);
- void updateColumns();
+ virtual void updateColumns();
void calcColumnWidths();
S32 getMaxContentWidth() { return mMaxContentWidth; }
- void setDisplayHeading(BOOL display);
void setHeadingHeight(S32 heading_height);
void setCollapseEmptyColumns(BOOL collapse);
@@ -561,7 +332,7 @@ public:
BOOL getSortAscending() { return mSortColumns.empty() ? TRUE : mSortColumns.back().second; }
BOOL needsSorting();
- S32 selectMultiple( LLDynamicArray<LLUUID> ids );
+ S32 selectMultiple( std::vector<LLUUID> ids );
void sortItems();
// sorts a list without affecting the permanent sort order (so further list insertions can be unsorted, for example)
void sortOnce(S32 column, BOOL ascending);
@@ -604,7 +375,6 @@ private:
void commitIfChanged();
BOOL setSort(S32 column, BOOL ascending);
-
S32 mCurIndex; // For get[First/Next]Data
S32 mCurSelectedIndex; // For get[First/Next]Selected
@@ -621,7 +391,7 @@ private:
BOOL mSelectionChanged;
BOOL mNeedsScroll;
BOOL mCanSelect;
- BOOL mDisplayColumnHeaders;
+ const BOOL mDisplayColumnHeaders;
BOOL mColumnsDirty;
item_list mItemList;
@@ -637,19 +407,20 @@ private:
BOOL mBackgroundVisible;
BOOL mDrawStripes;
- LLColor4 mBgWriteableColor;
- LLColor4 mBgReadOnlyColor;
- LLColor4 mBgSelectedColor;
- LLColor4 mBgStripeColor;
- LLColor4 mFgSelectedColor;
- LLColor4 mFgUnselectedColor;
- LLColor4 mFgDisabledColor;
- LLColor4 mHighlightedColor;
+ LLUIColor mBgWriteableColor;
+ LLUIColor mBgReadOnlyColor;
+ LLUIColor mBgSelectedColor;
+ LLUIColor mBgStripeColor;
+ LLUIColor mFgSelectedColor;
+ LLUIColor mFgUnselectedColor;
+ LLUIColor mFgDisabledColor;
+ LLUIColor mHoveredColor;
+ LLUIColor mHighlightedColor;
S32 mBorderThickness;
- void (*mOnDoubleClickCallback)(void* userdata);
- void (*mOnMaximumSelectCallback)(void* userdata );
- void (*mOnSortChangedCallback)(void* userdata);
+ callback_t mOnDoubleClickCallback;
+ callback_t mOnMaximumSelectCallback;
+ callback_t mOnSortChangedCallback;
S32 mHighlightedItem;
class LLViewBorder* mBorder;
@@ -678,7 +449,15 @@ private:
// HACK: Did we draw one selected item this frame?
BOOL mDrewSelected;
+
+ LLTextBox* mCommentTextBox;
}; // end class LLScrollListCtrl
+#ifdef LL_WINDOWS
+#ifndef INSTANTIATE_GETCHILD_SCROLLLIST
+#pragma warning (disable : 4231)
+extern template LLScrollListCtrl* LLView::getChild<LLScrollListCtrl>( const std::string& name, BOOL recurse, BOOL create_if_missing ) const;
+#endif
+#endif
#endif // LL_SCROLLLISTCTRL_H