1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef ABSTRACT_TABLE_H 6 #define ABSTRACT_TABLE_H 7 8 #include <ObjectList.h> 9 #include <ColumnListView.h> 10 11 12 class TableColumn; 13 14 15 class AbstractTableModelBase { 16 public: 17 virtual ~AbstractTableModelBase(); 18 19 virtual int32 CountColumns() const = 0; 20 }; 21 22 23 // NOTE: Intention is to inherit from "protected BColumnListView", but GCC2 24 // has problems dynamic_casting a BHandler pointer to a BView then... 25 class AbstractTable : public BColumnListView { 26 public: 27 AbstractTable(const char* name, uint32 flags, 28 border_style borderStyle = B_NO_BORDER, 29 bool showHorizontalScrollbar = true); 30 virtual ~AbstractTable(); 31 32 BView* ToView() { return this; } 33 34 virtual void AddColumn(TableColumn* column); 35 void ResizeColumnToPreferred(int32 index); 36 void ResizeAllColumnsToPreferred(); 37 38 list_view_type SelectionMode() const; 39 void SetSelectionMode(list_view_type type); 40 void DeselectAll(); 41 42 void SetSortingEnabled(bool enabled); 43 bool SortingEnabled() const; 44 void SetSortColumn(TableColumn* column, bool add, 45 bool ascending); 46 void ClearSortColumns(); 47 48 protected: 49 class AbstractColumn; 50 51 typedef BObjectList<AbstractColumn> ColumnList; 52 53 protected: 54 virtual AbstractColumn* CreateColumn(TableColumn* column) = 0; 55 56 AbstractColumn* GetColumn(TableColumn* column) const; 57 58 protected: 59 ColumnList fColumns; 60 }; 61 62 63 // implementation private 64 65 class AbstractTable::AbstractColumn : public BColumn { 66 public: 67 AbstractColumn(TableColumn* tableColumn); 68 virtual ~AbstractColumn(); 69 70 virtual void SetModel(AbstractTableModelBase* model) = 0; 71 72 TableColumn* GetTableColumn() const { return fTableColumn; } 73 74 protected: 75 TableColumn* fTableColumn; 76 }; 77 78 79 #endif // ABSTRACT_TABLE_H 80