llscrolllistctrl.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /**
  2. * @file llscrolllistctrl.h
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewergpl$
  5. *
  6. * Copyright (c) 2001-2009, Linden Research, Inc.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #ifndef LL_SCROLLLISTCTRL_H
  32. #define LL_SCROLLLISTCTRL_H
  33. #include <vector>
  34. #include <deque>
  35. #include "llcheckboxctrl.h"
  36. #include "llcombobox.h"
  37. #include "lldate.h"
  38. #include "lleditmenuhandler.h"
  39. #include "llframetimer.h"
  40. #include "llimagegl.h"
  41. #include "llpreprocessor.h"
  42. #include "llresizebar.h"
  43. #include "llscrollbar.h"
  44. #include "llstring.h"
  45. #include "lluictrl.h"
  46. #include "lluuid.h"
  47. /*
  48. * Represents a cell in a scrollable table.
  49. *
  50. * Sub-classes must return height and other properties though width accessors
  51. * are implemented by the base class. It is therefore important for sub-class
  52. * constructors to call setWidth() with realistic values.
  53. */
  54. class LLScrollListCell
  55. {
  56. public:
  57. LLScrollListCell(S32 width = 0)
  58. : mWidth(width)
  59. {
  60. }
  61. virtual ~LLScrollListCell() = default;
  62. virtual void draw(const LLColor4& color,
  63. const LLColor4& highlight_color) const = 0;
  64. LL_INLINE virtual S32 getWidth() const { return mWidth; }
  65. LL_INLINE virtual S32 getContentWidth() const { return 0; }
  66. virtual S32 getHeight() const = 0;
  67. LL_INLINE virtual LLSD getValue() const { return LLStringUtil::null; }
  68. LL_INLINE virtual void setValue(const LLSD& value) {}
  69. LL_INLINE virtual bool getVisible() const { return true; }
  70. LL_INLINE virtual void setWidth(S32 width) { mWidth = width; }
  71. LL_INLINE virtual void highlightText(S32 offset,
  72. S32 num_chars) {}
  73. virtual bool isText() const = 0;
  74. LL_INLINE virtual void setColor(const LLColor4&) {}
  75. virtual void onCommit() {}
  76. virtual bool handleClick() { return false; }
  77. LL_INLINE virtual void setEnabled(bool enable) {}
  78. private:
  79. S32 mWidth;
  80. };
  81. /*
  82. * Draws a horizontal line.
  83. */
  84. class LLScrollListSeparator : public LLScrollListCell
  85. {
  86. public:
  87. LLScrollListSeparator(S32 width);
  88. virtual void draw(const LLColor4& color,
  89. const LLColor4& highlight_color) const;
  90. virtual S32 getHeight() const;
  91. LL_INLINE virtual bool isText() const { return false; }
  92. };
  93. /*
  94. * Cell displaying a text label.
  95. */
  96. class LLScrollListText : public LLScrollListCell
  97. {
  98. public:
  99. LLScrollListText(const std::string& text, const LLFontGL* font,
  100. S32 width = 0, U8 font_style = LLFontGL::NORMAL,
  101. LLFontGL::HAlign font_alignment = LLFontGL::LEFT,
  102. LLColor4& color = LLColor4::black, bool use_color = false,
  103. bool visible = true);
  104. ~LLScrollListText() override;
  105. void draw(const LLColor4& color,
  106. const LLColor4& highlight_color) const override;
  107. LL_INLINE void setText(const std::string& text) { mText = text; }
  108. LL_INLINE void setValue(const LLSD& value) override { setText(value.asString()); }
  109. LL_INLINE LLSD getValue() const override { return LLSD(mText.getString()); }
  110. LL_INLINE S32 getContentWidth() const override { return mFont->getWidth(mText.getString()); }
  111. S32 getHeight() const override;
  112. LL_INLINE bool getVisible() const override { return mVisible; }
  113. void highlightText(S32 offset, S32 num_chars) override;
  114. LL_INLINE void setColor(const LLColor4& c) override { mColor = c; mUseColor = true; }
  115. LL_INLINE bool isText() const override { return true; }
  116. LL_INLINE void setFontStyle(U8 font_style) { mFontStyle = font_style; }
  117. private:
  118. LLColor4 mColor;
  119. const LLFontGL* mFont;
  120. LLFontGL::HAlign mFontAlignment;
  121. LLUIString mText;
  122. S32 mHighlightCount;
  123. S32 mHighlightOffset;
  124. U8 mFontStyle;
  125. bool mUseColor;
  126. bool mVisible;
  127. static U32 sCount;
  128. };
  129. class LLScrollListDate : public LLScrollListText
  130. {
  131. public:
  132. LLScrollListDate(const LLDate& date, const std::string& format,
  133. const LLFontGL* font, S32 width = 0,
  134. U8 font_style = LLFontGL::NORMAL,
  135. LLFontGL::HAlign font_alignment = LLFontGL::LEFT,
  136. LLColor4& color = LLColor4::black, bool use_color = false,
  137. bool visible = true);
  138. void setValue(const LLSD& value) override;
  139. LL_INLINE LLSD getValue() const override { return mDate; }
  140. private:
  141. LLDate mDate;
  142. std::string mFormat;
  143. };
  144. /*
  145. * Cell displaying an image.
  146. */
  147. class LLScrollListIcon : public LLScrollListCell
  148. {
  149. public:
  150. LLScrollListIcon(LLUIImagePtr icon, S32 width = 0);
  151. LLScrollListIcon(const LLSD& value, S32 width = 0);
  152. void draw(const LLColor4& color, const LLColor4& highlight) const override;
  153. S32 getWidth() const override;
  154. LL_INLINE S32 getHeight() const override { return mIcon ? mIcon->getHeight() : 0; }
  155. LL_INLINE LLSD getValue() const override { return mIcon.isNull() ? LLStringUtil::null : mIcon->getName(); }
  156. void setColor(const LLColor4& color) override;
  157. LL_INLINE bool isText() const override { return false; }
  158. void setValue(const LLSD& value) override;
  159. LL_INLINE void setImage(LLUIImagePtr image) { mIcon = image; }
  160. private:
  161. LLUIImagePtr mIcon;
  162. LLColor4 mColor;
  163. };
  164. /*
  165. * An interactive cell containing a check box.
  166. */
  167. class LLScrollListCheck : public LLScrollListCell
  168. {
  169. public:
  170. LLScrollListCheck(LLCheckBoxCtrl* check_box, S32 width = 0);
  171. ~LLScrollListCheck() override;
  172. void draw(const LLColor4& color, const LLColor4& highlight) const override;
  173. LL_INLINE S32 getHeight() const override { return 0; }
  174. LL_INLINE LLSD getValue() const override { return mCheckBox->getValue(); }
  175. LL_INLINE void setValue(const LLSD& v) override { mCheckBox->setValue(v); }
  176. void onCommit() override { mCheckBox->onCommit(); }
  177. bool handleClick() override;
  178. LL_INLINE void setEnabled(bool enable) override { mCheckBox->setEnabled(enable); }
  179. LL_INLINE LLCheckBoxCtrl* getCheckBox() { return mCheckBox; }
  180. LL_INLINE bool isText() const override { return false; }
  181. private:
  182. LLCheckBoxCtrl* mCheckBox;
  183. };
  184. /*
  185. * A simple data class describing a column within a scroll list.
  186. */
  187. class LLScrollListColumn
  188. {
  189. public:
  190. LLScrollListColumn();
  191. LLScrollListColumn(const LLSD& sd, LLScrollListCtrl* parent);
  192. void setWidth(S32 width);
  193. LL_INLINE S32 getWidth() const { return mWidth; }
  194. private:
  195. S32 mWidth;
  196. public:
  197. // Public data is fine so long as this remains a simple struct-like data
  198. // class. If it ever gets any smarter than that, these should all become
  199. // private with protected or public accessor methods added as needed. -MG
  200. LLScrollListCtrl* mParentCtrl;
  201. class LLColumnHeader* mHeader;
  202. LLFontGL::HAlign mFontAlignment;
  203. std::string mName;
  204. std::string mSortingColumn;
  205. std::string mLabel;
  206. S32 mMaxContentWidth;
  207. S32 mIndex;
  208. F32 mRelWidth;
  209. bool mDynamicWidth;
  210. bool mSortAscending;
  211. };
  212. class LLColumnHeader : public LLComboBox
  213. {
  214. public:
  215. LLColumnHeader(const std::string& label, const LLRect& rect,
  216. LLScrollListColumn* column, const LLFontGL* font = NULL);
  217. void draw() override;
  218. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  219. void showList() override;
  220. LLView* findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir,
  221. ESnapEdge snap_edge, ESnapType snap_type,
  222. S32 threshold, S32 padding) override;
  223. void userSetShape(const LLRect& new_rect) override;
  224. void setImage(const std::string &image_name);
  225. LL_INLINE LLScrollListColumn* getColumn() { return mColumn; }
  226. void setHasResizableElement(bool resizable);
  227. void updateResizeBars();
  228. bool canResize();
  229. void enableResizeBar(bool enable);
  230. LL_INLINE std::string getLabel() { return mOrigLabel; }
  231. static void onSelectSort(LLUICtrl* ctrl, void* user_data);
  232. static void onClick(void* user_data);
  233. static void onMouseDown(void* user_data);
  234. static void onHeldDown(void* user_data);
  235. private:
  236. LLScrollListColumn* mColumn;
  237. LLResizeBar* mResizeBar;
  238. std::string mOrigLabel;
  239. LLUIString mAscendingText;
  240. LLUIString mDescendingText;
  241. bool mShowSortOptions;
  242. bool mHasResizableElement;
  243. };
  244. class LLScrollListItem
  245. {
  246. protected:
  247. LOG_CLASS(LLScrollListItem);
  248. public:
  249. LLScrollListItem(bool enabled = true, void* userdata = NULL,
  250. const LLUUID& id = LLUUID::null)
  251. : mSelected(false),
  252. mItemEnabled(enabled),
  253. mUserdata(userdata),
  254. mItemValue(id),
  255. mItemID(id)
  256. {
  257. }
  258. LLScrollListItem(const LLSD& item_value, void* userdata = NULL)
  259. : mSelected(false),
  260. mItemEnabled(true),
  261. mUserdata(userdata),
  262. mItemValue(item_value)
  263. {
  264. if (mItemValue.isUUID())
  265. {
  266. mItemID = mItemValue.asUUID();
  267. }
  268. }
  269. virtual ~LLScrollListItem();
  270. LL_INLINE void setSelected(bool b) { mSelected = b; }
  271. LL_INLINE bool getSelected() const { return mSelected; }
  272. LL_INLINE void setEnabled(bool b) { mItemEnabled = b; }
  273. LL_INLINE bool getEnabled() const { return mItemEnabled; }
  274. LL_INLINE void setUserdata(void* userdata) { mUserdata = userdata; }
  275. LL_INLINE void* getUserdata() const { return mUserdata; }
  276. LL_INLINE void setToolTip(const std::string& tool_tip) { mToolTip = tool_tip; }
  277. LL_INLINE const std::string& getToolTip() const { return mToolTip; }
  278. LL_INLINE const LLUUID& getUUID() const { return mItemID; }
  279. LL_INLINE const LLSD& getValue() const { return mItemValue; }
  280. // If width = 0, just use the width of the text. Otherwise override with
  281. // specified width in pixels.
  282. LL_INLINE void addColumn(const std::string& text, const LLFontGL* font,
  283. S32 width = 0, U8 font_style = LLFontGL::NORMAL,
  284. LLFontGL::HAlign font_alignment = LLFontGL::LEFT,
  285. bool visible = true)
  286. {
  287. mColumns.push_back(new LLScrollListText(text, font, width, font_style,
  288. font_alignment,
  289. LLColor4::black, false,
  290. visible));
  291. }
  292. LL_INLINE void addColumn(LLUIImagePtr icon, S32 width = 0)
  293. {
  294. mColumns.push_back(new LLScrollListIcon(icon, width));
  295. }
  296. LL_INLINE void addColumn(LLCheckBoxCtrl* check, S32 width = 0)
  297. {
  298. mColumns.push_back(new LLScrollListCheck(check, width));
  299. }
  300. void setNumColumns(S32 columns);
  301. void setColumn(S32 column, LLScrollListCell* cell);
  302. LL_INLINE S32 getNumColumns() const { return (S32)mColumns.size(); }
  303. LL_INLINE LLScrollListCell* getColumn(S32 i) const
  304. {
  305. return i >= 0 && i < getNumColumns() ? mColumns[i] : NULL;
  306. }
  307. std::string getContentsCSV() const;
  308. virtual void draw(const LLRect& rect, const LLColor4& fg_color,
  309. const LLColor4& bg_color, const LLColor4& highlight_col,
  310. S32 column_padding);
  311. private:
  312. void* mUserdata;
  313. std::string mToolTip;
  314. std::vector<LLScrollListCell*> mColumns;
  315. LLUUID mItemID;
  316. LLSD mItemValue;
  317. bool mSelected;
  318. bool mItemEnabled;
  319. };
  320. /*
  321. * A graphical control representing a scrollable table. Cells in the table can
  322. * be simple text or more complicated things such as icons or even interactive
  323. * elements like check boxes.
  324. */
  325. class LLScrollListItemComment : public LLScrollListItem
  326. {
  327. public:
  328. LLScrollListItemComment(const std::string& comment_string,
  329. const LLColor4& color);
  330. void draw(const LLRect& rect, const LLColor4& fg_color,
  331. const LLColor4& bg_color, const LLColor4& highlight_color,
  332. S32 column_padding) override;
  333. private:
  334. LLColor4 mColor;
  335. };
  336. class LLScrollListItemSeparator : public LLScrollListItem
  337. {
  338. public:
  339. LLScrollListItemSeparator();
  340. void draw(const LLRect& rect, const LLColor4& fg_color,
  341. const LLColor4& bg_color, const LLColor4& highlight_color,
  342. S32 column_padding) override;
  343. };
  344. class LLScrollListCtrl : public LLUICtrl, public LLEditMenuHandler
  345. {
  346. public:
  347. enum EOperation
  348. {
  349. OP_DELETE = 1,
  350. OP_SELECT,
  351. OP_DESELECT,
  352. };
  353. LLScrollListCtrl(const std::string& name, const LLRect& rect,
  354. void (*commit_callback)(LLUICtrl*, void*),
  355. void* callback_userdata,
  356. bool allow_multiple_selection, bool draw_border = true);
  357. ~LLScrollListCtrl() override;
  358. const std::string& getTag() const override;
  359. LLXMLNodePtr getXML(bool save_children = true) const override;
  360. static LLView* fromXML(LLXMLNodePtr node, LLView* parent,
  361. LLUICtrlFactory* factory);
  362. void setScrollListParameters(LLXMLNodePtr node);
  363. LL_INLINE bool isEmpty() const { return mItemList.empty(); }
  364. LL_INLINE void deleteAllItems() { clearRows(); }
  365. // Sets an array of column descriptors
  366. void setColumnHeadings(LLSD headings);
  367. void sortByColumnIndex(U32 column, bool ascending);
  368. LL_INLINE S32 getItemCount() const { return mItemList.size(); }
  369. // Adds a single column descriptor: ["name" : string, "label" : string,
  370. // "width" : integer, "relwidth" : integer ]
  371. void addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
  372. void clearColumns();
  373. void setColumnLabel(const std::string& col, const std::string& l);
  374. virtual LLScrollListColumn* getColumn(S32 index);
  375. LL_INLINE S32 getNumColumns() const { return mColumnsIndexed.size(); }
  376. // Adds a single element, from an array of:
  377. // "columns" => [ "column" => column name, "value" => value,
  378. // "type" => type, "font" => font, "font-style" => style ], "id" => uuid
  379. // Creates missing columns automatically.
  380. virtual LLScrollListItem* addElement(const LLSD& value,
  381. EAddPosition pos = ADD_BOTTOM,
  382. void* userdata = NULL);
  383. void clearRows(); // Clears all elements
  384. void sortByColumn(const std::string& name, bool ascending);
  385. // This method takes an array of arrays of elements, as above
  386. void setValue(const LLSD& value) override;
  387. // Returns the value of the first selected item
  388. LLSD getValue() const override;
  389. // DEPRECATED: Use selectByID() below.
  390. LL_INLINE bool setCurrentByID(const LLUUID& id)
  391. {
  392. return selectByValue(LLSD(id));
  393. }
  394. LL_INLINE virtual LLUUID getCurrentID() const
  395. {
  396. return getStringUUIDSelectedItem();
  397. }
  398. bool operateOnSelection(EOperation op);
  399. bool operateOnAll(EOperation op);
  400. // Returns false if unable to set the max count so low
  401. bool setMaxItemCount(S32 max_count);
  402. // Returns false if item not found
  403. LL_INLINE bool selectByID(const LLUUID& id) { return selectByValue(LLSD(id)); }
  404. // Match item by value.asString(), which should work for string, integer,
  405. // UUID. Returns false if not found.
  406. bool setSelectedByValue(const LLSD& value, bool selected);
  407. LL_INLINE bool selectByValue(const LLSD value) { return setSelectedByValue(value, true); }
  408. LL_INLINE bool isSorted() const { return mSorted; }
  409. bool isSelected(const LLSD& value) const;
  410. bool handleClick(S32 x, S32 y, MASK mask);
  411. bool selectFirstItem();
  412. bool selectNthItem(S32 index);
  413. bool selectItemRange(S32 first, S32 last);
  414. bool selectItemAt(S32 x, S32 y, MASK mask);
  415. void selectItem(LLScrollListItem* itemp, bool single_select = true);
  416. void deleteItem(LLScrollListItem* item);
  417. void deleteSingleItem(S32 index);
  418. void deleteItems(const LLSD& sd);
  419. void deleteSelectedItems();
  420. // By default, goes ahead and commits on selection change
  421. void deselectAllItems(bool no_commit_on_change = false);
  422. void highlightNthItem(S32 index);
  423. void setDoubleClickCallback(void (*cb)(void*)) override { mOnDoubleClickCallback = cb; }
  424. void setMaximumSelectCallback(void (*cb)(void*)) { mOnMaximumSelectCallback = cb; }
  425. void setSortChangedCallback(void (*cb)(void*)) { mOnSortChangedCallback = cb; }
  426. void swapWithNext(S32 index);
  427. void swapWithPrevious(S32 index);
  428. LL_INLINE void setCanSelect(bool can_select) { mCanSelect = can_select; }
  429. LL_INLINE bool getCanSelect() const { return mCanSelect; }
  430. S32 getItemIndex(LLScrollListItem* item) const;
  431. S32 getItemIndex(const LLUUID& item_id) const;
  432. LLScrollListItem* addCommentText(const std::string& comment_text,
  433. EAddPosition pos = ADD_BOTTOM);
  434. LLScrollListItem* addSeparator(EAddPosition pos);
  435. // "Simple" interface: use this when you are creating a list that contains
  436. // only unique strings, only one of which can be selected at a time.
  437. LLScrollListItem* addSimpleElement(const std::string& value,
  438. EAddPosition pos = ADD_BOTTOM,
  439. const LLSD& id = LLSD());
  440. // false if item not found
  441. bool selectItemByLabel(const std::string& item,
  442. bool case_sensitive = true, S32 column = 0);
  443. bool selectItemByPrefix(const std::string& target,
  444. bool case_sensitive = true);
  445. bool selectItemByPrefix(const LLWString& target,
  446. bool case_sensitive = true);
  447. LLScrollListItem* getItemByLabel(const std::string& item,
  448. bool case_sensitive = true,
  449. S32 column = 0) const;
  450. LLScrollListItem* getItemByIndex(S32 index) const;
  451. const std::string getSelectedItemLabel(S32 column = 0) const;
  452. LLSD getSelectedValue();
  453. // DEPRECATED: Use LLSD versions of addCommentText() and getSelectedValue().
  454. // "StringUUID" interface: use this when you are creating a list that
  455. // contains non-unique strings each of which has an associated, unique
  456. // UUID, and only one of which can be selected at a time.
  457. LLScrollListItem* addStringUUIDItem(const std::string& item_text,
  458. const LLUUID& id,
  459. EAddPosition pos = ADD_BOTTOM,
  460. bool enabled = true,
  461. S32 column_width = 0);
  462. LLUUID getStringUUIDSelectedItem() const;
  463. LLScrollListItem* getFirstSelected() const;
  464. S32 getFirstSelectedIndex() const;
  465. std::vector<LLScrollListItem*> getAllSelected() const;
  466. S32 getNumSelected() const;
  467. uuid_vec_t getSelectedIDs();
  468. LL_INLINE LLScrollListItem* getLastSelectedItem() const { return mLastSelected; }
  469. // To iterate over all items
  470. LLScrollListItem* getFirstData() const;
  471. LLScrollListItem* getLastData() const;
  472. std::vector<LLScrollListItem*> getAllData() const;
  473. LLScrollListItem* getItem(const LLSD& sd) const;
  474. LL_INLINE void setAllowMultipleSelection(bool mult) { mAllowMultipleSelection = mult; }
  475. LL_INLINE void setBgWriteableColor(const LLColor4 &c) { mBgWriteableColor = c; }
  476. LL_INLINE void setReadOnlyBgColor(const LLColor4 &c) { mBgReadOnlyColor = c; }
  477. LL_INLINE void setBgSelectedColor(const LLColor4 &c) { mBgSelectedColor = c; }
  478. LL_INLINE void setBgStripeColor(const LLColor4& c) { mBgStripeColor = c; }
  479. LL_INLINE void setFgSelectedColor(const LLColor4 &c) { mFgSelectedColor = c; }
  480. LL_INLINE void setFgUnselectedColor(const LLColor4 &c) { mFgUnselectedColor = c; }
  481. LL_INLINE void setHighlightedColor(const LLColor4 &c) { mHighlightedColor = c; }
  482. LL_INLINE void setFgDisableColor(const LLColor4 &c) { mFgDisabledColor = c; }
  483. LL_INLINE void setBackgroundVisible(bool b) { mBackgroundVisible = b; }
  484. LL_INLINE void setDrawStripes(bool b) { mDrawStripes = b; }
  485. LL_INLINE void setColumnPadding(S32 c) { mColumnPadding = c; }
  486. LL_INLINE S32 getColumnPadding() { return mColumnPadding; }
  487. LL_INLINE void setCommitOnKeyboardMovement(bool b) { mCommitOnKeyboardMovement = b; }
  488. LL_INLINE void setCommitOnSelectionChange(bool b) { mCommitOnSelectionChange = b; }
  489. LL_INLINE void setAllowKeyboardMovement(bool b) { mAllowKeyboardMovement = b; }
  490. LL_INLINE void setMaxSelectable(U32 max_selected) { mMaxSelectable = max_selected; }
  491. LL_INLINE S32 getMaxSelectable() { return mMaxSelectable; }
  492. S32 getScrollPos() const;
  493. void setScrollPos(S32 pos);
  494. void scrollToShowSelected();
  495. S32 getSearchColumn();
  496. LL_INLINE void setSearchColumn(S32 column) { mSearchColumn = column; }
  497. S32 getColumnIndexFromOffset(S32 x);
  498. S32 getColumnOffsetFromIndex(S32 index);
  499. S32 getRowOffsetFromIndex(S32 index);
  500. LL_INLINE void clearSearchString() { mSearchString.clear(); }
  501. // Overridden from LLView
  502. void draw() override;
  503. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  504. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  505. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  506. bool handleHover(S32 x, S32 y, MASK mask) override;
  507. bool handleKeyHere(KEY key, MASK mask) override;
  508. bool handleUnicodeCharHere(llwchar uni_char) override;
  509. bool handleScrollWheel(S32 x, S32 y, S32 clicks) override;
  510. bool handleToolTip(S32 x, S32 y, std::string& msg, LLRect* rect) override;
  511. void setEnabled(bool enabled) override;
  512. void setFocus(bool b) override;
  513. void onFocusReceived() override;
  514. void onFocusLost() override;
  515. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  516. bool isDirty() const override;
  517. void resetDirty() override; // Clears dirty state
  518. void updateLayout();
  519. void fitContents(S32 max_width, S32 max_height);
  520. LLRect getRequiredRect() override;
  521. LL_INLINE LLRect getItemListRect() { return mItemListRect; }
  522. // Used "internally" by the scroll bar.
  523. static void onScrollChange(S32 new_pos, LLScrollbar* src, void* userdata);
  524. static void onClickColumn(void* userdata);
  525. void updateColumns(bool force_update = false);
  526. S32 calcMaxContentWidth();
  527. bool updateColumnWidths();
  528. void setDisplayHeading(bool display);
  529. void setHeadingHeight(S32 heading_height);
  530. LLScrollListItem* hitItem(S32 x,S32 y);
  531. void scrollToShowLast();
  532. // LLEditMenuHandler methods
  533. void copy() override;
  534. bool canCopy() const override;
  535. void cut() override;
  536. bool canCut() const override;
  537. void selectAll() override;
  538. bool canSelectAll() const override;
  539. void deselect() override;
  540. LL_INLINE bool canDeselect() const override { return getCanSelect(); }
  541. LL_INLINE void setNumDynamicColumns(S32 num) { mNumDynamicWidthColumns = num; }
  542. void updateStaticColumnWidth(LLScrollListColumn* col, S32 new_width);
  543. LL_INLINE S32 getTotalStaticColumnWidth() { return mTotalStaticColumnWidth; }
  544. std::string getSortColumnName();
  545. LL_INLINE bool getSortAscending() { return mSortColumns.empty() || mSortColumns.back().second; }
  546. LL_INLINE bool needsSorting() { return !mSortColumns.empty(); }
  547. LL_INLINE bool hasSortOrder() const { return !mSortColumns.empty(); }
  548. LL_INLINE void clearSortOrder() { mSortColumns.clear(); }
  549. S32 selectMultiple(uuid_vec_t ids);
  550. void sortItems();
  551. // Sorts a list without affecting the permanent sort order (so further list
  552. // insertions can be unsorted, for example)
  553. void sortOnce(S32 column, bool ascending);
  554. // Manually call this whenever editing list items in place to flag need for
  555. // resorting
  556. LL_INLINE void setSorted(bool sorted) { mSorted = sorted; }
  557. // Some operation has potentially affected column layout or ordering
  558. void dirtyColumns();
  559. // When passed false, suspends dirty columns refreshing (useful to gain
  560. // time when adding many elements in sequence). Passing true also triggers
  561. // a call to dirtyColumns().
  562. void setAllowRefresh(bool b);
  563. protected:
  564. // "Full" interface: use this when you are creating a list that has one or
  565. // more of the following:
  566. // * contains icons
  567. // * contains multiple columns
  568. // * allows multiple selection
  569. // * has items that are not guarenteed to have unique names
  570. // * has additional per-item data (e.g. a UUID or void* userdata)
  571. //
  572. // To add items using this approach, create new LLScrollListItems and
  573. // LLScrollListCells. Add the cells (column entries) to each item, and add
  574. // the item to the LLScrollListCtrl.
  575. //
  576. // The LLScrollListCtrl owns its items and is responsible for deleting them
  577. // (except in the case that the addItem() call fails, in which case it is
  578. // up to the caller to delete the item)
  579. //
  580. // Returns false if item failed to be added to list, does NOT delete 'item'
  581. bool addItem(LLScrollListItem* item, EAddPosition pos = ADD_BOTTOM,
  582. bool requires_column = true);
  583. typedef std::deque<LLScrollListItem*> item_list;
  584. LL_INLINE item_list& getItemList() { return mItemList; }
  585. private:
  586. void selectPrevItem(bool extend_selection);
  587. void selectNextItem(bool extend_selection);
  588. void drawItems();
  589. void updateLineHeight();
  590. void updateLineHeightInsert(LLScrollListItem* item);
  591. void reportInvalidInput();
  592. bool isRepeatedChars(const LLWString& string) const;
  593. void deselectItem(LLScrollListItem* itemp);
  594. void commitIfChanged();
  595. bool setSort(S32 column, bool ascending);
  596. private:
  597. class LLViewBorder* mBorder;
  598. LLScrollListItem* mLastSelected;
  599. LLScrollbar* mScrollbar;
  600. item_list mItemList;
  601. LLWString mSearchString;
  602. typedef std::map<std::string, LLScrollListColumn> column_map_t;
  603. column_map_t mColumns;
  604. typedef std::vector<LLScrollListColumn*> ordered_columns_t;
  605. ordered_columns_t mColumnsIndexed;
  606. typedef std::pair<S32, bool> sort_column_t;
  607. std::vector<sort_column_t> mSortColumns;
  608. void (*mOnDoubleClickCallback)(void* userdata);
  609. void (*mOnMaximumSelectCallback)(void* userdata);
  610. void (*mOnSortChangedCallback)(void* userdata);
  611. LLFrameTimer mSearchTimer;
  612. LLRect mItemListRect;
  613. LLColor4 mBgWriteableColor;
  614. LLColor4 mBgReadOnlyColor;
  615. LLColor4 mBgSelectedColor;
  616. LLColor4 mBgStripeColor;
  617. LLColor4 mFgSelectedColor;
  618. LLColor4 mFgUnselectedColor;
  619. LLColor4 mFgDisabledColor;
  620. LLColor4 mHighlightedColor;
  621. S32 mLineHeight; // The maximum height of a single line
  622. S32 mScrollLines; // How many lines we have scrolled down
  623. // Max number of lines is it possible to see on the screen given mRect and
  624. // mLineHeight:
  625. S32 mPageLines;
  626. // The height of the column header buttons, if visible:
  627. S32 mHeadingHeight;
  628. U32 mMaxSelectable;
  629. S32 mMaxItemCount;
  630. S32 mColumnPadding;
  631. S32 mBorderThickness;
  632. S32 mHighlightedItem;
  633. S32 mSearchColumn;
  634. S32 mNumDynamicWidthColumns;
  635. S32 mTotalStaticColumnWidth;
  636. S32 mTotalColumnPadding;
  637. S32 mOriginalSelection;
  638. bool mAllowMultipleSelection;
  639. bool mAllowKeyboardMovement;
  640. bool mCommitOnKeyboardMovement;
  641. bool mCommitOnSelectionChange;
  642. bool mSelectionChanged;
  643. bool mNeedsScroll;
  644. bool mCanSelect;
  645. bool mDisplayColumnHeaders;
  646. bool mColumnsDirty;
  647. bool mColumnWidthsDirty;
  648. bool mAllowRefresh;
  649. bool mBackgroundVisible;
  650. bool mDrawStripes;
  651. bool mDirty;
  652. bool mSorted;
  653. };
  654. #endif // LL_SCROLLLISTCTRL_H