Added support for mouse down/up events in [Tree]TableListener.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33900 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-11-05 17:22:14 +00:00
parent f56fa21bdb
commit 6309d64e37
6 changed files with 237 additions and 1 deletions

View File

@ -7,6 +7,9 @@
#include <new>
#include <Looper.h>
#include <Message.h>
#include "table/TableColumn.h"
@ -25,8 +28,10 @@ AbstractTable::AbstractColumn::AbstractColumn(TableColumn* tableColumn)
:
BColumn(tableColumn->Width(), tableColumn->MinWidth(),
tableColumn->MaxWidth(), tableColumn->Alignment()),
fTableColumn(tableColumn)
fTableColumn(tableColumn),
fTable(NULL)
{
SetWantsEvents(true);
}
@ -36,6 +41,67 @@ AbstractTable::AbstractColumn::~AbstractColumn()
}
void
AbstractTable::AbstractColumn::SetTable(AbstractTable* table)
{
fTable = table;
}
void
AbstractTable::AbstractColumn::MouseDown(BColumnListView* parent, BRow* row,
BField* field, BRect fieldRect, BPoint point, uint32 _buttons)
{
if (fTable == NULL)
return;
if (fTable == NULL)
return;
BLooper* window = fTable->Looper();
if (window == NULL)
return;
BMessage* message = window->CurrentMessage();
if (message == NULL)
return;
int32 buttons;
// Note: The _buttons parameter cannot be trusted.
BPoint screenWhere;
if (message->FindInt32("buttons", &buttons) != B_OK
|| message->FindPoint("screen_where", &screenWhere) != B_OK) {
return;
}
fTable->ColumnMouseDown(this, row, field, screenWhere, buttons);
}
void
AbstractTable::AbstractColumn::MouseUp(BColumnListView* parent, BRow* row,
BField* field)
{
if (fTable == NULL)
return;
BLooper* window = fTable->Looper();
if (window == NULL)
return;
BMessage* message = window->CurrentMessage();
if (message == NULL)
return;
int32 buttons;
BPoint screenWhere;
if (message->FindInt32("buttons", &buttons) != B_OK
|| message->FindPoint("screen_where", &screenWhere) != B_OK) {
return;
}
fTable->ColumnMouseUp(this, row, field, screenWhere, buttons);
}
// #pragma mark - AbstractTable
@ -60,6 +126,7 @@ AbstractTable::AddColumn(TableColumn* column)
return;
AbstractColumn* privateColumn = CreateColumn(column);
privateColumn->SetTable(this);
if (!fColumns.AddItem(privateColumn)) {
delete privateColumn;

View File

@ -47,12 +47,20 @@ public:
protected:
class AbstractColumn;
friend class AbstractColumn;
typedef BObjectList<AbstractColumn> ColumnList;
protected:
virtual AbstractColumn* CreateColumn(TableColumn* column) = 0;
virtual void ColumnMouseDown(AbstractColumn* column,
BRow* row, BField* field, BPoint point,
uint32 buttons) = 0;
virtual void ColumnMouseUp(AbstractColumn* column,
BRow* row, BField* field, BPoint point,
uint32 buttons) = 0;
AbstractColumn* GetColumn(TableColumn* column) const;
protected:
@ -67,12 +75,21 @@ public:
AbstractColumn(TableColumn* tableColumn);
virtual ~AbstractColumn();
void SetTable(AbstractTable* table);
virtual void SetModel(AbstractTableModelBase* model) = 0;
TableColumn* GetTableColumn() const { return fTableColumn; }
virtual void MouseDown(BColumnListView* parent, BRow* row,
BField* field, BRect fieldRect,
BPoint point, uint32 buttons);
virtual void MouseUp(BColumnListView* parent, BRow* row,
BField* field);
protected:
TableColumn* fTableColumn;
AbstractTable* fTable;
};

View File

