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(); 125 BRow(float height); 126 virtual ~BRow(); 127 virtual bool HasLatch() const; 128 129 int32 CountFields() const; 130 BField* GetField(int32 logicalFieldIndex); 131 const BField* GetField(int32 logicalFieldIndex) const; 132 void SetField(BField* field, 133 int32 logicalFieldIndex); 134 135 float Height() const; 136 bool IsExpanded() const; 137 bool IsSelected() const; 138 139 void Invalidate(); 140 141 private: 142 // Blows up into the debugger if the validation fails. 143 void ValidateFields() const; 144 void ValidateField(const BField* field, 145 int32 logicalFieldIndex) const; 146 private: 147 BList fFields; 148 BPrivate:: 149 BRowContainer* fChildList; 150 bool fIsExpanded; 151 float fHeight; 152 BRow* fNextSelected; 153 BRow* fPrevSelected; 154 BRow* fParent; 155 BColumnListView* fList; 156 157 158 friend class BColumnListView; 159 friend class BPrivate::RecursiveOutlineIterator; 160 friend class BPrivate::OutlineView; 161 }; 162 163 // Information about a single column in the list. A column knows 164 // how to display the BField objects that occur at its location in 165 // each of the list's rows. See ColumnTypes.h for particular 166 // subclasses of BField and BColumn that handle common data types. 167 class BColumn { 168 public: 169 BColumn(float width, float minWidth, 170 float maxWidth, 171 alignment align = B_ALIGN_LEFT); 172 virtual ~BColumn(); 173 174 float Width() const; 175 void SetWidth(float width); 176 float MinWidth() const; 177 float MaxWidth() const; 178 179 virtual void DrawTitle(BRect rect, BView* targetView); 180 virtual void DrawField(BField* field, BRect rect, 181 BView* targetView); 182 virtual int CompareFields(BField* field1, BField* field2); 183 184 virtual void MouseMoved(BColumnListView* parent, BRow* row, 185 BField* field, BRect fieldRect, 186 BPoint point, uint32 buttons, int32 code); 187 virtual void MouseDown(BColumnListView* parent, BRow* row, 188 BField* field, BRect fieldRect, 189 BPoint point, uint32 buttons); 190 virtual void MouseUp(BColumnListView* parent, BRow* row, 191 BField* field); 192 193 virtual void GetColumnName(BString* into) const; 194 virtual float GetPreferredWidth(BField* field, 195 BView* parent) const; 196 197 bool IsVisible() const; 198 void SetVisible(bool); 199 200 bool WantsEvents() const; 201 void SetWantsEvents(bool); 202 203 bool ShowHeading() const; 204 void SetShowHeading(bool); 205 206 alignment Alignment() const; 207 void SetAlignment(alignment); 208 209 int32 LogicalFieldNum() const; 210 211 /*! 212 \param field The BField derivative to validate. 213 214 Implement this function on your BColumn derivatives to validate 215 BField derivatives that your BColumn will be drawing/manipulating. 216 217 This function will be called when BFields are added to the Column, 218 use dynamic_cast<> to determine if it is of a kind that your 219 BColumn know how ot handle. return false if it is not. 220 221 \note The debugger will be called if you return false from here 222 with information about what type of BField and BColumn and the 223 logical field index where it occured. 224 225 \note Do not call the inherited version of this, it just returns 226 true; 227 */ 228 virtual bool AcceptsField(const BField* field) const; 229 230 private: 231 float fWidth; 232 float fMinWidth; 233 float fMaxWidth; 234 bool fVisible; 235 int32 fFieldID; 236 BColumnListView* fList; 237 bool fSortAscending; 238 bool fWantsEvents; 239 bool fShowHeading; 240 alignment fAlignment; 241 242 friend class BPrivate::OutlineView; 243 friend class BColumnListView; 244 friend class BPrivate::TitleView; 245 }; 246 247 // The column list view class. 248 class BColumnListView : public BView, public BInvoker { 249 public: 250 BColumnListView(BRect rect, 251 const char* name, uint32 resizingMode, 252 uint32 flags, border_style = B_NO_BORDER, 253 bool showHorizontalScrollbar = true); 254 BColumnListView(const char* name, 255 uint32 flags, border_style = B_NO_BORDER, 256 bool showHorizontalScrollbar = true); 257 virtual ~BColumnListView(); 258 259 // Interaction 260 virtual bool InitiateDrag(BPoint, bool wasSelected); 261 virtual void MessageDropped(BMessage*, BPoint point); 262 virtual void ExpandOrCollapse(BRow* row, bool expand); 263 virtual status_t Invoke(BMessage* message = NULL); 264 virtual void ItemInvoked(); 265 virtual void SetInvocationMessage(BMessage* message); 266 BMessage* InvocationMessage() const; 267 uint32 InvocationCommand() const; 268 BRow* FocusRow() const; 269 void SetFocusRow(int32 index, bool select = false); 270 void SetFocusRow(BRow* row, bool select = false); 271 void SetMouseTrackingEnabled(bool); 272 273 // Selection 274 list_view_type SelectionMode() const; 275 void Deselect(BRow* row); 276 void AddToSelection(BRow* row); 277 void DeselectAll(); 278 BRow* CurrentSelection(BRow* lastSelected = 0) const; 279 virtual void SelectionChanged(); 280 virtual void SetSelectionMessage(BMessage* message); 281 BMessage* SelectionMessage(); 282 uint32 SelectionCommand() const; 283 void SetSelectionMode(list_view_type type); 284 // list_view_type is defined in ListView.h. 285 286 // Sorting 287 void SetSortingEnabled(bool); 288 bool SortingEnabled() const; 289 void SetSortColumn(BColumn* column, bool add, 290 bool ascending); 291 void ClearSortColumns(); 292 293 // The status view is a little area in the lower left hand corner. 294 void AddStatusView(BView* view); 295 BView* RemoveStatusView(); 296 297 // Column Manipulation 298 void AddColumn(BColumn* column, 299 int32 logicalFieldIndex); 300 void MoveColumn(BColumn* column, int32 index); 301 void RemoveColumn(BColumn* column); 302 int32 CountColumns() const; 303 BColumn* ColumnAt(int32 index) const; 304 BColumn* ColumnAt(BPoint point) const; 305 void SetColumnVisible(BColumn* column, 306 bool isVisible); 307 void SetColumnVisible(int32, bool); 308 bool IsColumnVisible(int32) const; 309 void SetColumnFlags(column_flags flags); 310 void ResizeColumnToPreferred(int32 index); 311 void ResizeAllColumnsToPreferred(); 312 313 // Row manipulation 314 const BRow* RowAt(int32 index, BRow *parent = 0) const; 315 BRow* RowAt(int32 index, BRow *parent = 0); 316 const BRow* RowAt(BPoint) const; 317 BRow* RowAt(BPoint); 318 bool GetRowRect(const BRow* row, BRect* _rect) const; 319 bool FindParent(BRow* row, BRow** _parent, 320 bool *_isVisible) const; 321 int32 IndexOf(BRow* row); 322 int32 CountRows(BRow* parent = 0) const; 323 void AddRow(BRow* row, BRow* parent = NULL); 324 void AddRow(BRow* row, int32 index, 325 BRow* parent = NULL); 326 327 void ScrollTo(const BRow* Row); 328 void ScrollTo(BPoint point); 329 330 // Does not delete row or children at this time. 331 // todo: Make delete row and children 332 void RemoveRow(BRow* row); 333 void UpdateRow(BRow* row); 334 bool SwapRows(int32 index1, int32 index2, BRow* 335 parentRow1 = NULL, BRow* parentRow2 = NULL); 336 void Clear(); 337 338 void InvalidateRow(BRow* row); 339 340 // Appearance (DEPRECATED) 341 void GetFont(BFont* font) const 342 { BView::GetFont(font); } 343 virtual void SetFont(const BFont* font, 344 uint32 mask = B_FONT_ALL); 345 virtual void SetHighColor(rgb_color); 346 void SetSelectionColor(rgb_color); 347 void SetBackgroundColor(rgb_color); 348 void SetEditColor(rgb_color); 349 const rgb_color SelectionColor() const; 350 const rgb_color BackgroundColor() const; 351 const rgb_color EditColor() const; 352 353 // Appearance (NEW STYLE) 354 void SetColor(ColumnListViewColor colorIndex, 355 rgb_color color); 356 void SetFont(ColumnListViewFont fontIndex, 357 const BFont* font, 358 uint32 mask = B_FONT_ALL); 359 rgb_color Color(ColumnListViewColor colorIndex) const; 360 void GetFont(ColumnListViewFont fontIndex, 361 BFont* font) const; 362 363 BPoint SuggestTextPosition(const BRow* row, 364 const BColumn* column = NULL) const; 365 366 BRect GetFieldRect(const BRow* row, 367 const BColumn* column) const; 368 369 void SetLatchWidth(float width); 370 float LatchWidth() const; 371 virtual void DrawLatch(BView* view, BRect frame, 372 LatchType type, BRow* row); 373 virtual void MakeFocus(bool isfocus = true); 374 void SaveState(BMessage* archive); 375 void LoadState(BMessage* archive); 376 377 BView* ScrollView() const 378 { return (BView*)fOutlineView; } 379 void SetEditMode(bool state); 380 void Refresh(); 381 382 virtual BSize MinSize(); 383 virtual BSize PreferredSize(); 384 virtual BSize MaxSize(); 385 386 387 protected: 388 virtual void MessageReceived(BMessage* message); 389 virtual void KeyDown(const char* bytes, int32 numBytes); 390 virtual void AttachedToWindow(); 391 virtual void WindowActivated(bool active); 392 virtual void Draw(BRect updateRect); 393 394 virtual void LayoutInvalidated(bool descendants = false); 395 virtual void DoLayout(); 396 397 private: 398 void _Init(); 399 void _GetChildViewRects(const BRect& bounds, 400 BRect& titleRect, BRect& outlineRect, 401 BRect& vScrollBarRect, 402 BRect& hScrollBarRect); 403 404 rgb_color fColorList[B_COLOR_TOTAL]; 405 BPrivate::TitleView* fTitleView; 406 BPrivate::OutlineView* fOutlineView; 407 BList fColumns; 408 BScrollBar* fHorizontalScrollBar; 409 BScrollBar* fVerticalScrollBar; 410 BList fSortColumns; 411 BView* fStatusView; 412 BMessage* fSelectionMessage; 413 bool fSortingEnabled; 414 float fLatchWidth; 415 border_style fBorderStyle; 416 bool fShowingHorizontalScrollBar; 417 }; 418 419 #endif // _COLUMN_LIST_VIEW_H 420