Added basic listener support to Table.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30400 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -137,6 +137,20 @@ TableColumn::GetPreferredWidth(BField* _field, BView* parent) const
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - TableListener
|
||||
|
||||
|
||||
TableListener::~TableListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TableListener::TableRowInvoked(Table* table, int32 rowIndex)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - Table
|
||||
|
||||
|
||||
@@ -233,3 +247,34 @@ Table::AddColumn(TableColumn* column)
|
||||
|
||||
BColumnListView::AddColumn(column, column->ModelIndex());
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Table::AddTableListener(TableListener* listener)
|
||||
{
|
||||
return fListeners.AddItem(listener);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Table::RemoveTableListener(TableListener* listener)
|
||||
{
|
||||
fListeners.RemoveItem(listener);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Table::ItemInvoked()
|
||||
{
|
||||
if (fListeners.IsEmpty())
|
||||
return;
|
||||
|
||||
BRow* row = CurrentSelection();
|
||||
if (row == NULL)
|
||||
return;
|
||||
|
||||
int32 index = IndexOf(row);
|
||||
int32 listenerCount = fListeners.CountItems();
|
||||
for (int32 i = listenerCount - 1; i >= 0; i--)
|
||||
fListeners.ItemAt(i)->TableRowInvoked(this, index);
|
||||
}
|
||||
|
||||
@@ -66,6 +66,14 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class TableListener {
|
||||
public:
|
||||
virtual ~TableListener();
|
||||
|
||||
virtual void TableRowInvoked(Table* table, int32 rowIndex);
|
||||
};
|
||||
|
||||
|
||||
class Table : private BColumnListView {
|
||||
public:
|
||||
Table(const char* name, uint32 flags,
|
||||
@@ -84,12 +92,20 @@ public:
|
||||
|
||||
void AddColumn(TableColumn* column);
|
||||
|
||||
bool AddTableListener(TableListener* listener);
|
||||
void RemoveTableListener(TableListener* listener);
|
||||
|
||||
private:
|
||||
typedef BObjectList<TableColumn> ColumnList;
|
||||
typedef BObjectList<TableListener> ListenerList;
|
||||
|
||||
private:
|
||||
virtual void ItemInvoked();
|
||||
|
||||
private:
|
||||
TableModel* fModel;
|
||||
ColumnList fColumns;
|
||||
ListenerList fListeners;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user