llfolderview.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. /**
  2. * @file llfolderview.h
  3. * @brief Definition of the folder view collection of classes.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. // The folder view collection of classes provides an interface for making a
  33. // 'folder view' similar to the way the a single pane file folder interface
  34. // works.
  35. #ifndef LL_LLFOLDERVIEW_H
  36. #define LL_LLFOLDERVIEW_H
  37. #include <deque>
  38. #include <vector>
  39. #include "llcolor4.h"
  40. #include "lleditmenuhandler.h"
  41. #include "llfoldertype.h"
  42. #include "llpanel.h"
  43. #include "lltooldraganddrop.h"
  44. #include "llviewertexture.h"
  45. class LLFolderView;
  46. class LLFolderViewFolder;
  47. class LLFolderViewItem;
  48. class LLFontGL;
  49. class LLInventoryModel;
  50. class LLInventoryObserver;
  51. class LLInventoryPanel;
  52. class LLInvFVBridge;
  53. class LLLineEditor;
  54. class LLMenuGL;
  55. class LLScrollableContainer;
  56. class LLUICtrl;
  57. class LLUICtrlFactory;
  58. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. // Class LLFolderViewEventListener
  60. //
  61. // This is an abstract base class that users of the folderview classes would
  62. // use to catch the useful events emitted from the folder views.
  63. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. class LLFolderViewEventListener
  65. {
  66. protected:
  67. LOG_CLASS(LLFolderViewEventListener);
  68. public:
  69. virtual ~LLFolderViewEventListener() = default;
  70. virtual const std::string& getName() const = 0;
  71. virtual const std::string& getDisplayName() const = 0;
  72. virtual const LLUUID& getUUID() const = 0;
  73. virtual time_t getCreationDate() const = 0; // UTC seconds
  74. virtual PermissionMask getPermissionMask() const = 0;
  75. virtual LLFolderType::EType getPreferredType() const = 0;
  76. virtual LLUIImagePtr getIcon() const = 0;
  77. virtual LLFontGL::StyleFlags getLabelStyle() const = 0;
  78. virtual std::string getLabelSuffix() const = 0;
  79. virtual void openItem() = 0;
  80. virtual void previewItem() = 0;
  81. virtual void selectItem() = 0;
  82. virtual void showProperties() = 0;
  83. virtual bool isItemRenameable() const = 0;
  84. virtual bool renameItem(const std::string& new_name) = 0;
  85. virtual bool isItemMovable() = 0; // Can be moved to another folder
  86. virtual bool isItemRemovable() = 0; // Can be destroyed
  87. virtual bool removeItem() = 0;
  88. virtual void removeBatch(std::vector<LLFolderViewEventListener*>& batch) = 0;
  89. virtual void move(LLFolderViewEventListener* parent_listener) = 0;
  90. virtual bool isItemCopyable() const = 0;
  91. virtual bool copyToClipboard() const = 0;
  92. virtual bool cutToClipboard() const = 0;
  93. virtual bool isClipboardPasteable() const = 0;
  94. virtual void pasteFromClipboard() = 0;
  95. virtual void pasteLinkFromClipboard() = 0;
  96. virtual void buildContextMenu(LLMenuGL& menu, U32 flags) = 0;
  97. virtual bool isUpToDate() const = 0;
  98. LL_INLINE virtual bool hasChildren() const { return false; }
  99. virtual LLInventoryType::EType getInventoryType() const = 0;
  100. virtual S32 getSubType() const = 0;
  101. LL_INLINE virtual void performAction(LLFolderView* folderp,
  102. LLInventoryModel* modelp,
  103. const std::string& action)
  104. {
  105. }
  106. // This method should be called when a drag begins. Returns true if the
  107. // drag can begin, otherwise false.
  108. virtual bool startDrag(EDragAndDropType* type, LLUUID* id) const = 0;
  109. // This method will be called to determine if a drop can be performed, and
  110. // will set drop to true if a drop is requested. Returns true if a drop is
  111. // possible/happened, otherwise false.
  112. virtual bool dragOrDrop(MASK mask, bool drop,
  113. EDragAndDropType cargo_type,
  114. void* cargo_data, std::string& tooltip_msg) = 0;
  115. // This method accesses the parent and arranges and sets it as specified.
  116. void arrangeAndSet(LLFolderViewItem* focusp, bool set_selection,
  117. bool take_keyboard_focus = true);
  118. // Cancels any existing tip. May be called with not_drop_msg = true to
  119. // cancel only drag-related message tips (but not drop-related ones).
  120. static void cancelTip(bool not_drop_msg = false);
  121. // This static method should be called after each call to dragOrDrop() so
  122. // to deal with tooltip_msg displaying (as notification tips) at the
  123. // folder view level.
  124. static void dragOrDropTip(bool drop, const std::string& tooltip_msg);
  125. private:
  126. static LLUUID sLastDragTipID;
  127. static std::string sLastDragTipMsg;
  128. // true when last message came from a drop event:
  129. static bool sLastDragTipDrop;
  130. };
  131. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132. // Class LLFolderViewListenerFunctor
  133. //
  134. // This simple abstract base class can be used to applied to all listeners in a
  135. // hierarchy.
  136. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137. class LLFolderViewListenerFunctor
  138. {
  139. public:
  140. virtual ~LLFolderViewListenerFunctor() = default;
  141. virtual void operator()(LLFolderViewEventListener* listener) = 0;
  142. };
  143. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144. // Class LLFolderViewFunctor
  145. //
  146. // Simple abstract base class for applying a functor to folders and items in a
  147. // folder view hierarchy. This is suboptimal for algorithms that only work
  148. // folders or only work on items, but I'll worry about that later when it's
  149. // determined to be too slow.
  150. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151. class LLFolderViewFunctor
  152. {
  153. public:
  154. virtual ~LLFolderViewFunctor() = default;
  155. virtual void doFolder(LLFolderViewFolder* folder) = 0;
  156. virtual void doItem(LLFolderViewItem* item) = 0;
  157. };
  158. class LLSelectFirstFilteredItem final : public LLFolderViewFunctor
  159. {
  160. public:
  161. LL_INLINE LLSelectFirstFilteredItem()
  162. : mItemSelected(false)
  163. {
  164. }
  165. void doFolder(LLFolderViewFolder* folder) override;
  166. void doItem(LLFolderViewItem* item) override;
  167. LL_INLINE bool wasItemSelected() { return mItemSelected; }
  168. protected:
  169. bool mItemSelected;
  170. };
  171. class LLSaveFolderState final : public LLFolderViewFunctor
  172. {
  173. public:
  174. LL_INLINE LLSaveFolderState()
  175. : mApply(false)
  176. {
  177. }
  178. void doFolder(LLFolderViewFolder* folder) override;
  179. LL_INLINE void doItem(LLFolderViewItem*) override {}
  180. void setApply(bool apply);
  181. LL_INLINE void clearOpenFolders() { mOpenFolders.clear(); }
  182. protected:
  183. std::set<LLUUID> mOpenFolders;
  184. bool mApply;
  185. };
  186. class LLOpenFilteredFolders final : public LLFolderViewFunctor
  187. {
  188. public:
  189. LLOpenFilteredFolders() = default;
  190. void doFolder(LLFolderViewFolder* folder) override;
  191. void doItem(LLFolderViewItem* item) override;
  192. };
  193. class LLOpenFoldersWithSelection final : public LLFolderViewFunctor
  194. {
  195. public:
  196. LLOpenFoldersWithSelection() = default;
  197. void doFolder(LLFolderViewFolder* folder) override;
  198. void doItem(LLFolderViewItem* item) override;
  199. };
  200. class LLOpenFolderByID final : public LLFolderViewFunctor
  201. {
  202. public:
  203. LL_INLINE LLOpenFolderByID(const LLUUID& id)
  204. : mID(id)
  205. {
  206. }
  207. void doFolder(LLFolderViewFolder* folder) override;
  208. // Do nothing
  209. LL_INLINE void doItem(LLFolderViewItem*) override {}
  210. protected:
  211. const LLUUID& mID;
  212. };
  213. class LLInventoryFilter
  214. {
  215. protected:
  216. LOG_CLASS(LLInventoryFilter);
  217. public:
  218. typedef enum e_folder_show
  219. {
  220. SHOW_ALL_FOLDERS,
  221. SHOW_NON_EMPTY_FOLDERS,
  222. SHOW_NO_FOLDERS
  223. } EFolderShow;
  224. typedef enum e_filter_behavior
  225. {
  226. // Nothing to do, already filtered
  227. FILTER_NONE,
  228. // Restart filtering from scratch
  229. FILTER_RESTART,
  230. // Existing filtered items will certainly pass this filter
  231. FILTER_LESS_RESTRICTIVE,
  232. // If you did not pass the previous filter, you definitely woiuld not
  233. // pass this one
  234. FILTER_MORE_RESTRICTIVE
  235. } EFilterBehavior;
  236. static constexpr U32 SO_DATE = 1;
  237. static constexpr U32 SO_FOLDERS_BY_NAME = 2;
  238. static constexpr U32 SO_SYSTEM_FOLDERS_TO_TOP = 4;
  239. LLInventoryFilter(const std::string& name);
  240. virtual ~LLInventoryFilter() = default;
  241. void setFilterTypes(U32 types);
  242. LL_INLINE U32 getFilterTypes() const { return mFilterOps.mFilterTypes; }
  243. void setFilterSubString(const std::string& string);
  244. LL_INLINE const std::string getFilterSubString(bool trim = false)
  245. {
  246. return mFilterSubString;
  247. }
  248. LL_INLINE void setFilterHideLibrary(bool hide) { mHideLibrary = hide; }
  249. LL_INLINE void setFilterSubType(S32 subtype) { mFilterSubType = subtype; }
  250. LL_INLINE bool getFilterSubType() const { return mFilterSubType; }
  251. LL_INLINE void setFilterWorn(bool worn) { mFilterWorn = worn; }
  252. LL_INLINE bool getFilterWorn() const { return mFilterWorn; }
  253. LL_INLINE void setFilterLastOpen(bool b) { mFilterLastOpen = b; }
  254. LL_INLINE bool getFilterLastOpen() const { return mFilterLastOpen; }
  255. LL_INLINE void setFilterShowLinks(bool b) { mFilterShowLinks = b; }
  256. LL_INLINE bool getFilterShowLinks() const { return mFilterShowLinks; }
  257. void setFilterPermissions(PermissionMask perms);
  258. LL_INLINE PermissionMask getFilterPermissions() const
  259. {
  260. return mFilterOps.mPermissions;
  261. }
  262. void setDateRange(time_t min_date, time_t max_date);
  263. void setDateRangeLastLogoff(bool sl);
  264. LL_INLINE time_t getMinDate() const { return mFilterOps.mMinDate; }
  265. LL_INLINE time_t getMaxDate() const { return mFilterOps.mMaxDate; }
  266. void setHoursAgo(U32 hours);
  267. LL_INLINE U32 getHoursAgo() const { return mFilterOps.mHoursAgo; }
  268. void setShowFolderState(EFolderShow state);
  269. LL_INLINE EFolderShow getShowFolderState() { return mFilterOps.mShowFolderState; }
  270. void setSortOrder(U32 order);
  271. LL_INLINE U32 getSortOrder() { return mOrder; }
  272. bool check(LLFolderViewItem* item);
  273. LL_INLINE size_t getStringMatchOffset() const { return mSubStringMatchOffset; }
  274. bool isActive();
  275. bool isNotDefault();
  276. LL_INLINE bool isModified() { return mModified; }
  277. LL_INLINE void clearModified()
  278. {
  279. mModified = false;
  280. mFilterBehavior = FILTER_NONE;
  281. }
  282. LL_INLINE bool isModifiedAndClear()
  283. {
  284. bool ret = mModified;
  285. mModified = false;
  286. return ret;
  287. }
  288. bool isSinceLogoff();
  289. LL_INLINE const std::string getName() const { return mName; }
  290. std::string getFilterText();
  291. void setFilterCount(S32 count) { mFilterCount = count; }
  292. LL_INLINE S32 getFilterCount() { return mFilterCount; }
  293. LL_INLINE void decrementFilterCount() { --mFilterCount; }
  294. void markDefault();
  295. void resetDefault();
  296. bool isFilterWith(LLInventoryType::EType t);
  297. LL_INLINE S32 getCurrentGeneration() const { return mFilterGeneration; }
  298. LL_INLINE S32 getMinRequiredGeneration() const { return mMinRequiredGeneration; }
  299. LL_INLINE S32 getMustPassGeneration() const { return mMustPassGeneration; }
  300. // RN: this is public to allow system to externally force a global
  301. // re-filter
  302. void setModified(EFilterBehavior behavior = FILTER_RESTART);
  303. void setLastOpenID(const LLUUID& folder_id) { mLastOpenID = folder_id; }
  304. void toLLSD(LLSD& data);
  305. void fromLLSD(LLSD& data);
  306. private:
  307. LLUUID mLastOpenID;
  308. std::string mFilterText;
  309. U32 mLastLogoff;
  310. bool mModified;
  311. bool mNeedTextRebuild;
  312. protected:
  313. U32 mOrder;
  314. S32 mFilterGeneration;
  315. S32 mMustPassGeneration;
  316. S32 mMinRequiredGeneration;
  317. S32 mFilterCount;
  318. S32 mNextFilterGeneration;
  319. EFilterBehavior mFilterBehavior;
  320. struct filter_ops
  321. {
  322. U32 mFilterTypes;
  323. time_t mMinDate;
  324. time_t mMaxDate;
  325. U32 mHoursAgo;
  326. EFolderShow mShowFolderState;
  327. PermissionMask mPermissions;
  328. };
  329. filter_ops mFilterOps;
  330. filter_ops mDefaultFilterOps;
  331. size_t mSubStringMatchOffset;
  332. std::string mFilterSubString;
  333. const std::string mName;
  334. S32 mFilterSubType;
  335. bool mHideLibrary;
  336. bool mFilterWorn;
  337. bool mFilterLastOpen;
  338. bool mFilterShowLinks;
  339. };
  340. // These are grouping of inventory types. Order matters when sorting system
  341. // folders to the top.
  342. enum EInventorySortGroup
  343. {
  344. SG_SYSTEM_FOLDER,
  345. SG_TRASH_FOLDER,
  346. SG_NORMAL_FOLDER,
  347. SG_ITEM
  348. };
  349. class LLInventorySort
  350. {
  351. public:
  352. LLInventorySort()
  353. : mSortOrder(0),
  354. mByDate(false),
  355. mSystemToTop(false),
  356. mFoldersByName(false)
  357. {
  358. }
  359. // Returns true if order has changed
  360. bool updateSort(U32 order);
  361. LL_INLINE U32 getSort() { return mSortOrder; }
  362. bool operator()(const LLFolderViewItem* const& a,
  363. const LLFolderViewItem* const& b);
  364. private:
  365. U32 mSortOrder;
  366. bool mByDate;
  367. bool mSystemToTop;
  368. bool mFoldersByName;
  369. };
  370. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  371. // Class LLFolderViewItem
  372. //
  373. // An instance of this class represents a single item in a folder view
  374. // such as an inventory item or a file.
  375. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  376. class LLFolderViewItem : public LLUICtrl
  377. {
  378. friend class LLFolderViewEventListener;
  379. protected:
  380. LOG_CLASS(LLFolderViewItem);
  381. // Helper method to change the selection from the root.
  382. void changeSelectionFromRoot(LLFolderViewItem* selection, bool selected);
  383. // Helper method to change the selection from the root.
  384. void extendSelectionFromRoot(LLFolderViewItem* selection);
  385. // This is an internal method used for adding items to folders. A no-op at
  386. // this level, but reimplemented in derived classes.
  387. virtual bool addItem(LLFolderViewItem*) { return false; }
  388. virtual bool addFolder(LLFolderViewFolder*) { return false; }
  389. public:
  390. // This method clears the currently selected item and records the specified
  391. // selected item appropriately for display and use in the UI. If 'openitem'
  392. // is true, then folders are opened up along the way to the selection.
  393. void setSelectionFromRoot(LLFolderViewItem* selection, bool openitem,
  394. bool take_keyboard_focus = true);
  395. static void initClass();
  396. static void cleanupClass();
  397. static void refreshCachedSettings();
  398. // This method is called when the folder view is dirty. It is implemented
  399. // here but called by derived classes when folding the views.
  400. void arrangeFromRoot();
  401. void filterFromRoot();
  402. // Note: 'creation_date' is in UTC seconds
  403. LLFolderViewItem(const std::string& name, LLUIImagePtr icon,
  404. S32 creation_date, LLFolderView* root,
  405. LLFolderViewEventListener* listener);
  406. virtual ~LLFolderViewItem();
  407. // Returns true on success, false otherwise
  408. virtual bool addToFolder(LLFolderViewFolder* folder, LLFolderView* root);
  409. virtual EInventorySortGroup getSortGroup() const;
  410. // Finds width and height of this object and it's children. Also makes sure
  411. // that this view and it's children are the right size.
  412. virtual S32 arrange(S32* width, S32* height, S32 filter_generation);
  413. virtual S32 getItemHeight();
  414. // Applies filters to control visibility of inventory items
  415. virtual void filter(LLInventoryFilter& filter);
  416. // Updates filter serial number and optionally propagated value up to root
  417. LL_INLINE S32 getLastFilterGeneration() { return mLastFilterGeneration; }
  418. virtual void dirtyFilter();
  419. // If 'selection' is 'this' then note that otherwise ignore.
  420. // Returns true if this item ends up being selected.
  421. virtual bool setSelection(LLFolderViewItem* selection, bool openitem,
  422. bool take_keyboard_focus);
  423. // This method is used to set the selection state of an item.
  424. // If 'selection' is 'this' then note selection.
  425. // Returns true if the selection state of this item was changed.
  426. virtual bool changeSelection(LLFolderViewItem* selection, bool selected);
  427. // This method is used to group select items
  428. virtual void extendSelection(LLFolderViewItem* selection,
  429. LLFolderViewItem* last_selected,
  430. std::vector<LLFolderViewItem*>& items)
  431. {
  432. }
  433. // This method is used to deselect this element
  434. void deselectItem();
  435. // This method is used to select this element
  436. void selectItem();
  437. // Gets multiple-element selection in an UUID set
  438. LL_INLINE virtual bool getSelectionList(uuid_list_t& selection)
  439. {
  440. return true;
  441. }
  442. // Gets multiple-element selection in an UUID vector
  443. LL_INLINE virtual bool getSelection(uuid_vec_t& selection)
  444. {
  445. return true;
  446. }
  447. // Returns true is this object and all of its children can be removed
  448. // (deleted by user)
  449. virtual bool isRemovable();
  450. // Returns true is this object and all of its children can be moved
  451. virtual bool isMovable();
  452. // destroys this item recursively
  453. virtual void destroyView();
  454. LL_INLINE bool isSelected() const { return mIsSelected; }
  455. LL_INLINE void setIsCurSelection(bool select) { mIsCurSelection = select; }
  456. LL_INLINE bool getIsCurSelection() { return mIsCurSelection; }
  457. LL_INLINE void disableDoubleClick(bool b = true) { mDoubleClickDisabled = b; }
  458. LL_INLINE bool hasVisibleChildren() { return mHasVisibleChildren; }
  459. #if 0
  460. // Call through to the viewed object and return true if it can be removed.
  461. // Returns true if it is removed.
  462. virtual bool removeRecursively(bool single_item);
  463. #endif
  464. bool remove();
  465. // Build an appropriate context menu for the item. Flags unused.
  466. void buildContextMenu(LLMenuGL& menu, U32 flags);
  467. // This method returns the actual name of the thing being viewed. This
  468. // method will ask the viewed object itself.
  469. std::string getName() const override;
  470. std::string getSearchableData();
  471. // This method returns the label displayed on the view. This
  472. // method was primarily added to allow sorting on the folder
  473. // contents possible before the entire view has been constructed.
  474. LL_INLINE const std::string& getLabel() const { return mLabel; }
  475. // Used for sorting, like getLabel() above.
  476. LL_INLINE virtual time_t getCreationDate() const { return mCreationDate; }
  477. LL_INLINE LLFolderViewFolder* getParentFolder() { return mParentFolder; }
  478. LL_INLINE const LLFolderViewFolder* getParentFolder() const
  479. {
  480. return mParentFolder;
  481. }
  482. LLFolderViewItem* getNextOpenNode(bool include_children = true);
  483. LLFolderViewItem* getPreviousOpenNode(bool include_children = true);
  484. LL_INLINE const LLFolderViewEventListener* getListener() const
  485. {
  486. return mListener;
  487. }
  488. LL_INLINE LLFolderViewEventListener* getListener() { return mListener; }
  489. // Renames the object.
  490. void rename(const std::string& new_name);
  491. virtual void openItem();
  492. virtual void preview();
  493. // Show children (unfortunate that this is called "open")
  494. LL_INLINE virtual void setOpen(bool open = true) {}
  495. LL_INLINE virtual bool isOpen() { return false; }
  496. LL_INLINE LLFolderView* getRoot() { return mRoot; }
  497. bool isDescendantOf(const LLFolderViewFolder* potential_ancestor);
  498. LL_INLINE S32 getIndentation() { return mIndentation; }
  499. // Do we know for a fact that this item has been filtered out ?
  500. virtual bool potentiallyVisible();
  501. virtual bool getFiltered();
  502. virtual bool getFiltered(S32 filter_generation);
  503. virtual void setFiltered(bool filtered, S32 filter_generation);
  504. // Changes the icon
  505. LL_INLINE void setIcon(LLUIImagePtr icon) { mIcon = icon; }
  506. // Refreshes information from the object being viewed.
  507. void refreshFromListener();
  508. virtual void refresh();
  509. virtual void applyListenerFunctorRecursively(LLFolderViewListenerFunctor& functor);
  510. // LLView functionality
  511. bool handleRightMouseDown(S32 x, S32 y, MASK mask) override;
  512. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  513. bool handleHover(S32 x, S32 y, MASK mask) override;
  514. bool handleMouseUp(S32 x, S32 y, MASK mask) override;
  515. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  516. bool handleScrollWheel(S32 x, S32 y, S32 clicks) override;
  517. void draw() override;
  518. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  519. EDragAndDropType cargo_type, void* cargo_data,
  520. EAcceptance* accept, std::string& tooltip) override;
  521. private:
  522. static void connectRefreshCachedSettingsSafe(const char* name);
  523. // Returns the font to use to render and adjust the style if necessary
  524. // (avoids making up artificially, from the default font, bold and italic
  525. // fonts when they exist). HB
  526. const LLFontGL* getRenderFont(U32& style);
  527. protected:
  528. LLFolderView* mRoot;
  529. LLFolderViewFolder* mParentFolder;
  530. LLFolderViewEventListener* mListener;
  531. LLUIImagePtr mIcon;
  532. LLTimer mTimeSinceRequestStart;
  533. size_t mStringMatchOffset;
  534. S32 mIndentation;
  535. S32 mLastFilterGeneration;
  536. U32 mCreationDate;
  537. F32 mControlLabelRotation;
  538. S32 mLabelWidth;
  539. LLFontGL::StyleFlags mLabelStyle;
  540. std::string mLabel;
  541. LLWString mWLabel;
  542. std::string mSearchableLabel;
  543. std::string mSearchableDesc;
  544. std::string mSearchableCreator;
  545. std::string mType;
  546. std::string mLabelSuffix;
  547. LLWString mWLabelSuffix;
  548. bool mHasDescription;
  549. bool mIsCurSelection;
  550. bool mSelectPending;
  551. bool mHasVisibleChildren;
  552. bool mFiltered;
  553. bool mDragAndDropTarget;
  554. bool mIsLoading;
  555. static const LLFontGL* sFont;
  556. static const LLFontGL* sFontItalic;
  557. static F32 sFontLineHeight;
  558. static S32 sFontLineHeightRounded;
  559. static LLColor4 sFgColor;
  560. static LLColor4 sHighlightBgColor;
  561. static LLColor4 sHighlightFgColor;
  562. static LLColor4 sContextMenuBgColor;
  563. static LLColor4 sFilterBGColor;
  564. static LLColor4 sFilterTextColor;
  565. static LLColor4 sSuffixColor;
  566. static LLColor4 sSearchStatusColor;
  567. static LLUIImagePtr sArrowImage;
  568. static LLWString sLoadingStr;
  569. private:
  570. bool mIsSelected;
  571. bool mDoubleClickDisabled;
  572. };
  573. // function used for sorting.
  574. typedef bool (*sort_order_f)(LLFolderViewItem* a, LLFolderViewItem* b);
  575. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  576. // Class LLFolderViewFolder
  577. //
  578. // An instance of an LLFolderViewFolder represents a collection of
  579. // more folders and items. This is used to build the hierarchy of
  580. // items found in the folder view. :)
  581. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  582. class LLFolderViewFolder : public LLFolderViewItem
  583. {
  584. protected:
  585. LOG_CLASS(LLFolderViewFolder);
  586. public:
  587. typedef enum e_recurse_type
  588. {
  589. RECURSE_NO,
  590. RECURSE_UP,
  591. RECURSE_DOWN,
  592. RECURSE_UP_DOWN
  593. } ERecurseType;
  594. LLFolderViewFolder(const std::string& name, LLUIImagePtr icon,
  595. LLFolderView* rootp,
  596. LLFolderViewEventListener* listenerp);
  597. ~LLFolderViewFolder() override;
  598. bool potentiallyVisible() override;
  599. LLFolderViewItem* getNextFromChild(LLFolderViewItem*,
  600. bool include_children = true);
  601. LLFolderViewItem* getPreviousFromChild(LLFolderViewItem*,
  602. bool include_children = true);
  603. // Returns true on success, false otherwise
  604. bool addToFolder(LLFolderViewFolder* folderp,
  605. LLFolderView* rootp) override;
  606. // Finds width and height of this object and it's children. Also makes sure
  607. // that this view and it's children are the right size.
  608. S32 arrange(S32* width, S32* height, S32 filter_generation) override;
  609. bool needsArrange();
  610. // Returns the sort group (system, trash, folder) for this folder.
  611. EInventorySortGroup getSortGroup() const override;
  612. virtual void setCompletedFilterGeneration(S32 generation, bool recurse_up);
  613. LL_INLINE virtual S32 getCompletedFilterGeneration()
  614. {
  615. return mCompletedFilterGeneration;
  616. }
  617. bool hasFilteredDescendants(S32 filter_generation);
  618. bool hasFilteredDescendants();
  619. void recursiveIncrementNumDescendantsSelected(S32 increment);
  620. LL_INLINE S32 numSelected() const
  621. {
  622. return mNumDescendantsSelected + (isSelected() ? 1 : 0);
  623. }
  624. // Applies filters to control visibility of inventory items
  625. void filter(LLInventoryFilter& filter) override;
  626. void setFiltered(bool filtered, S32 filter_generation) override;
  627. void dirtyFilter() override;
  628. // Passes selection information on to children and record selection
  629. // information if necessary. Returns true if this object (or a child) ends
  630. // up being selected. If 'openitem' is true then folders are opened up
  631. // along the way to the selection.
  632. bool setSelection(LLFolderViewItem* selection, bool openitem,
  633. bool take_keyboard_focus) override;
  634. // This method is used to change the selection of an item. Recursively
  635. // traverses all children; if 'selection' is 'this' then change the select
  636. // status if necessary. Returns true if the selection state of this folder,
  637. // or of a child, was changed.
  638. bool changeSelection(LLFolderViewItem* selection, bool selected) override;
  639. // This method is used to group select items
  640. void extendSelection(LLFolderViewItem* selection,
  641. LLFolderViewItem* last_selected,
  642. std::vector<LLFolderViewItem*>& items) override;
  643. // Deselects this folder and all folder/items it contains recursively.
  644. void recursiveDeselect(bool deselect_self);
  645. // Returns true is this object and all of its children can be removed.
  646. bool isRemovable() override;
  647. // Returns true is this object and all of its children can be moved
  648. bool isMovable() override;
  649. // Destroys this folder, and all children
  650. void destroyView() override;
  651. #if 0
  652. // If this folder can be removed, remove all children that can be removed,
  653. // returns true if this is empty after the operation and its viewed folder
  654. // object can be removed.
  655. virtual bool removeRecursively(bool single_item);
  656. virtual bool remove();
  657. #endif
  658. // Removee the specified item (and any children) if possible. Returns true
  659. // if the item was deleted.
  660. bool removeItem(LLFolderViewItem* item);
  661. // Simply removes the view (and any children) Doesn't bother telling the
  662. // listeners.
  663. void removeView(LLFolderViewItem* item);
  664. // Removes the specified item from the folder, but does not delete it.
  665. void extractItem(LLFolderViewItem* item);
  666. // Called by a child that needs to be resorted.
  667. void resort(LLFolderViewItem* item);
  668. void setItemSortOrder(U32 ordering);
  669. void sortBy(U32);
  670. LL_INLINE void setRegisterLastOpen(bool b) { mRegisterLastOpen = b; }
  671. LL_INLINE void setAutoOpenCountdown(F32 countdown) { mAutoOpenCountdown = countdown; }
  672. // Folders can be opened. This will usually be called by internal methods.
  673. virtual void toggleOpen();
  674. // Forces a folder open or closed
  675. void setOpen(bool openitem = true) override;
  676. // Called when a child is refreshed but does not rearrange child folder
  677. // contents unless explicitly requested
  678. virtual void requestArrange(bool include_descendants = false);
  679. // Internal method which doesn't update the entire view. This method was
  680. // written because the list iterators destroy the state of other
  681. // iterations, thus, we cannot arrange while iterating through the children
  682. // (such as when setting which is selected.
  683. virtual void setOpenArrangeRecursively(bool openitem,
  684. ERecurseType recurse = RECURSE_NO);
  685. // Gets the current state of the folder.
  686. LL_INLINE bool isOpen() override { return mIsOpen; }
  687. // Special case if an object is dropped on the child.
  688. bool handleDragAndDropFromChild(MASK mask, bool drop,
  689. EDragAndDropType cargo_type,
  690. void* cargo_data, EAcceptance* accept,
  691. std::string& tooltip_msg);
  692. void applyFunctorRecursively(LLFolderViewFunctor& functor);
  693. void applyListenerFunctorRecursively(LLFolderViewListenerFunctor& functor) override;
  694. void openItem() override;
  695. bool addItem(LLFolderViewItem* item) override;
  696. bool addFolder(LLFolderViewFolder* folder) override;
  697. // LLView functionality
  698. bool handleHover(S32 x, S32 y, MASK mask) override;
  699. bool handleRightMouseDown(S32 x, S32 y, MASK mask) override;
  700. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  701. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  702. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  703. EDragAndDropType cargo_type, void* cargo_data,
  704. EAcceptance* accept, std::string& tooltip) override;
  705. void draw() override;
  706. time_t getCreationDate() const override;
  707. bool isTrash() const;
  708. bool isCOF() const;
  709. bool isMarketplace() const;
  710. LL_INLINE S32 getNumSelectedDescendants() const { return mNumDescendantsSelected; }
  711. public:
  712. static LLUUID sLastOpenId;
  713. private:
  714. S32 mNumDescendantsSelected;
  715. protected:
  716. typedef std::list<LLFolderViewItem*> items_t;
  717. items_t mItems;
  718. typedef std::list<LLFolderViewFolder*> folders_t;
  719. folders_t mFolders;
  720. LLInventorySort mSortFunction;
  721. F32 mCurHeight;
  722. F32 mTargetHeight;
  723. F32 mAutoOpenCountdown;
  724. time_t mSubtreeCreationDate;
  725. S32 mLastArrangeGeneration;
  726. S32 mLastCalculatedWidth;
  727. S32 mCompletedFilterGeneration;
  728. S32 mMostFilteredDescendantGeneration;
  729. mutable S32 mAmTrash;
  730. mutable S32 mAmCOF;
  731. mutable S32 mAmMarket;
  732. bool mIsOpen;
  733. bool mRegisterLastOpen;
  734. bool mForceFetched;
  735. };
  736. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  737. // LLDepthStack template. Used to be in its own llcommon/lldepthstack.h header,
  738. // but is only used here... HB
  739. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  740. template <class DATA_TYPE> class LLDepthStack
  741. {
  742. public:
  743. LL_INLINE LLDepthStack()
  744. : mCurrentDepth(0),
  745. mMaxDepth(0)
  746. {
  747. }
  748. LL_INLINE void setDepth(U32 depth) { mMaxDepth = depth; }
  749. LL_INLINE U32 getDepth() const { return mCurrentDepth; }
  750. LL_INLINE void push(DATA_TYPE* data)
  751. {
  752. if (mCurrentDepth < mMaxDepth)
  753. {
  754. mStack.push_back(data);
  755. ++mCurrentDepth;
  756. }
  757. else
  758. {
  759. // The last item falls off stack and is deleted
  760. if (!mStack.empty())
  761. {
  762. mStack.pop_front();
  763. }
  764. mStack.push_back(data);
  765. }
  766. }
  767. LL_INLINE DATA_TYPE* pop()
  768. {
  769. DATA_TYPE* tempp = NULL;
  770. if (!mStack.empty())
  771. {
  772. tempp = mStack.back();
  773. mStack.pop_back();
  774. --mCurrentDepth;
  775. }
  776. return tempp;
  777. }
  778. LL_INLINE DATA_TYPE* check()
  779. {
  780. return mStack.empty() ? NULL : mStack.back();
  781. }
  782. LL_INLINE void removeAllNodes()
  783. {
  784. mCurrentDepth = 0;
  785. mStack.clear();
  786. }
  787. private:
  788. std::deque<DATA_TYPE*> mStack;
  789. U32 mCurrentDepth;
  790. U32 mMaxDepth;
  791. };
  792. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  793. // Class LLFolderView
  794. //
  795. // The LLFolderView represents the root level folder view object. It manages
  796. // the screen region of the folder view.
  797. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  798. class LLFolderView : public LLFolderViewFolder, LLEditMenuHandler
  799. {
  800. protected:
  801. LOG_CLASS(LLFolderView);
  802. public:
  803. typedef std::deque<LLFolderViewItem*> selected_items_t;
  804. typedef void (*selection_cb_t)(LLFolderView* folderp, bool user_action,
  805. void* userdata);
  806. LLFolderView(const std::string& name, LLUIImagePtr root_folder_icon,
  807. const LLRect& rect, const LLUUID& source_id,
  808. LLPanel* parent_panel);
  809. ~LLFolderView() override;
  810. static LLFolderView* getInstance(const LLUUID& id);
  811. LL_INLINE bool canFocusChildren() const override { return false; }
  812. // FolderViews default to sort by name. This will change that and resort
  813. // the items if necessary.
  814. void setSortOrder(U32 order);
  815. void checkTreeResortForModelChanged();
  816. LL_INLINE void setFilterPermMask(PermissionMask filter_perm_mask)
  817. {
  818. mFilter.setFilterPermissions(filter_perm_mask);
  819. }
  820. LL_INLINE void setSelectCallback(selection_cb_t callback, void* userdata)
  821. {
  822. mSelectCallback = callback;
  823. mUserData = userdata;
  824. }
  825. LL_INLINE void setAllowMultiSelect(bool allow) { mAllowMultiSelect = allow; }
  826. LL_INLINE LLInventoryFilter* getFilter() { return &mFilter; }
  827. const std::string getFilterSubString(bool trim = false);
  828. LL_INLINE bool getFilterWorn() const { return mFilter.getFilterWorn(); }
  829. LL_INLINE bool getFilterLastOpen() const { return mFilter.getFilterLastOpen(); }
  830. LL_INLINE bool getFilterShowLinks() const { return mFilter.getFilterShowLinks(); }
  831. LL_INLINE U32 getFilterTypes() const { return mFilter.getFilterTypes(); }
  832. LL_INLINE PermissionMask getFilterPermissions() const
  833. {
  834. return mFilter.getFilterPermissions();
  835. }
  836. LL_INLINE LLInventoryFilter::EFolderShow getShowFolderState()
  837. {
  838. return mFilter.getShowFolderState();
  839. }
  840. U32 getSortOrder() const;
  841. LL_INLINE bool isFilterModified() { return mFilter.isNotDefault(); }
  842. LL_INLINE bool getAllowMultiSelect() { return mAllowMultiSelect; }
  843. U32 toggleSearchType(std::string toggle);
  844. U32 getSearchType() const;
  845. // Closes all folders in the view
  846. void closeAllFolders();
  847. void openFolder(const std::string& foldername);
  848. void openFolder(const LLUUID& cat_id);
  849. LL_INLINE void toggleOpen() override {}
  850. void setOpenArrangeRecursively(bool open, ERecurseType recurse) override;
  851. bool addFolder(LLFolderViewFolder* folder) override;
  852. // Finds width and height of this object and it's children. Also
  853. // makes sure that this view and it's children are the right size.
  854. S32 arrange(S32* width, S32* height, S32 filter_generation) override;
  855. LL_INLINE void arrangeAll() { ++mArrangeGeneration; }
  856. LL_INLINE S32 getArrangeGeneration() { return mArrangeGeneration; }
  857. // Applies filters to control visibility of inventory items
  858. void filter(LLInventoryFilter& filter) override;
  859. // Get the last selected item
  860. virtual LLFolderViewItem* getCurSelectedItem();
  861. // Record the selected item and pass it down the hierachy.
  862. bool setSelection(LLFolderViewItem* selection, bool openitem,
  863. bool take_keyboard_focus) override;
  864. // This method is used to toggle the selection of an item. Walks children
  865. // and keeps track of selected objects.
  866. bool changeSelection(LLFolderViewItem* selection, bool selected) override;
  867. void extendSelection(LLFolderViewItem* selection,
  868. LLFolderViewItem* last_selected,
  869. std::vector<LLFolderViewItem*>& items) override;
  870. bool getSelectionList(uuid_list_t& selection) override;
  871. bool getSelection(uuid_vec_t& selection) override;
  872. // Makes sure if ancestor is selected, descendents are not:
  873. void sanitizeSelection();
  874. void clearSelection();
  875. void addToSelectionList(LLFolderViewItem* item);
  876. void removeFromSelectionList(LLFolderViewItem* item);
  877. bool startDrag(LLToolDragAndDrop::ESource source);
  878. LL_INLINE void setDragAndDropThisFrame() { mDragAndDropThisFrame = true; }
  879. LL_INLINE void setShowThumbnails(bool b = true) { mShowThumbnails = b; }
  880. LL_INLINE bool showThumbnails() const { return mShowThumbnails; }
  881. LL_INLINE void setGotLeftMouseClick() { mGotLeftMouseClick = true; }
  882. // Deletion functionality
  883. void removeSelectedItems(bool confirm = true);
  884. // Opens the selected item:
  885. void openSelectedItems();
  886. void propertiesSelectedItems();
  887. void autoOpenItem(LLFolderViewFolder* item);
  888. void closeAutoOpenedFolders();
  889. bool autoOpenTest(LLFolderViewFolder* item);
  890. // Copy & paste
  891. void copy() override;
  892. bool canCopy() const override;
  893. void doCut(bool confirm);
  894. void cut() override;
  895. bool canCut() const override;
  896. void doPaste(bool confirm);
  897. void paste() override;
  898. bool canPaste() const override;
  899. void doDelete() override;
  900. bool canDoDelete() const override;
  901. // Public rename functionality: can only start the process
  902. void startRenamingSelectedItem(bool confirm = true);
  903. // Marketplace Listing upkeeping
  904. void rememberMarketplaceFolders();
  905. void updateMarketplaceFolders();
  906. // LLUICtrl Functionality
  907. void setFocus(bool focus) override;
  908. // LLView functionality
  909. #if 0
  910. bool handleKey(KEY key, MASK mask, bool called_from_parent) override;
  911. #endif
  912. bool handleKeyHere(KEY key, MASK mask) override;
  913. bool handleUnicodeCharHere(llwchar uni_char) override;
  914. bool handleMouseDown(S32 x, S32 y, MASK mask) override;
  915. bool handleDoubleClick(S32 x, S32 y, MASK mask) override;
  916. bool handleRightMouseDown(S32 x, S32 y, MASK mask) override;
  917. bool handleHover(S32 x, S32 y, MASK mask) override;
  918. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  919. EDragAndDropType cargo_type, void* cargo_data,
  920. EAcceptance* accept, std::string& tooltip) override;
  921. void reshape(S32 width, S32 height, bool call_from_parent = true) override;
  922. void onFocusLost() override;
  923. bool handleScrollWheel(S32 x, S32 y, S32 clicks) override;
  924. void draw() override;
  925. void deleteAllChildren() override;
  926. void scrollToShowSelection();
  927. void scrollToShowItem(LLFolderViewItem* item);
  928. LL_INLINE void setScrollContainer(LLScrollableContainer* parent)
  929. {
  930. mScrollContainer = parent;
  931. }
  932. LLRect getVisibleRect();
  933. bool search(LLFolderViewItem* first_item, const std::string& search_string,
  934. bool backward = false);
  935. LL_INLINE void setShowSelectionContext(bool show) { mShowSelectionContext = show; }
  936. bool getShowSelectionContext();
  937. void setShowSingleSelection(bool show);
  938. LL_INLINE bool getShowSingleSelection() { return mShowSingleSelection; }
  939. LL_INLINE F32 getSelectionFadeElapsedTime() { return mMultiSelectionFadeTimer.getElapsedTimeF32(); }
  940. void addItemID(const LLUUID& id, LLFolderViewItem* itemp);
  941. void removeItemID(const LLUUID& id);
  942. LLFolderViewItem* getItemByID(const LLUUID& id);
  943. void doIdle(); // Real idle routine
  944. static void idle(void* user_data); // static glue to doIdle()
  945. LL_INLINE void setCanAutoSelect(bool b) { mCanAutoSelect = b; }
  946. LL_INLINE bool needsAutoSelect() { return mNeedsAutoSelect; }
  947. LL_INLINE bool needsAutoRename() { return mNeedsAutoRename; }
  948. LL_INLINE void setNeedsAutoRename(bool b) { mNeedsAutoRename = b; }
  949. LL_INLINE const selected_items_t& getSelectedItems() const
  950. {
  951. return mSelectedItems;
  952. }
  953. LL_INLINE LLPanel* getParentPanel() const { return mParentPanel; }
  954. protected:
  955. static void commitRename(LLUICtrl* renamer, void* user_data);
  956. static void onRenamerLost(LLUICtrl* renamer, void* user_data);
  957. void finishRenamingItem();
  958. void closeRenamer();
  959. // Gets the context menu pointer, creating the menu if not already done.
  960. // May return NULL after the menu has been deleted for this folder view. HB
  961. LLMenuGL* getContextMenu();
  962. public:
  963. static F32 sAutoOpenTime;
  964. protected:
  965. LLPanel* mParentPanel;
  966. LLHandle<LLView> mPopupMenuHandle;
  967. // NULL if this is not a child of a scroll container.
  968. LLScrollableContainer* mScrollContainer;
  969. // Set at creation time. It is the task ID for in-world objects folder views
  970. // or LLUUID::null for the all the inventory floaters. This ID is also used
  971. // by LLToolDragAndDrop (which itself sends messages to the server with
  972. // that ID) and should therefore not be touched.
  973. LLUUID mSourceID;
  974. // Used by notification static callbacks to find which folder view it
  975. // relates to. It is either the task UUID for inworld object (== mSourceID)
  976. // or a randomly generated UUID for each main inventory folder views.
  977. LLUUID mFolderViewId;
  978. // Renaming variables and methods
  979. LLFolderViewItem* mRenameItem; // The item being renamed
  980. LLLineEditor* mRenamer;
  981. LLFolderViewItem* mLastScrollItem;
  982. LLCoordGL mLastScrollOffset;
  983. U32 mSortOrder;
  984. U32 mSearchType;
  985. LLFolderViewFolder* mAutoOpenCandidate;
  986. LLFrameTimer mAutoOpenTimer;
  987. LLFrameTimer mSearchTimer;
  988. std::string mSearchString;
  989. LLInventoryFilter mFilter;
  990. LLFrameTimer mMultiSelectionFadeTimer;
  991. S32 mArrangeGeneration;
  992. S32 mSignalSelectCallback;
  993. void* mUserData;
  994. selection_cb_t mSelectCallback;
  995. S32 mMinWidth;
  996. typedef LLDepthStack<LLFolderViewFolder> auto_open_stack_t;
  997. auto_open_stack_t mAutoOpenItems;
  998. typedef fast_hmap<LLUUID, LLFolderViewItem*> item_map_t;
  999. item_map_t mItemMap;
  1000. selected_items_t mSelectedItems;
  1001. // Marketplace listings upkeeping
  1002. uuid_list_t mMarketplaceFolders;
  1003. bool mWillModifyListing;
  1004. bool mWillUnlistIfRemoved;
  1005. bool mWillDeleteListingIfRemoved;
  1006. bool mContextMenuCreated;
  1007. bool mKeyboardSelection;
  1008. bool mAllowMultiSelect;
  1009. bool mNeedsScroll;
  1010. bool mCanAutoSelect;
  1011. bool mNeedsAutoSelect;
  1012. bool mNeedsAutoRename;
  1013. bool mShowSelectionContext;
  1014. bool mShowSingleSelection;
  1015. bool mHasCapture;
  1016. bool mDragAndDropThisFrame;
  1017. bool mShowThumbnails;
  1018. bool mGotLeftMouseClick;
  1019. typedef fast_hmap<LLUUID, LLFolderView*> instances_map_t;
  1020. static instances_map_t sInstances;
  1021. };
  1022. class LLInventoryPanel : public LLPanel
  1023. {
  1024. protected:
  1025. LOG_CLASS(LLInventoryPanel);
  1026. public:
  1027. LLInventoryPanel(const std::string& name, const std::string& sort_order,
  1028. const LLRect& rect, LLInventoryModel* inventory,
  1029. bool allow_multi_select, bool disable_double_click,
  1030. bool show_thumbnails);
  1031. ~LLInventoryPanel() override;
  1032. LL_INLINE LLInventoryModel* getModel() { return mInventory; }
  1033. bool postBuild() override;
  1034. // LLView methods
  1035. const std::string& getTag() const override;
  1036. LLXMLNodePtr getXML(bool save_children = true) const override;
  1037. static LLView* fromXML(LLXMLNodePtr node, LLView* parentp,
  1038. LLUICtrlFactory*);
  1039. void draw() override;
  1040. bool handleHover(S32 x, S32 y, MASK mask) override;
  1041. bool handleDragAndDrop(S32 x, S32 y, MASK mask, bool drop,
  1042. EDragAndDropType cargo_type, void* cargo_data,
  1043. EAcceptance* accept,
  1044. std::string& tooltip_msg) override;
  1045. // Call this method to set the selection.
  1046. void openAllFolders();
  1047. void closeAllFolders();
  1048. void openDefaultFolderForType(LLAssetType::EType);
  1049. void setSelection(const LLUUID& obj_id, bool take_keyboard_focus);
  1050. LL_INLINE void setSelectCallback(LLFolderView::selection_cb_t callback,
  1051. void* user_data)
  1052. {
  1053. if (mFolders)
  1054. {
  1055. mFolders->setSelectCallback(callback, user_data);
  1056. }
  1057. }
  1058. void clearSelection();
  1059. LL_INLINE LLInventoryFilter* getFilter() { return mFolders->getFilter(); }
  1060. void setFilterTypes(U32 filter);
  1061. LL_INLINE U32 getFilterTypes() const { return mFolders->getFilterTypes(); }
  1062. void setFilterHideLibrary(bool hide = true);
  1063. void setFilterSubType(S32 subtype);
  1064. void setFilterPermMask(PermissionMask filter_perm_mask);
  1065. LL_INLINE U32 getFilterPermMask() const { return mFolders->getFilterPermissions(); }
  1066. void setFilterSubString(const std::string& string);
  1067. LL_INLINE const std::string getFilterSubString() { return mFolders->getFilterSubString(); }
  1068. void setFilterWorn(bool worn);
  1069. LL_INLINE bool getFilterWorn() const { return mFolders->getFilterWorn(); }
  1070. void setFilterLastOpen(bool b);
  1071. LL_INLINE bool getFilterLastOpen() const { return mFolders->getFilterLastOpen(); }
  1072. void setFilterShowLinks(bool b);
  1073. LL_INLINE bool getFilterShowLinks() const { return mFolders->getFilterShowLinks(); }
  1074. void setSortOrder(U32 order);
  1075. LL_INLINE U32 getSortOrder() { return mFolders->getSortOrder(); }
  1076. void setSinceLogoff(bool sl);
  1077. void setHoursAgo(U32 hours);
  1078. LL_INLINE bool getSinceLogoff() { return mFolders->getFilter()->isSinceLogoff(); }
  1079. void setShowFolderState(LLInventoryFilter::EFolderShow show);
  1080. LLInventoryFilter::EFolderShow getShowFolderState();
  1081. LL_INLINE void setAllowMultiSelect(bool allow) { mFolders->setAllowMultiSelect(allow); }
  1082. // This method is called when something has changed about the inventory.
  1083. void modelChanged(U32 mask);
  1084. LL_INLINE LLFolderView* getRootFolder() { return mFolders; }
  1085. LL_INLINE LLScrollableContainer* getScrollableContainer()
  1086. {
  1087. return mScroller;
  1088. }
  1089. void openSelected();
  1090. LL_INLINE void unSelectAll() { mFolders->setSelection(NULL, false, false); }
  1091. LL_INLINE void setLastOpenLocked(bool b) { mLastOpenLocked = b; }
  1092. // Used to keep track of the last open folder in the "Last Open" tab:
  1093. bool makeLastOpenCurrent();
  1094. LL_INLINE const LLUUID& getLastOpenID() { return mLastOpenID; }
  1095. protected:
  1096. // Given the id and the parent, build all of the folder views.
  1097. void rebuildViewsFor(const LLUUID& id);
  1098. void buildNewViews(const LLUUID& id);
  1099. protected:
  1100. LLUUID mSelectThisID; // If non null, select this item
  1101. LLUUID mLastOpenID;
  1102. LLInventoryModel* mInventory;
  1103. LLInventoryObserver* mInventoryObserver;
  1104. LLFolderView* mFolders;
  1105. LLScrollableContainer* mScroller;
  1106. const std::string mSortOrderSetting;
  1107. bool mAllowMultiSelect;
  1108. bool mLastOpenLocked;
  1109. bool mDoubleClickDisabled;
  1110. bool mShowThumbnails;
  1111. };
  1112. bool sort_item_name(LLFolderViewItem* a, LLFolderViewItem* b);
  1113. bool sort_item_date(LLFolderViewItem* a, LLFolderViewItem* b);
  1114. // Flags for buildContextMenu()
  1115. constexpr U32 SUPPRESS_OPEN_ITEM = 0x1;
  1116. constexpr U32 FIRST_SELECTED_ITEM = 0x2;
  1117. constexpr U32 ITEM_IN_MULTI_SELECTION = 0x4;
  1118. #endif // LL_LLFOLDERVIEW_H