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 friend class AbstractColumn; 51 52 typedef BObjectList<AbstractColumn> ColumnList; 53 54 protected: 55 virtual AbstractColumn* CreateColumn(TableColumn* column) = 0; 56 57 virtual void ColumnMouseDown(AbstractColumn* column, 58 BRow* row, BField* field, BPoint point, 59 uint32 buttons) = 0; 60 virtual void ColumnMouseUp(AbstractColumn* column, 61 BRow* row, BField* field, BPoint point, 62 uint32 buttons) = 0; 63 64 AbstractColumn* GetColumn(TableColumn* column) const; 65 66 protected: 67 ColumnList fColumns; 68 }; 69 70 71 // implementation private 72 73 class AbstractTable::AbstractColumn : public BColumn { 74 public: 75 AbstractColumn(TableColumn* tableColumn); 76 virtual ~AbstractColumn(); 77 78 void SetTable(AbstractTable* table); 79 80 virtual void SetModel(AbstractTableModelBase* model) = 0; 81 82 TableColumn* GetTableColumn() const { return fTableColumn; } 83 84 virtual void MouseDown(BColumnListView* parent, BRow* row, 85 BField* field, BRect fieldRect, 86 BPoint point, uint32 buttons); 87 virtual void MouseUp(BColumnListView* parent, BRow* row, 88 BField* field); 89 90 protected: 91 TableColumn* fTableColumn; 92 AbstractTable* fTable; 93 }; 94 95 96 #endif // ABSTRACT_TABLE_H 97