/indra/newview/llfolderviewitem.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 574 lines · 307 code · 125 blank · 142 comment · 0 complexity · 9deef7e14e62cd86f08a3cdc817660e4 MD5 · raw file

  1. /**
  2. * @file llfolderviewitem.h
  3. * @brief Items and folders that can appear in a hierarchical folder view
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LLFOLDERVIEWITEM_H
  27. #define LLFOLDERVIEWITEM_H
  28. #include "llview.h"
  29. #include "lldarray.h" // *TODO: Eliminate, forward declare
  30. #include "lluiimage.h"
  31. class LLFontGL;
  32. class LLFolderView;
  33. class LLFolderViewEventListener;
  34. class LLFolderViewFolder;
  35. class LLFolderViewFunctor;
  36. class LLFolderViewItem;
  37. class LLFolderViewListenerFunctor;
  38. class LLInventoryFilter;
  39. class LLMenuGL;
  40. class LLUIImage;
  41. class LLViewerInventoryItem;
  42. // These are grouping of inventory types.
  43. // Order matters when sorting system folders to the top.
  44. enum EInventorySortGroup
  45. {
  46. SG_SYSTEM_FOLDER,
  47. SG_TRASH_FOLDER,
  48. SG_NORMAL_FOLDER,
  49. SG_ITEM
  50. };
  51. // *TODO: do we really need one sort object per folder?
  52. // can we just have one of these per LLFolderView ?
  53. class LLInventorySort
  54. {
  55. public:
  56. LLInventorySort()
  57. : mSortOrder(0),
  58. mByDate(false),
  59. mSystemToTop(false),
  60. mFoldersByName(false) { }
  61. // Returns true if order has changed
  62. bool updateSort(U32 order);
  63. U32 getSort() { return mSortOrder; }
  64. bool isByDate() { return mByDate; }
  65. bool operator()(const LLFolderViewItem* const& a, const LLFolderViewItem* const& b);
  66. private:
  67. U32 mSortOrder;
  68. bool mByDate;
  69. bool mSystemToTop;
  70. bool mFoldersByName;
  71. };
  72. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. // Class LLFolderViewItem
  74. //
  75. // An instance of this class represents a single item in a folder view
  76. // such as an inventory item or a file.
  77. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. class LLFolderViewItem : public LLView
  79. {
  80. public:
  81. static void initClass();
  82. static void cleanupClass();
  83. struct Params : public LLInitParam::Block<Params, LLView::Params>
  84. {
  85. Optional<LLUIImage*> icon;
  86. Optional<LLUIImage*> icon_open; // used for folders
  87. Optional<LLUIImage*> icon_overlay; // for links
  88. Optional<LLFolderView*> root;
  89. Mandatory<LLFolderViewEventListener*> listener;
  90. Optional<LLUIImage*> folder_arrow_image;
  91. Optional<S32> folder_indentation; // pixels
  92. Optional<LLUIImage*> selection_image;
  93. Optional<S32> item_height; // pixels
  94. Optional<S32> item_top_pad; // pixels
  95. Optional<S32> creation_date; //UTC seconds
  96. Params();
  97. };
  98. // layout constants
  99. static const S32 LEFT_PAD = 5;
  100. // LEFT_INDENTATION is set via folder_indentation above
  101. static const S32 ICON_PAD = 2;
  102. static const S32 ICON_WIDTH = 16;
  103. static const S32 TEXT_PAD = 1;
  104. static const S32 ARROW_SIZE = 12;
  105. static const S32 MAX_FOLDER_ITEM_OVERLAP = 2;
  106. // animation parameters
  107. static const F32 FOLDER_CLOSE_TIME_CONSTANT;
  108. static const F32 FOLDER_OPEN_TIME_CONSTANT;
  109. // Mostly for debugging printout purposes.
  110. const std::string& getSearchableLabel() { return mSearchableLabel; }
  111. BOOL isLoading() const { return mIsLoading; }
  112. private:
  113. BOOL mIsSelected;
  114. protected:
  115. friend class LLUICtrlFactory;
  116. friend class LLFolderViewEventListener;
  117. LLFolderViewItem(const Params& p);
  118. std::string mLabel;
  119. std::string mSearchableLabel;
  120. S32 mLabelWidth;
  121. bool mLabelWidthDirty;
  122. time_t mCreationDate;
  123. LLFolderViewFolder* mParentFolder;
  124. LLFolderViewEventListener* mListener;
  125. BOOL mIsCurSelection;
  126. BOOL mSelectPending;
  127. LLFontGL::StyleFlags mLabelStyle;
  128. std::string mLabelSuffix;
  129. LLUIImagePtr mIcon;
  130. std::string mStatusText;
  131. LLUIImagePtr mIconOpen;
  132. LLUIImagePtr mIconOverlay;
  133. BOOL mHasVisibleChildren;
  134. S32 mIndentation;
  135. S32 mItemHeight;
  136. BOOL mPassedFilter;
  137. S32 mLastFilterGeneration;
  138. std::string::size_type mStringMatchOffset;
  139. F32 mControlLabelRotation;
  140. LLFolderView* mRoot;
  141. BOOL mDragAndDropTarget;
  142. BOOL mIsLoading;
  143. LLTimer mTimeSinceRequestStart;
  144. bool mShowLoadStatus;
  145. bool mIsMouseOverTitle;
  146. // helper function to change the selection from the root.
  147. void changeSelectionFromRoot(LLFolderViewItem* selection, BOOL selected);
  148. // this is an internal method used for adding items to folders. A
  149. // no-op at this level, but reimplemented in derived classes.
  150. virtual BOOL addItem(LLFolderViewItem*) { return FALSE; }
  151. virtual BOOL addFolder(LLFolderViewFolder*) { return FALSE; }
  152. static LLFontGL* getLabelFontForStyle(U8 style);
  153. virtual void setCreationDate(time_t creation_date_utc) { mCreationDate = creation_date_utc; }
  154. public:
  155. BOOL postBuild();
  156. // This function clears the currently selected item, and records
  157. // the specified selected item appropriately for display and use
  158. // in the UI. If open is TRUE, then folders are opened up along
  159. // the way to the selection.
  160. void setSelectionFromRoot(LLFolderViewItem* selection, BOOL openitem,
  161. BOOL take_keyboard_focus = TRUE);
  162. // This function is called when the folder view is dirty. It's
  163. // implemented here but called by derived classes when folding the
  164. // views.
  165. void arrangeFromRoot();
  166. void filterFromRoot( void );
  167. void arrangeAndSet(BOOL set_selection, BOOL take_keyboard_focus);
  168. virtual ~LLFolderViewItem( void );
  169. // addToFolder() returns TRUE if it succeeds. FALSE otherwise
  170. enum { ARRANGE = TRUE, DO_NOT_ARRANGE = FALSE };
  171. virtual BOOL addToFolder(LLFolderViewFolder* folder, LLFolderView* root);
  172. virtual EInventorySortGroup getSortGroup() const;
  173. // Finds width and height of this object and it's children. Also
  174. // makes sure that this view and it's children are the right size.
  175. virtual S32 arrange( S32* width, S32* height, S32 filter_generation );
  176. virtual S32 getItemHeight();
  177. // applies filters to control visibility of inventory items
  178. virtual void filter( LLInventoryFilter& filter);
  179. // updates filter serial number and optionally propagated value up to root
  180. S32 getLastFilterGeneration() { return mLastFilterGeneration; }
  181. virtual void dirtyFilter();
  182. // If 'selection' is 'this' then note that otherwise ignore.
  183. // Returns TRUE if this item ends up being selected.
  184. virtual BOOL setSelection(LLFolderViewItem* selection, BOOL openitem, BOOL take_keyboard_focus);
  185. // This method is used to set the selection state of an item.
  186. // If 'selection' is 'this' then note selection.
  187. // Returns TRUE if the selection state of this item was changed.
  188. virtual BOOL changeSelection(LLFolderViewItem* selection, BOOL selected);
  189. // this method is used to deselect this element
  190. void deselectItem();
  191. // this method is used to select this element
  192. virtual void selectItem();
  193. // gets multiple-element selection
  194. virtual std::set<LLUUID> getSelectionList() const;
  195. // Returns true is this object and all of its children can be removed (deleted by user)
  196. virtual BOOL isRemovable();
  197. // Returns true is this object and all of its children can be moved
  198. virtual BOOL isMovable();
  199. // destroys this item recursively
  200. virtual void destroyView();
  201. BOOL isSelected() const { return mIsSelected; }
  202. void setUnselected() { mIsSelected = FALSE; }
  203. void setIsCurSelection(BOOL select) { mIsCurSelection = select; }
  204. BOOL getIsCurSelection() { return mIsCurSelection; }
  205. BOOL hasVisibleChildren() { return mHasVisibleChildren; }
  206. void setShowLoadStatus(bool status) { mShowLoadStatus = status; }
  207. // Call through to the viewed object and return true if it can be
  208. // removed. Returns true if it's removed.
  209. //virtual BOOL removeRecursively(BOOL single_item);
  210. BOOL remove();
  211. // Build an appropriate context menu for the item. Flags unused.
  212. void buildContextMenu(LLMenuGL& menu, U32 flags);
  213. // This method returns the actual name of the thing being
  214. // viewed. This method will ask the viewed object itself.
  215. const std::string& getName( void ) const;
  216. const std::string& getSearchableLabel( void ) const;
  217. // This method returns the label displayed on the view. This
  218. // method was primarily added to allow sorting on the folder
  219. // contents possible before the entire view has been constructed.
  220. const std::string& getLabel() const { return mLabel; }
  221. // Used for sorting, like getLabel() above.
  222. virtual time_t getCreationDate() const { return mCreationDate; }
  223. LLFolderViewFolder* getParentFolder( void ) { return mParentFolder; }
  224. const LLFolderViewFolder* getParentFolder( void ) const { return mParentFolder; }
  225. LLFolderViewItem* getNextOpenNode( BOOL include_children = TRUE );
  226. LLFolderViewItem* getPreviousOpenNode( BOOL include_children = TRUE );
  227. const LLFolderViewEventListener* getListener( void ) const { return mListener; }
  228. LLFolderViewEventListener* getListener( void ) { return mListener; }
  229. // Gets the inventory item if it exists (null otherwise)
  230. LLViewerInventoryItem * getInventoryItem(void);
  231. // just rename the object.
  232. void rename(const std::string& new_name);
  233. // open
  234. virtual void openItem( void );
  235. virtual void preview(void);
  236. // Show children (unfortunate that this is called "open")
  237. virtual void setOpen(BOOL open = TRUE) {};
  238. virtual BOOL isOpen() const { return FALSE; }
  239. virtual LLFolderView* getRoot();
  240. BOOL isDescendantOf( const LLFolderViewFolder* potential_ancestor );
  241. S32 getIndentation() { return mIndentation; }
  242. virtual BOOL potentiallyVisible(); // do we know for a fact that this item has been filtered out?
  243. virtual BOOL getFiltered();
  244. virtual BOOL getFiltered(S32 filter_generation);
  245. virtual void setFiltered(BOOL filtered, S32 filter_generation);
  246. // change the icon
  247. void setIcon(LLUIImagePtr icon);
  248. // refresh information from the object being viewed.
  249. void refreshFromListener();
  250. virtual void refresh();
  251. virtual void applyListenerFunctorRecursively(LLFolderViewListenerFunctor& functor);
  252. // LLView functionality
  253. virtual BOOL handleRightMouseDown( S32 x, S32 y, MASK mask );
  254. virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask );
  255. virtual BOOL handleHover( S32 x, S32 y, MASK mask );
  256. virtual BOOL handleMouseUp( S32 x, S32 y, MASK mask );
  257. virtual BOOL handleDoubleClick( S32 x, S32 y, MASK mask );
  258. virtual void onMouseLeave(S32 x, S32 y, MASK mask);
  259. virtual LLView* findChildView(const std::string& name, BOOL recurse) const { return NULL; }
  260. // virtual void handleDropped();
  261. virtual void draw();
  262. virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
  263. EDragAndDropType cargo_type,
  264. void* cargo_data,
  265. EAcceptance* accept,
  266. std::string& tooltip_msg);
  267. private:
  268. static std::map<U8, LLFontGL*> sFonts; // map of styles to fonts
  269. };
  270. // function used for sorting.
  271. typedef bool (*sort_order_f)(LLFolderViewItem* a, LLFolderViewItem* b);
  272. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  273. // Class LLFolderViewFolder
  274. //
  275. // An instance of an LLFolderViewFolder represents a collection of
  276. // more folders and items. This is used to build the hierarchy of
  277. // items found in the folder view.
  278. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279. class LLFolderViewFolder : public LLFolderViewItem
  280. {
  281. protected:
  282. LLFolderViewFolder( const LLFolderViewItem::Params& );
  283. friend class LLUICtrlFactory;
  284. public:
  285. typedef enum e_trash
  286. {
  287. UNKNOWN, TRASH, NOT_TRASH
  288. } ETrash;
  289. typedef std::list<LLFolderViewItem*> items_t;
  290. typedef std::list<LLFolderViewFolder*> folders_t;
  291. protected:
  292. items_t mItems;
  293. folders_t mFolders;
  294. LLInventorySort mSortFunction;
  295. BOOL mIsOpen;
  296. BOOL mExpanderHighlighted;
  297. F32 mCurHeight;
  298. F32 mTargetHeight;
  299. F32 mAutoOpenCountdown;
  300. time_t mSubtreeCreationDate;
  301. mutable ETrash mAmTrash;
  302. S32 mLastArrangeGeneration;
  303. S32 mLastCalculatedWidth;
  304. S32 mCompletedFilterGeneration;
  305. S32 mMostFilteredDescendantGeneration;
  306. bool mNeedsSort;
  307. bool mPassedFolderFilter;
  308. public:
  309. typedef enum e_recurse_type
  310. {
  311. RECURSE_NO,
  312. RECURSE_UP,
  313. RECURSE_DOWN,
  314. RECURSE_UP_DOWN
  315. } ERecurseType;
  316. virtual ~LLFolderViewFolder( void );
  317. virtual BOOL potentiallyVisible();
  318. LLFolderViewItem* getNextFromChild( LLFolderViewItem*, BOOL include_children = TRUE );
  319. LLFolderViewItem* getPreviousFromChild( LLFolderViewItem*, BOOL include_children = TRUE );
  320. // addToFolder() returns TRUE if it succeeds. FALSE otherwise
  321. virtual BOOL addToFolder(LLFolderViewFolder* folder, LLFolderView* root);
  322. // Finds width and height of this object and it's children. Also
  323. // makes sure that this view and it's children are the right size.
  324. virtual S32 arrange( S32* width, S32* height, S32 filter_generation );
  325. BOOL needsArrange();
  326. void requestSort();
  327. // Returns the sort group (system, trash, folder) for this folder.
  328. virtual EInventorySortGroup getSortGroup() const;
  329. virtual void setCompletedFilterGeneration(S32 generation, BOOL recurse_up);
  330. virtual S32 getCompletedFilterGeneration() { return mCompletedFilterGeneration; }
  331. BOOL hasFilteredDescendants(S32 filter_generation);
  332. BOOL hasFilteredDescendants();
  333. // applies filters to control visibility of inventory items
  334. virtual void filter( LLInventoryFilter& filter);
  335. virtual void setFiltered(BOOL filtered, S32 filter_generation);
  336. virtual BOOL getFiltered();
  337. virtual BOOL getFiltered(S32 filter_generation);
  338. virtual void dirtyFilter();
  339. // folder-specific filtering (filter status propagates top down instead of bottom up)
  340. void filterFolder(LLInventoryFilter& filter);
  341. void setFilteredFolder(bool filtered, S32 filter_generation);
  342. bool getFilteredFolder(S32 filter_generation);
  343. // Passes selection information on to children and record
  344. // selection information if necessary.
  345. // Returns TRUE if this object (or a child) ends up being selected.
  346. // If 'openitem' is TRUE then folders are opened up along the way to the selection.
  347. virtual BOOL setSelection(LLFolderViewItem* selection, BOOL openitem, BOOL take_keyboard_focus);
  348. // This method is used to change the selection of an item.
  349. // Recursively traverse all children; if 'selection' is 'this' then change
  350. // the select status if necessary.
  351. // Returns TRUE if the selection state of this folder, or of a child, was changed.
  352. virtual BOOL changeSelection(LLFolderViewItem* selection, BOOL selected);
  353. // this method is used to group select items
  354. void extendSelectionTo(LLFolderViewItem* selection);
  355. // Returns true is this object and all of its children can be removed.
  356. virtual BOOL isRemovable();
  357. // Returns true is this object and all of its children can be moved
  358. virtual BOOL isMovable();
  359. // destroys this folder, and all children
  360. virtual void destroyView();
  361. // If this folder can be removed, remove all children that can be
  362. // removed, return TRUE if this is empty after the operation and
  363. // it's viewed folder object can be removed.
  364. //virtual BOOL removeRecursively(BOOL single_item);
  365. //virtual BOOL remove();
  366. // remove the specified item (and any children) if
  367. // possible. Return TRUE if the item was deleted.
  368. BOOL removeItem(LLFolderViewItem* item);
  369. // simply remove the view (and any children) Don't bother telling
  370. // the listeners.
  371. void removeView(LLFolderViewItem* item);
  372. // extractItem() removes the specified item from the folder, but
  373. // doesn't delete it.
  374. void extractItem( LLFolderViewItem* item );
  375. // This function is called by a child that needs to be resorted.
  376. void resort(LLFolderViewItem* item);
  377. void setItemSortOrder(U32 ordering);
  378. void sortBy(U32);
  379. //BOOL (*func)(LLFolderViewItem* a, LLFolderViewItem* b));
  380. void setAutoOpenCountdown(F32 countdown) { mAutoOpenCountdown = countdown; }
  381. // folders can be opened. This will usually be called by internal
  382. // methods.
  383. virtual void toggleOpen();
  384. // Force a folder open or closed
  385. virtual void setOpen(BOOL openitem = TRUE);
  386. // Called when a child is refreshed.
  387. // don't rearrange child folder contents unless explicitly requested
  388. virtual void requestArrange(BOOL include_descendants = FALSE);
  389. // internal method which doesn't update the entire view. This
  390. // method was written because the list iterators destroy the state
  391. // of other iterations, thus, we can't arrange while iterating
  392. // through the children (such as when setting which is selected.
  393. virtual void setOpenArrangeRecursively(BOOL openitem, ERecurseType recurse = RECURSE_NO);
  394. // Get the current state of the folder.
  395. virtual BOOL isOpen() const { return mIsOpen; }
  396. // special case if an object is dropped on the child.
  397. BOOL handleDragAndDropFromChild(MASK mask,
  398. BOOL drop,
  399. EDragAndDropType cargo_type,
  400. void* cargo_data,
  401. EAcceptance* accept,
  402. std::string& tooltip_msg);
  403. void applyFunctorRecursively(LLFolderViewFunctor& functor);
  404. virtual void applyListenerFunctorRecursively(LLFolderViewListenerFunctor& functor);
  405. // Just apply this functor to the folder's immediate children.
  406. void applyFunctorToChildren(LLFolderViewFunctor& functor);
  407. virtual void openItem( void );
  408. virtual BOOL addItem(LLFolderViewItem* item);
  409. virtual BOOL addFolder( LLFolderViewFolder* folder);
  410. // LLView functionality
  411. virtual BOOL handleHover(S32 x, S32 y, MASK mask);
  412. virtual BOOL handleRightMouseDown( S32 x, S32 y, MASK mask );
  413. virtual BOOL handleMouseDown( S32 x, S32 y, MASK mask );
  414. virtual BOOL handleDoubleClick( S32 x, S32 y, MASK mask );
  415. virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
  416. EDragAndDropType cargo_type,
  417. void* cargo_data,
  418. EAcceptance* accept,
  419. std::string& tooltip_msg);
  420. BOOL handleDragAndDropToThisFolder(MASK mask, BOOL drop,
  421. EDragAndDropType cargo_type,
  422. void* cargo_data,
  423. EAcceptance* accept,
  424. std::string& tooltip_msg);
  425. virtual void draw();
  426. time_t getCreationDate() const;
  427. bool isTrash() const;
  428. folders_t::const_iterator getFoldersBegin() const { return mFolders.begin(); }
  429. folders_t::const_iterator getFoldersEnd() const { return mFolders.end(); }
  430. folders_t::size_type getFoldersCount() const { return mFolders.size(); }
  431. items_t::const_iterator getItemsBegin() const { return mItems.begin(); }
  432. items_t::const_iterator getItemsEnd() const { return mItems.end(); }
  433. items_t::size_type getItemsCount() const { return mItems.size(); }
  434. LLFolderViewFolder* getCommonAncestor(LLFolderViewItem* item_a, LLFolderViewItem* item_b, bool& reverse);
  435. void gatherChildRangeExclusive(LLFolderViewItem* start, LLFolderViewItem* end, bool reverse, std::vector<LLFolderViewItem*>& items);
  436. };
  437. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  438. // Class LLFolderViewListenerFunctor
  439. //
  440. // This simple abstract base class can be used to applied to all
  441. // listeners in a hierarchy.
  442. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  443. class LLFolderViewListenerFunctor
  444. {
  445. public:
  446. virtual ~LLFolderViewListenerFunctor() {}
  447. virtual void operator()(LLFolderViewEventListener* listener) = 0;
  448. };
  449. #endif // LLFOLDERVIEWITEM_H