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