1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include "table/AbstractTable.h" 7 8 #include <new> 9 10 #include "table/TableColumn.h" 11 12 13 // #pragma mark - AbstractTableModelBase 14 15 16 AbstractTableModelBase::~AbstractTableModelBase() 17 { 18 } 19 20 21 // #pragma mark - AbstractColumn 22 23 24 AbstractTable::AbstractColumn::AbstractColumn(TableColumn* tableColumn) 25 : 26 BColumn(tableColumn->Width(), tableColumn->MinWidth(), 27 tableColumn->MaxWidth(), tableColumn->Alignment()), 28 fTableColumn(tableColumn) 29 { 30 } 31 32 33 AbstractTable::AbstractColumn::~AbstractColumn() 34 { 35 delete fTableColumn; 36 } 37 38 39 // #pragma mark - AbstractTable 40 41 42 AbstractTable::AbstractTable(const char* name, uint32 flags, 43 border_style borderStyle, bool showHorizontalScrollbar) 44 : 45 BColumnListView(name, flags, borderStyle, showHorizontalScrollbar), 46 fColumns(20, true) 47 { 48 } 49 50 51 AbstractTable::~AbstractTable() 52 { 53 } 54 55 56 void 57 AbstractTable::AddColumn(TableColumn* column) 58 { 59 if (column == NULL) 60 return; 61 62 AbstractColumn* privateColumn = CreateColumn(column); 63 64 if (!fColumns.AddItem(privateColumn)) { 65 delete privateColumn; 66 throw std::bad_alloc(); 67 } 68 69 BColumnListView::AddColumn(privateColumn, column->ModelIndex()); 70 71 // TODO: The derived classes need to be notified, so that they can create 72 // fields for the existing rows. 73 } 74 75 76 void 77 AbstractTable::ResizeColumnToPreferred(int32 index) 78 { 79 BColumnListView::ResizeColumnToPreferred(index); 80 } 81 82 83 void 84 AbstractTable::ResizeAllColumnsToPreferred() 85 { 86 BColumnListView::ResizeAllColumnsToPreferred(); 87 } 88 89 90 list_view_type 91 AbstractTable::SelectionMode() const 92 { 93 return BColumnListView::SelectionMode(); 94 } 95 96 97 void 98 AbstractTable::SetSelectionMode(list_view_type type) 99 { 100 BColumnListView::SetSelectionMode(type); 101 } 102 103 104 void 105 AbstractTable::DeselectAll() 106 { 107 BColumnListView::DeselectAll(); 108 } 109 110 111 void 112 AbstractTable::SetSortingEnabled(bool enabled) 113 { 114 BColumnListView::SetSortingEnabled(enabled); 115 } 116 117 118 bool 119 AbstractTable::SortingEnabled() const 120 { 121 return BColumnListView::SortingEnabled(); 122 } 123 124 125 void 126 AbstractTable::SetSortColumn(TableColumn* column, bool add, bool ascending) 127 { 128 if (AbstractColumn* privateColumn = GetColumn(column)) 129 BColumnListView::SetSortColumn(privateColumn, add, ascending); 130 } 131 132 133 void 134 AbstractTable::ClearSortColumns() 135 { 136 BColumnListView::ClearSortColumns(); 137 } 138 139 140 AbstractTable::AbstractColumn* 141 AbstractTable::GetColumn(TableColumn* column) const 142 { 143 for (int32 i = 0; AbstractColumn* privateColumn = fColumns.ItemAt(i); i++) { 144 if (privateColumn->GetTableColumn() == column) 145 return privateColumn; 146 } 147 148 return NULL; 149 } 150