Skip to content

Commit

Permalink
{Tree,Table}: Add cell rect accessor.
Browse files Browse the repository at this point in the history
BColumnListView:
- Add helper method for getting the visible rect of a given field.
  Refactor SuggestTextPosition to use it.

{Tree,Table}:
- Add wrapper to retrieve table cell rect using the aforementioned
  BCLV helper.
  • Loading branch information
anevilyak committed Jul 18, 2015
1 parent 8988902 commit df459da
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
3 changes: 3 additions & 0 deletions headers/private/interface/ColumnListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ class BColumnListView : public BView, public BInvoker {
BPoint SuggestTextPosition(const BRow* row,
const BColumn* column = NULL) const;

BRect GetFieldRect(const BRow* row,
const BColumn* column) const;

void SetLatchWidth(float width);
float LatchWidth() const;
virtual void DrawLatch(BView* view, BRect frame,
Expand Down
17 changes: 17 additions & 0 deletions src/apps/debuganalyzer/gui/table/Table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,23 @@ Table::RemoveTableListener(TableListener* listener)
}


status_t
Table::GetCellRectAt(int32 rowIndex, int32 colIndex, BRect& _output) const
{
BRow* row = fRows.ItemAt(rowIndex);
if (row == NULL)
return B_ENTRY_NOT_FOUND;

AbstractColumn* column = fColumns.ItemAt(colIndex);
if (column == NULL)
return B_ENTRY_NOT_FOUND;

_output = GetFieldRect(row, column);

return B_OK;
}


bool
Table::GetToolTipAt(BPoint point, BToolTip** _tip)
{
Expand Down
3 changes: 3 additions & 0 deletions src/apps/debuganalyzer/gui/table/Table.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class Table : public AbstractTable, private TableModelListener {
bool AddTableListener(TableListener* listener);
void RemoveTableListener(TableListener* listener);

virtual status_t GetCellRectAt(int32 rowIndex, int32 colIndex,
BRect& _output) const;

protected:
virtual bool GetToolTipAt(BPoint point, BToolTip** _tip);

Expand Down
18 changes: 18 additions & 0 deletions src/apps/debuganalyzer/gui/table/TreeTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,24 @@ TreeTable::RemoveTreeTableListener(TreeTableListener* listener)
}


status_t
TreeTable::GetCellRectAt(const TreeTablePath& path, int32 colIndex,
BRect& _output) const
{
TreeTableNode* node = _NodeForPath(path);
if (node == NULL)
return B_ENTRY_NOT_FOUND;

AbstractColumn* column = fColumns.ItemAt(colIndex);
if (column == NULL)
return B_ENTRY_NOT_FOUND;

_output = GetFieldRect(node->Row(), column);

return B_OK;
}


bool
TreeTable::GetToolTipAt(BPoint point, BToolTip** _tip)
{
Expand Down
3 changes: 3 additions & 0 deletions src/apps/debuganalyzer/gui/table/TreeTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class TreeTable : public AbstractTable, private TreeTableModelListener {
void RemoveTreeTableListener(
TreeTableListener* listener);

virtual status_t GetCellRectAt(const TreeTablePath& path,
int32 colIndex, BRect& _output) const;

protected:
virtual bool GetToolTipAt(BPoint point, BToolTip** _tip);

Expand Down
21 changes: 15 additions & 6 deletions src/kits/interface/ColumnListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,10 +1501,23 @@ BColumnListView::EditColor() const
BPoint
BColumnListView::SuggestTextPosition(const BRow* row,
const BColumn* inColumn) const
{
BRect rect(GetFieldRect(row, inColumn));

font_height fh;
fOutlineView->GetFontHeight(&fh);
float baseline = floor(rect.top + fh.ascent
+ (rect.Height() + 1 - (fh.ascent + fh.descent)) / 2);
return BPoint(rect.left + 8, baseline);
}


BRect
BColumnListView::GetFieldRect(const BRow* row, const BColumn* inColumn) const
{
BRect rect;
GetRowRect(row, &rect);
if (inColumn) {
if (inColumn != NULL) {
float leftEdge = MAX(kLeftMargin, LatchWidth());
for (int index = 0; index < fColumns.CountItems(); index++) {
BColumn* column = (BColumn*) fColumns.ItemAt(index);
Expand All @@ -1521,11 +1534,7 @@ BColumnListView::SuggestTextPosition(const BRow* row,
}
}

font_height fh;
fOutlineView->GetFontHeight(&fh);
float baseline = floor(rect.top + fh.ascent
+ (rect.Height() + 1 - (fh.ascent + fh.descent)) / 2);
return BPoint(rect.left + 8, baseline);
return rect;
}


Expand Down

0 comments on commit df459da

Please sign in to comment.