ColumnListView.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*
  2. Open Tracker License
  3. Terms and Conditions
  4. Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
  5. Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. this software and associated documentation files (the "Software"), to deal in
  7. the Software without restriction, including without limitation the rights to
  8. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  9. of the Software, and to permit persons to whom the Software is furnished to do
  10. so, subject to the following conditions:
  11. The above copyright notice and this permission notice applies to all licensees
  12. and shall be included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  16. BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  17. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
  18. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. Except as contained in this notice, the name of Be Incorporated shall not be
  20. used in advertising or otherwise to promote the sale, use or other dealings in
  21. this Software without prior written authorization from Be Incorporated.
  22. Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
  23. of Be Incorporated in the United States and other countries. Other brand product
  24. names are registered trademarks or trademarks of their respective holders.
  25. All rights reserved.
  26. */
  27. /*******************************************************************************
  28. /
  29. / File: ColumnListView.h
  30. /
  31. / Description: Experimental multi-column list view.
  32. /
  33. / Copyright 2000+, Be Incorporated, All Rights Reserved
  34. /
  35. *******************************************************************************/
  36. #ifndef _COLUMN_LIST_VIEW_H
  37. #define _COLUMN_LIST_VIEW_H
  38. #include <BeBuild.h>
  39. #include <View.h>
  40. #include <List.h>
  41. #include <Invoker.h>
  42. #include <ListView.h>
  43. class BScrollBar;
  44. namespace BPrivate {
  45. class OutlineView;
  46. class TitleView;
  47. class BRowContainer;
  48. class RecursiveOutlineIterator;
  49. } // ns BPrivate
  50. class BField;
  51. class BRow;
  52. class BColumn;
  53. class BColumnListView;
  54. enum LatchType {
  55. B_NO_LATCH = 0,
  56. B_OPEN_LATCH = 1,
  57. B_PRESSED_LATCH = 2,
  58. B_CLOSED_LATCH = 3
  59. };
  60. typedef enum {
  61. B_ALLOW_COLUMN_NONE = 0,
  62. B_ALLOW_COLUMN_MOVE = 1,
  63. B_ALLOW_COLUMN_RESIZE = 2,
  64. B_ALLOW_COLUMN_POPUP = 4,
  65. B_ALLOW_COLUMN_REMOVE = 8
  66. } column_flags;
  67. enum ColumnListViewColor {
  68. B_COLOR_BACKGROUND = 0,
  69. B_COLOR_TEXT = 1,
  70. B_COLOR_ROW_DIVIDER = 2,
  71. B_COLOR_SELECTION = 3,
  72. B_COLOR_SELECTION_TEXT = 4,
  73. B_COLOR_NON_FOCUS_SELECTION = 5,
  74. B_COLOR_EDIT_BACKGROUND = 6,
  75. B_COLOR_EDIT_TEXT = 7,
  76. B_COLOR_HEADER_BACKGROUND = 8,
  77. B_COLOR_HEADER_TEXT = 9,
  78. B_COLOR_SEPARATOR_LINE = 10,
  79. B_COLOR_SEPARATOR_BORDER = 11,
  80. B_COLOR_TOTAL = 12
  81. };
  82. enum ColumnListViewFont {
  83. B_FONT_ROW = 0,
  84. B_FONT_HEADER = 1,
  85. B_FONT_TOTAL = 2
  86. };
  87. // A single row/column intersection in the list.
  88. class BField {
  89. public:
  90. BField();
  91. virtual ~BField();
  92. };
  93. // A single line in the list. Each line contains a BField object
  94. // for each column in the list, associated by their "logical field"
  95. // index. Hierarchies are formed by adding other BRow objects as
  96. // a parent of a row, using the AddRow() function in BColumnListView().
  97. class BRow {
  98. public:
  99. BRow(float height = 16.0);
  100. virtual ~BRow();
  101. virtual bool HasLatch() const;
  102. int32 CountFields() const;
  103. BField* GetField(int32 logicalFieldIndex);
  104. const BField* GetField(int32 logicalFieldIndex) const;
  105. void SetField(BField* field,
  106. int32 logicalFieldIndex);
  107. float Height() const;
  108. bool IsExpanded() const;
  109. bool IsSelected() const;
  110. private:
  111. // Blows up into the debugger if the validation fails.
  112. void ValidateFields() const;
  113. void ValidateField(const BField* field,
  114. int32 logicalFieldIndex) const;
  115. private:
  116. BList fFields;
  117. BPrivate::
  118. BRowContainer* fChildList;
  119. bool fIsExpanded;
  120. float fHeight;
  121. BRow* fNextSelected;
  122. BRow* fPrevSelected;
  123. BRow* fParent;
  124. BColumnListView* fList;
  125. friend class BColumnListView;
  126. friend class BPrivate::RecursiveOutlineIterator;
  127. friend class BPrivate::OutlineView;
  128. };
  129. // Information about a single column in the list. A column knows
  130. // how to display the BField objects that occur at its location in
  131. // each of the list's rows. See ColumnTypes.h for particular
  132. // subclasses of BField and BColumn that handle common data types.
  133. class BColumn {
  134. public:
  135. BColumn(float width, float minWidth,
  136. float maxWidth,
  137. alignment align = B_ALIGN_LEFT);
  138. virtual ~BColumn();
  139. float Width() const;
  140. void SetWidth(float width);
  141. float MinWidth() const;
  142. float MaxWidth() const;
  143. virtual void DrawTitle(BRect rect, BView* targetView);
  144. virtual void DrawField(BField* field, BRect rect,
  145. BView* targetView);
  146. virtual int CompareFields(BField* field1, BField* field2);
  147. virtual void MouseMoved(BColumnListView* parent, BRow* row,
  148. BField* field, BRect fieldRect,
  149. BPoint point, uint32 buttons, int32 code);
  150. virtual void MouseDown(BColumnListView* parent, BRow* row,
  151. BField* field, BRect fieldRect,
  152. BPoint point, uint32 buttons);
  153. virtual void MouseUp(BColumnListView* parent, BRow* row,
  154. BField* field);
  155. virtual void GetColumnName(BString* into) const;
  156. virtual float GetPreferredWidth(BField* field,
  157. BView* parent) const;
  158. bool IsVisible() const;
  159. void SetVisible(bool);
  160. bool WantsEvents() const;
  161. void SetWantsEvents(bool);
  162. bool ShowHeading() const;
  163. void SetShowHeading(bool);
  164. alignment Alignment() const;
  165. void SetAlignment(alignment);
  166. int32 LogicalFieldNum() const;
  167. /*!
  168. \param field The BField derivative to validate.
  169. Implement this function on your BColumn derivatives to validate
  170. BField derivatives that your BColumn will be drawing/manipulating.
  171. This function will be called when BFields are added to the Column,
  172. use dynamic_cast<> to determine if it is of a kind that your
  173. BColumn know how ot handle. return false if it is not.
  174. \note The debugger will be called if you return false from here
  175. with information about what type of BField and BColumn and the
  176. logical field index where it occured.
  177. \note Do not call the inherited version of this, it just returns
  178. true;
  179. */
  180. virtual bool AcceptsField(const BField* field) const;
  181. private:
  182. float fWidth;
  183. float fMinWidth;
  184. float fMaxWidth;
  185. bool fVisible;
  186. int32 fFieldID;
  187. BColumnListView* fList;
  188. bool fSortAscending;
  189. bool fWantsEvents;
  190. bool fShowHeading;
  191. alignment fAlignment;
  192. friend class BPrivate::OutlineView;
  193. friend class BColumnListView;
  194. friend class BPrivate::TitleView;
  195. };
  196. // The column list view class.
  197. class BColumnListView : public BView, public BInvoker {
  198. public:
  199. BColumnListView(BRect rect,
  200. const char* name, uint32 resizingMode,
  201. uint32 flags, border_style = B_NO_BORDER,
  202. bool showHorizontalScrollbar = true);
  203. BColumnListView(const char* name,
  204. uint32 flags, border_style = B_NO_BORDER,
  205. bool showHorizontalScrollbar = true);
  206. virtual ~BColumnListView();
  207. // Interaction
  208. virtual bool InitiateDrag(BPoint, bool wasSelected);
  209. virtual void MessageDropped(BMessage*, BPoint point);
  210. virtual void ExpandOrCollapse(BRow* row, bool expand);
  211. virtual status_t Invoke(BMessage* message = NULL);
  212. virtual void ItemInvoked();
  213. virtual void SetInvocationMessage(BMessage* message);
  214. BMessage* InvocationMessage() const;
  215. uint32 InvocationCommand() const;
  216. BRow* FocusRow() const;
  217. void SetFocusRow(int32 index, bool select = false);
  218. void SetFocusRow(BRow* row, bool select = false);
  219. void SetMouseTrackingEnabled(bool);
  220. // Selection
  221. list_view_type SelectionMode() const;
  222. void Deselect(BRow* row);
  223. void AddToSelection(BRow* row);
  224. void DeselectAll();
  225. BRow* CurrentSelection(BRow* lastSelected = 0) const;
  226. virtual void SelectionChanged();
  227. virtual void SetSelectionMessage(BMessage* message);
  228. BMessage* SelectionMessage();
  229. uint32 SelectionCommand() const;
  230. void SetSelectionMode(list_view_type type);
  231. // list_view_type is defined in ListView.h.
  232. // Sorting
  233. void SetSortingEnabled(bool);
  234. bool SortingEnabled() const;
  235. void SetSortColumn(BColumn* column, bool add,
  236. bool ascending);
  237. void ClearSortColumns();
  238. // The status view is a little area in the lower left hand corner.
  239. void AddStatusView(BView* view);
  240. BView* RemoveStatusView();
  241. // Column Manipulation
  242. void AddColumn(BColumn* column,
  243. int32 logicalFieldIndex);
  244. void MoveColumn(BColumn* column, int32 index);
  245. void RemoveColumn(BColumn* column);
  246. int32 CountColumns() const;
  247. BColumn* ColumnAt(int32 index) const;
  248. BColumn* ColumnAt(BPoint point) const;
  249. void SetColumnVisible(BColumn* column,
  250. bool isVisible);
  251. void SetColumnVisible(int32, bool);
  252. bool IsColumnVisible(int32) const;
  253. void SetColumnFlags(column_flags flags);
  254. void ResizeColumnToPreferred(int32 index);
  255. void ResizeAllColumnsToPreferred();
  256. // Row manipulation
  257. const BRow* RowAt(int32 index, BRow *parent = 0) const;
  258. BRow* RowAt(int32 index, BRow *parent = 0);
  259. const BRow* RowAt(BPoint) const;
  260. BRow* RowAt(BPoint);
  261. bool GetRowRect(const BRow* row, BRect* _rect) const;
  262. bool FindParent(BRow* row, BRow** _parent,
  263. bool *_isVisible) const;
  264. int32 IndexOf(BRow* row);
  265. int32 CountRows(BRow* parent = 0) const;
  266. void AddRow(BRow* row, BRow* parent = NULL);
  267. void AddRow(BRow* row, int32 index,
  268. BRow* parent = NULL);
  269. void ScrollTo(const BRow* Row);
  270. void ScrollTo(BPoint point);
  271. // Does not delete row or children at this time.
  272. // todo: Make delete row and children
  273. void RemoveRow(BRow* row);
  274. void UpdateRow(BRow* row);
  275. bool SwapRows(int32 index1, int32 index2, BRow*
  276. parentRow1 = NULL, BRow* parentRow2 = NULL);
  277. void Clear();
  278. // Appearance (DEPRECATED)
  279. void GetFont(BFont* font) const
  280. { BView::GetFont(font); }
  281. virtual void SetFont(const BFont* font,
  282. uint32 mask = B_FONT_ALL);
  283. virtual void SetHighColor(rgb_color);
  284. void SetSelectionColor(rgb_color);
  285. void SetBackgroundColor(rgb_color);
  286. void SetEditColor(rgb_color);
  287. const rgb_color SelectionColor() const;
  288. const rgb_color BackgroundColor() const;
  289. const rgb_color EditColor() const;
  290. // Appearance (NEW STYLE)
  291. void SetColor(ColumnListViewColor colorIndex,
  292. rgb_color color);
  293. void SetFont(ColumnListViewFont fontIndex,
  294. const BFont* font,
  295. uint32 mask = B_FONT_ALL);
  296. rgb_color Color(ColumnListViewColor colorIndex) const;
  297. void GetFont(ColumnListViewFont fontIndex,
  298. BFont* font) const;
  299. BPoint SuggestTextPosition(const BRow* row,
  300. const BColumn* column = NULL) const;
  301. void SetLatchWidth(float width);
  302. float LatchWidth() const;
  303. virtual void DrawLatch(BView* view, BRect frame,
  304. LatchType type, BRow* row);
  305. virtual void MakeFocus(bool isfocus = true);
  306. void SaveState(BMessage* archive);
  307. void LoadState(BMessage* archive);
  308. BView* ScrollView() const
  309. { return (BView*)fOutlineView; }
  310. void SetEditMode(bool state);
  311. void Refresh();
  312. virtual BSize MinSize();
  313. virtual BSize PreferredSize();
  314. virtual BSize MaxSize();
  315. protected:
  316. virtual void MessageReceived(BMessage* message);
  317. virtual void KeyDown(const char* bytes, int32 numBytes);
  318. virtual void AttachedToWindow();
  319. virtual void WindowActivated(bool active);
  320. virtual void Draw(BRect updateRect);
  321. virtual void LayoutInvalidated(bool descendants = false);
  322. virtual void DoLayout();
  323. private:
  324. void _Init();
  325. void _GetChildViewRects(const BRect& bounds,
  326. BRect& titleRect, BRect& outlineRect,
  327. BRect& vScrollBarRect,
  328. BRect& hScrollBarRect);
  329. rgb_color fColorList[B_COLOR_TOTAL];
  330. BPrivate::TitleView* fTitleView;
  331. BPrivate::OutlineView* fOutlineView;
  332. BList fColumns;
  333. BScrollBar* fHorizontalScrollBar;
  334. BScrollBar* fVerticalScrollBar;
  335. BList fSortColumns;
  336. BView* fStatusView;
  337. BMessage* fSelectionMessage;
  338. bool fSortingEnabled;
  339. float fLatchWidth;
  340. border_style fBorderStyle;
  341. bool fShowingHorizontalScrollBar;
  342. };
  343. #endif // _COLUMN_LIST_VIEW_H