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