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 void SetColumnVisible(BColumn* column, 301 bool isVisible); 302 void SetColumnVisible(int32, bool); 303 bool IsColumnVisible(int32) const; 304 void SetColumnFlags(column_flags flags); 305 306 // Row manipulation 307 const BRow* RowAt(int32 index, BRow *parent = 0) const; 308 BRow* RowAt(int32 index, BRow *parent = 0); 309 const BRow* RowAt(BPoint) const; 310 BRow* RowAt(BPoint); 311 bool GetRowRect(const BRow* row, BRect* _rect) const; 312 bool FindParent(BRow* row, BRow** _parent, 313 bool *_isVisible) const; 314 int32 IndexOf(BRow* row); 315 int32 CountRows(BRow* parent = 0) const; 316 void AddRow(BRow* row, BRow* parent = NULL); 317 void AddRow(BRow* row, int32 index, 318 BRow* parent = NULL); 319 320 void ScrollTo(const BRow* Row); 321 void ScrollTo(BPoint point); 322 323 // Does not delete row or children at this time. 324 // todo: Make delete row and children 325 void RemoveRow(BRow* row); 326 327 void UpdateRow(BRow* row); 328 void Clear(); 329 330 // Appearance (DEPRECATED) 331 void GetFont(BFont* font) const 332 { BView::GetFont(font); } 333 virtual void SetFont(const BFont* font, 334 uint32 mask = B_FONT_ALL); 335 virtual void SetHighColor(rgb_color); 336 void SetSelectionColor(rgb_color); 337 void SetBackgroundColor(rgb_color); 338 void SetEditColor(rgb_color); 339 const rgb_color SelectionColor() const; 340 const rgb_color BackgroundColor() const; 341 const rgb_color EditColor() const; 342 343 // Appearance (NEW STYLE) 344 void SetColor(ColumnListViewColor colorIndex, 345 rgb_color color); 346 void SetFont(ColumnListViewFont fontIndex, 347 const BFont* font, 348 uint32 mask = B_FONT_ALL); 349 rgb_color Color(ColumnListViewColor colorIndex) const; 350 void GetFont(ColumnListViewFont fontIndex, 351 BFont* font) const; 352 353 BPoint SuggestTextPosition(const BRow* row, 354 const BColumn* column = NULL) const; 355 356 void SetLatchWidth(float width); 357 float LatchWidth() const; 358 virtual void DrawLatch(BView* view, BRect frame, 359 LatchType type, BRow* row); 360 virtual void MakeFocus(bool isfocus = true); 361 void SaveState(BMessage* archive); 362 void LoadState(BMessage* archive); 363 364 BView* ScrollView() const 365 { return (BView*)fOutlineView; } 366 void SetEditMode(bool state); 367 void Refresh(); 368 369 protected: 370 virtual void MessageReceived(BMessage* message); 371 virtual void KeyDown(const char* bytes, int32 numBytes); 372 virtual void AttachedToWindow(); 373 virtual void WindowActivated(bool active); 374 virtual void Draw(BRect updateRect); 375 376 virtual BSize MinSize(); 377 virtual BSize PreferredSize(); 378 virtual BSize MaxSize(); 379 380 virtual void InvalidateLayout(bool descendants = false); 381 virtual void DoLayout(); 382 383 private: 384 void _Init(bool showHorizontalScrollbar); 385 void _GetChildViewRects(const BRect& bounds, 386 bool showHorizontalScrollBar, 387 BRect& titleRect, BRect& outlineRect, 388 BRect& vScrollBarRect, 389 BRect& hScrollBarRect); 390 391 rgb_color fColorList[B_COLOR_TOTAL]; 392 BPrivate::TitleView* fTitleView; 393 BPrivate::OutlineView* fOutlineView; 394 BList fColumns; 395 BScrollBar* fHorizontalScrollBar; 396 BScrollBar* fVerticalScrollBar; 397 BList fSortColumns; 398 BView* fStatusView; 399 BMessage* fSelectionMessage; 400 bool fSortingEnabled; 401 float fLatchWidth; 402 border_style fBorderStyle; 403 }; 404 405 #endif // _COLUMN_LIST_VIEW_H 406