{Tree,Table}: Add cell rect accessor.

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.
This commit is contained in:
Rene Gollent 2015-07-15 21:34:44 -04:00
parent 8988902ec3
commit df459da6ed
6 changed files with 59 additions and 6 deletions

View File

@ -363,6 +363,9 @@ public:
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,

View File

@ -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)
{

View File

@ -135,6 +135,9 @@ public:
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);

View File

@ -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)
{

View File

@ -195,6 +195,9 @@ public:
void RemoveTreeTableListener(
TreeTableListener* listener);
virtual status_t GetCellRectAt(const TreeTablePath& path,
int32 colIndex, BRect& _output) const;
protected:
virtual bool GetToolTipAt(BPoint point, BToolTip** _tip);

View File

@ -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);
@ -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;
}