From 6309d64e37f51b2b639fb2ef1a2eaf46b335f832 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 5 Nov 2009 17:22:14 +0000 Subject: [PATCH] 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 --- .../debuganalyzer/gui/table/AbstractTable.cpp | 69 ++++++++++++++++++- .../debuganalyzer/gui/table/AbstractTable.h | 17 +++++ src/apps/debuganalyzer/gui/table/Table.cpp | 56 +++++++++++++++ src/apps/debuganalyzer/gui/table/Table.h | 14 ++++ .../debuganalyzer/gui/table/TreeTable.cpp | 66 ++++++++++++++++++ src/apps/debuganalyzer/gui/table/TreeTable.h | 16 +++++ 6 files changed, 237 insertions(+), 1 deletion(-) diff --git a/src/apps/debuganalyzer/gui/table/AbstractTable.cpp b/src/apps/debuganalyzer/gui/table/AbstractTable.cpp index e17def3caa..c548a65827 100644 --- a/src/apps/debuganalyzer/gui/table/AbstractTable.cpp +++ b/src/apps/debuganalyzer/gui/table/AbstractTable.cpp @@ -7,6 +7,9 @@ #include +#include +#include + #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; diff --git a/src/apps/debuganalyzer/gui/table/AbstractTable.h b/src/apps/debuganalyzer/gui/table/AbstractTable.h index 12953a2b6f..ed6ef800e6 100644 --- a/src/apps/debuganalyzer/gui/table/AbstractTable.h +++ b/src/apps/debuganalyzer/gui/table/AbstractTable.h @@ -47,12 +47,20 @@ public: protected: class AbstractColumn; + friend class AbstractColumn; typedef BObjectList 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; }; diff --git a/src/apps/debuganalyzer/gui/table/Table.cpp b/src/apps/debuganalyzer/gui/table/Table.cpp index 5b7bcb00fd..e0b6e0ff9b 100644 --- a/src/apps/debuganalyzer/gui/table/Table.cpp +++ b/src/apps/debuganalyzer/gui/table/Table.cpp @@ -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) { diff --git a/src/apps/debuganalyzer/gui/table/Table.h b/src/apps/debuganalyzer/gui/table/Table.h index b75c25b067..1018849c85 100644 --- a/src/apps/debuganalyzer/gui/table/Table.h +++ b/src/apps/debuganalyzer/gui/table/Table.h @@ -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); diff --git a/src/apps/debuganalyzer/gui/table/TreeTable.cpp b/src/apps/debuganalyzer/gui/table/TreeTable.cpp index 88e853ca33..0c20843914 100644 --- a/src/apps/debuganalyzer/gui/table/TreeTable.cpp +++ b/src/apps/debuganalyzer/gui/table/TreeTable.cpp @@ -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(_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(_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) diff --git a/src/apps/debuganalyzer/gui/table/TreeTable.h b/src/apps/debuganalyzer/gui/table/TreeTable.h index 31e590e8d9..a4758690e3 100644 --- a/src/apps/debuganalyzer/gui/table/TreeTable.h +++ b/src/apps/debuganalyzer/gui/table/TreeTable.h @@ -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,