supports double clicking column title separator to preferred column size

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28371 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2008-10-29 22:50:52 +00:00
parent 3ebfe9b245
commit 2c558054fe
4 changed files with 52 additions and 3 deletions

View File

@ -183,6 +183,7 @@ public:
virtual void MouseUp(BColumnListView *parent, BRow *row, BField *field); virtual void MouseUp(BColumnListView *parent, BRow *row, BField *field);
virtual void GetColumnName(BString* into) const; virtual void GetColumnName(BString* into) const;
virtual float GetPreferredWidth(BField *field, BView *parent) const;
bool IsVisible() const; bool IsVisible() const;
void SetVisible(bool); void SetVisible(bool);

View File

@ -85,6 +85,7 @@ class BStringColumn : public BTitledColumn
BView* parent); BView* parent);
virtual int CompareFields (BField* field1, virtual int CompareFields (BField* field1,
BField* field2); BField* field2);
virtual float GetPreferredWidth(BField* field, BView* parent) const;
virtual bool AcceptsField (const BField* field) const; virtual bool AcceptsField (const BField* field) const;
private: private:

View File

@ -237,7 +237,7 @@ private:
int32 FindColumn(BPoint, float *out_leftEdge); int32 FindColumn(BPoint, float *out_leftEdge);
void FixScrollBar(bool scrollToFit); void FixScrollBar(bool scrollToFit);
void DragSelectedColumn(BPoint); void DragSelectedColumn(BPoint);
void ResizeSelectedColumn(BPoint); void ResizeSelectedColumn(BPoint, bool = false);
void ComputeDragBoundries(BColumn*, BPoint); void ComputeDragBoundries(BColumn*, BPoint);
void DrawTitle(BView*, BRect, BColumn*, bool depressed); void DrawTitle(BView*, BRect, BColumn*, bool depressed);
@ -296,6 +296,7 @@ public:
void RedrawColumn(BColumn *column, float leftEdge, bool isFirstColumn); void RedrawColumn(BColumn *column, float leftEdge, bool isFirstColumn);
void StartSorting(); void StartSorting();
float GetColumnPreferredWidth(BColumn *column);
void AddRow(BRow*, int32 index, BRow *TheRow); void AddRow(BRow*, int32 index, BRow *TheRow);
BRow* CurrentSelection(BRow *lastSelected) const; BRow* CurrentSelection(BRow *lastSelected) const;
@ -619,6 +620,11 @@ void BColumn::GetColumnName(BString* into) const
*into = "(Unnamed)"; *into = "(Unnamed)";
} }
float BColumn::GetPreferredWidth(BField *field, BView *parent) const
{
return fWidth;
}
bool BColumn::IsVisible() const bool BColumn::IsVisible() const
{ {
return fVisible; return fVisible;
@ -1798,13 +1804,21 @@ void TitleView::SetColumnFlags(column_flags flags)
} }
void TitleView::ResizeSelectedColumn(BPoint position) void TitleView::ResizeSelectedColumn(BPoint position, bool preferred)
{ {
float minWidth = fSelectedColumn->MinWidth(); float minWidth = fSelectedColumn->MinWidth();
float maxWidth = fSelectedColumn->MaxWidth(); float maxWidth = fSelectedColumn->MaxWidth();
float originalEdge = fSelectedColumnRect.left + fSelectedColumn->Width(); float originalEdge = fSelectedColumnRect.left + fSelectedColumn->Width();
if (position.x > fSelectedColumnRect.left + maxWidth) if (preferred) {
float width = fOutlineView->GetColumnPreferredWidth(fSelectedColumn);
if (width < minWidth)
fSelectedColumn->SetWidth(minWidth);
else if (width > maxWidth)
fSelectedColumn->SetWidth(maxWidth);
else
fSelectedColumn->SetWidth(width);
} else if (position.x > fSelectedColumnRect.left + maxWidth)
fSelectedColumn->SetWidth(maxWidth); fSelectedColumn->SetWidth(maxWidth);
else if (position.x < fSelectedColumnRect.left + minWidth) else if (position.x < fSelectedColumnRect.left + minWidth)
fSelectedColumn->SetWidth(minWidth); fSelectedColumn->SetWidth(minWidth);
@ -2138,6 +2152,13 @@ void TitleView::MouseDown(BPoint position)
&& position.x < rightEdge + kColumnResizeAreaWidth / 2 && position.x < rightEdge + kColumnResizeAreaWidth / 2
&& column->MaxWidth() > column->MinWidth() && column->MaxWidth() > column->MinWidth()
&& (fColumnFlags & B_ALLOW_COLUMN_RESIZE)) { && (fColumnFlags & B_ALLOW_COLUMN_RESIZE)) {
int32 clicks = 0;
Window()->CurrentMessage()->FindInt32("clicks", &clicks);
if (clicks == 2) {
ResizeSelectedColumn(position, true);
fCurrentState = INACTIVE;
break;
}
fCurrentState = RESIZING_COLUMN; fCurrentState = RESIZING_COLUMN;
fSelectedColumn = column; fSelectedColumn = column;
fSelectedColumnRect.Set(leftEdge, 0, rightEdge, fVisibleRect.Height()); fSelectedColumnRect.Set(leftEdge, 0, rightEdge, fVisibleRect.Height());
@ -4036,6 +4057,22 @@ void OutlineView::InvalidateCachedPositions()
FindRect(fFocusRow, &fFocusRowRect); FindRect(fFocusRow, &fFocusRowRect);
} }
float OutlineView::GetColumnPreferredWidth(BColumn *column)
{
float preferred = 0.0;
for (RecursiveOutlineIterator iterator(&fRows); iterator.CurrentRow();
iterator.GoToNext()) {
BRow *row = iterator.CurrentRow();
BField *field = row->GetField(column->fFieldID);
if (field) {
float width = column->GetPreferredWidth(field, this);
if (preferred < width)
preferred = width;
}
}
return preferred;
}
// #pragma mark - // #pragma mark -

View File

@ -187,6 +187,16 @@ BStringColumn::DrawField(BField* _field, BRect rect, BView* parent)
} }
float
BStringColumn::GetPreferredWidth(BField *_field, BView* parent) const
{
BStringField* field = static_cast<BStringField*>(_field);
BFont font;
parent->GetFont(&font);
return font.StringWidth(field->String()) + 2 * kTEXT_MARGIN;
}
int int
BStringColumn::CompareFields(BField* field1, BField* field2) BStringColumn::CompareFields(BField* field1, BField* field2)
{ {