@ -222,6 +222,20 @@ TableListener::TableRowInvoked(Table* table, int32 rowIndex)
}
void
TableListener::TableCellMouseDown(Table* table, int32 rowIndex,
int32 columnIndex, BPoint screenWhere, uint32 buttons)
{
}
void
TableListener::TableCellMouseUp(Table* table, int32 rowIndex, int32 columnIndex,
BPoint screenWhere, uint32 buttons)
{
}
// #pragma mark - Column
@ -512,6 +526,48 @@ Table::CreateColumn(TableColumn* column)
}
void
Table::ColumnMouseDown(AbstractColumn* column, BRow* row, BField* field,
BPoint screenWhere, uint32 buttons)
{
if (!fListeners.IsEmpty()) {
// get the table row and column indices
int32 rowIndex = _ModelIndexOfRow(row);
int32 columnIndex = column->LogicalFieldNum();
if (rowIndex < 0 || columnIndex < 0)
return;
// notify listeners
int32 listenerCount = fListeners.CountItems();
for (int32 i = listenerCount - 1; i >= 0; i--) {
fListeners.ItemAt(i)->TableCellMouseDown(this, rowIndex,
columnIndex, screenWhere, buttons);
}
}
}
void
Table::ColumnMouseUp(AbstractColumn* column, BRow* row, BField* field,
BPoint screenWhere, uint32 buttons)
{
if (!fListeners.IsEmpty()) {
// get the table row and column indices
int32 rowIndex = _ModelIndexOfRow(row);
int32 columnIndex = column->LogicalFieldNum();
if (rowIndex < 0 || columnIndex < 0)
return;
// notify listeners
int32 listenerCount = fListeners.CountItems();
for (int32 i = listenerCount - 1; i >= 0; i--) {
fListeners.ItemAt(i)->TableCellMouseUp(this, rowIndex, columnIndex,
screenWhere, buttons);
}
}
}
void
Table::TableRowsAdded(TableModel* model, int32 rowIndex, int32 count)
{

View File

@ -95,6 +95,13 @@ public:
virtual void TableSelectionChanged(Table* table);
virtual void TableRowInvoked(Table* table, int32 rowIndex);
virtual void TableCellMouseDown(Table* table, int32 rowIndex,
int32 columnIndex, BPoint screenWhere,
uint32 buttons);
virtual void TableCellMouseUp(Table* table, int32 rowIndex,
int32 columnIndex, BPoint screenWhere,
uint32 buttons);
};
@ -133,6 +140,13 @@ protected:
virtual AbstractColumn* CreateColumn(TableColumn* column);
virtual void ColumnMouseDown(AbstractColumn* column,
BRow* row, BField* field,
BPoint screenWhere, uint32 buttons);
virtual void ColumnMouseUp(AbstractColumn* column,
BRow* row, BField* field,
BPoint screenWhere, uint32 buttons);
private:
virtual void TableRowsAdded(TableModel* model,
int32 rowIndex, int32 count);

View File

@ -254,6 +254,22 @@ TreeTableListener::TreeTableNodeExpandedChanged(TreeTable* table,
}
void
TreeTableListener::TreeTableCellMouseDown(TreeTable* table,
const TreeTablePath& path, int32 columnIndex, BPoint screenWhere,
uint32 buttons)
{
}
void
TreeTableListener::TreeTableCellMouseUp(TreeTable* table,
const TreeTablePath& path, int32 columnIndex, BPoint screenWhere,
uint32 buttons)
{
}
// #pragma mark - Column
@ -817,6 +833,56 @@ TreeTable::CreateColumn(TableColumn* column)
}
void
TreeTable::ColumnMouseDown(AbstractColumn* column, BRow* _row, BField* field,
BPoint screenWhere, uint32 buttons)
{
if (!fListeners.IsEmpty()) {
// get the table node and the column index
TreeTableRow* row = dynamic_cast<TreeTableRow*>(_row);
int32 columnIndex = column->LogicalFieldNum();
if (row == NULL || columnIndex < 0)
return;
// get the node path
TreeTablePath path;
_GetPathForNode(row->Node(), path);
// notify listeners
int32 listenerCount = fListeners.CountItems();
for (int32 i = listenerCount - 1; i >= 0; i--) {
fListeners.ItemAt(i)->TreeTableCellMouseDown(this, path,
columnIndex, screenWhere, buttons);
}
}
}
void
TreeTable::ColumnMouseUp(AbstractColumn* column, BRow* _row, BField* field,
BPoint screenWhere, uint32 buttons)
{
if (!fListeners.IsEmpty()) {
// get the table node and the column index
TreeTableRow* row = dynamic_cast<TreeTableRow*>(_row);
int32 columnIndex = column->LogicalFieldNum();
if (row == NULL || columnIndex < 0)
return;
// get the node path
TreeTablePath path;
_GetPathForNode(row->Node(), path);
// notify listeners
int32 listenerCount = fListeners.CountItems();
for (int32 i = listenerCount - 1; i >= 0; i--) {
fListeners.ItemAt(i)->TreeTableCellMouseUp(this, path, columnIndex,
screenWhere, buttons);
}
}
}
void
TreeTable::TableNodesAdded(TreeTableModel* model, const TreeTablePath& path,
int32 childIndex, int32 count)

View File

@ -131,6 +131,15 @@ public:
const TreeTablePath& path);
virtual void TreeTableNodeExpandedChanged(TreeTable* table,
const TreeTablePath& path, bool expanded);
virtual void TreeTableCellMouseDown(TreeTable* table,
const TreeTablePath& path,
int32 columnIndex, BPoint screenWhere,
uint32 buttons);
virtual void TreeTableCellMouseUp(TreeTable* table,
const TreeTablePath& path,
int32 columnIndex, BPoint screenWhere,
uint32 buttons);
};
@ -172,6 +181,13 @@ protected:
virtual AbstractColumn* CreateColumn(TableColumn* column);
virtual void ColumnMouseDown(AbstractColumn* column,
BRow* row, BField* field,
BPoint screenWhere, uint32 buttons);
virtual void ColumnMouseUp(AbstractColumn* column,
BRow* row, BField* field,
BPoint screenWhere, uint32 buttons);
private:
virtual void TableNodesAdded(TreeTableModel* model,
const TreeTablePath& path, int32 childIndex,