* Moved restriction to min/max column width from where GetColumnPreferredWidth
was used into GetColumnPreferredWidth for convenience. * Disabled cached total column width in title view, since it wasn't properly maintained. Instead of finding the bug (the code should use proper listening mechanisms, and such problems would go away automatically), the total width is now calculated on the fly. It is used for updating the horizontal scrollbar. * Resolved TODO in PreferredSize(), the width is now based on the preferred width of all columns. +alphabranch git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32850 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -249,10 +249,12 @@ private:
|
|||||||
void DrawTitle(BView* view, BRect frame,
|
void DrawTitle(BView* view, BRect frame,
|
||||||
BColumn* column, bool depressed);
|
BColumn* column, bool depressed);
|
||||||
|
|
||||||
|
float _VirtualWidth() const;
|
||||||
|
|
||||||
OutlineView* fOutlineView;
|
OutlineView* fOutlineView;
|
||||||
BList* fColumns;
|
BList* fColumns;
|
||||||
BList* fSortColumns;
|
BList* fSortColumns;
|
||||||
float fColumnsWidth;
|
// float fColumnsWidth;
|
||||||
BRect fVisibleRect;
|
BRect fVisibleRect;
|
||||||
|
|
||||||
#if DOUBLE_BUFFERED_COLUMN_RESIZE
|
#if DOUBLE_BUFFERED_COLUMN_RESIZE
|
||||||
@@ -1159,10 +1161,6 @@ BColumnListView::ResizeColumnToPreferred(int32 index)
|
|||||||
|
|
||||||
// get the preferred column width
|
// get the preferred column width
|
||||||
float width = fOutlineView->GetColumnPreferredWidth(column);
|
float width = fOutlineView->GetColumnPreferredWidth(column);
|
||||||
if (width < column->MinWidth())
|
|
||||||
width = column->MinWidth();
|
|
||||||
else if (width > column->MaxWidth())
|
|
||||||
width = column->MaxWidth();
|
|
||||||
|
|
||||||
// set it
|
// set it
|
||||||
float oldWidth = column->Width();
|
float oldWidth = column->Width();
|
||||||
@@ -1879,7 +1877,17 @@ BColumnListView::PreferredSize()
|
|||||||
{
|
{
|
||||||
BSize size = MinSize();
|
BSize size = MinSize();
|
||||||
size.height += ceilf(be_plain_font->Size()) * 20;
|
size.height += ceilf(be_plain_font->Size()) * 20;
|
||||||
// TODO: size.width = entire width of title view (all columns)
|
|
||||||
|
int32 count = CountColumns();
|
||||||
|
if (count > 0) {
|
||||||
|
// return MinSize().width if there are no columns.
|
||||||
|
size.width = 40.0f;
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
BColumn* column = ColumnAt(i);
|
||||||
|
if (column != NULL)
|
||||||
|
size.width += fOutlineView->GetColumnPreferredWidth(column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size);
|
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size);
|
||||||
}
|
}
|
||||||
@@ -2039,7 +2047,7 @@ TitleView::TitleView(BRect rect, OutlineView* horizontalSlave,
|
|||||||
fOutlineView(horizontalSlave),
|
fOutlineView(horizontalSlave),
|
||||||
fColumns(visibleColumns),
|
fColumns(visibleColumns),
|
||||||
fSortColumns(sortColumns),
|
fSortColumns(sortColumns),
|
||||||
fColumnsWidth(0),
|
// fColumnsWidth(0),
|
||||||
fVisibleRect(rect.OffsetToCopy(0, 0)),
|
fVisibleRect(rect.OffsetToCopy(0, 0)),
|
||||||
fCurrentState(INACTIVE),
|
fCurrentState(INACTIVE),
|
||||||
fColumnPop(NULL),
|
fColumnPop(NULL),
|
||||||
@@ -2097,7 +2105,7 @@ TitleView::~TitleView()
|
|||||||
void
|
void
|
||||||
TitleView::ColumnAdded(BColumn* column)
|
TitleView::ColumnAdded(BColumn* column)
|
||||||
{
|
{
|
||||||
fColumnsWidth += column->Width() + 1;
|
// fColumnsWidth += column->Width();
|
||||||
FixScrollBar(false);
|
FixScrollBar(false);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
@@ -2106,7 +2114,7 @@ TitleView::ColumnAdded(BColumn* column)
|
|||||||
void
|
void
|
||||||
TitleView::ColumnResized(BColumn* column, float oldWidth)
|
TitleView::ColumnResized(BColumn* column, float oldWidth)
|
||||||
{
|
{
|
||||||
fColumnsWidth += column->Width() - oldWidth;
|
// fColumnsWidth += column->Width() - oldWidth;
|
||||||
FixScrollBar(false);
|
FixScrollBar(false);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
@@ -2129,10 +2137,10 @@ TitleView::SetColumnVisible(BColumn* column, bool visible)
|
|||||||
// Now really set the visibility
|
// Now really set the visibility
|
||||||
column->fVisible = visible;
|
column->fVisible = visible;
|
||||||
|
|
||||||
if (visible)
|
// if (visible)
|
||||||
fColumnsWidth += column->Width();
|
// fColumnsWidth += column->Width();
|
||||||
else
|
// else
|
||||||
fColumnsWidth -= column->Width();
|
// fColumnsWidth -= column->Width();
|
||||||
|
|
||||||
BRect outlineInvalid(fOutlineView->VisibleRect());
|
BRect outlineInvalid(fOutlineView->VisibleRect());
|
||||||
outlineInvalid.left = titleInvalid.left;
|
outlineInvalid.left = titleInvalid.left;
|
||||||
@@ -2199,8 +2207,7 @@ TitleView::FixScrollBar(bool scrollToFit)
|
|||||||
if (hScrollBar == NULL)
|
if (hScrollBar == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float virtualWidth = fColumnsWidth + MAX(kLeftMargin,
|
float virtualWidth = _VirtualWidth();
|
||||||
fMasterView->LatchWidth()) + kRightMargin * 2;
|
|
||||||
|
|
||||||
if (virtualWidth > fVisibleRect.Width()) {
|
if (virtualWidth > fVisibleRect.Width()) {
|
||||||
hScrollBar->SetProportion(fVisibleRect.Width() / virtualWidth);
|
hScrollBar->SetProportion(fVisibleRect.Width() / virtualWidth);
|
||||||
@@ -2274,15 +2281,11 @@ 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 oldWidth = fSelectedColumn->Width();
|
||||||
|
float originalEdge = fSelectedColumnRect.left + oldWidth;
|
||||||
if (preferred) {
|
if (preferred) {
|
||||||
float width = fOutlineView->GetColumnPreferredWidth(fSelectedColumn);
|
float width = fOutlineView->GetColumnPreferredWidth(fSelectedColumn);
|
||||||
if (width < minWidth)
|
fSelectedColumn->SetWidth(width);
|
||||||
fSelectedColumn->SetWidth(minWidth);
|
|
||||||
else if (width > maxWidth)
|
|
||||||
fSelectedColumn->SetWidth(maxWidth);
|
|
||||||
else
|
|
||||||
fSelectedColumn->SetWidth(width);
|
|
||||||
} else if (position.x > fSelectedColumnRect.left + maxWidth)
|
} 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)
|
||||||
@@ -2326,7 +2329,7 @@ TitleView::ResizeSelectedColumn(BPoint position, bool preferred)
|
|||||||
fOutlineView->RedrawColumn(fSelectedColumn, fSelectedColumnRect.left,
|
fOutlineView->RedrawColumn(fSelectedColumn, fSelectedColumnRect.left,
|
||||||
fResizingFirstColumn);
|
fResizingFirstColumn);
|
||||||
|
|
||||||
fColumnsWidth += dX;
|
// fColumnsWidth += dX;
|
||||||
|
|
||||||
// Update the cursor
|
// Update the cursor
|
||||||
if (fSelectedColumn->Width() == minWidth)
|
if (fSelectedColumn->Width() == minWidth)
|
||||||
@@ -2335,6 +2338,8 @@ TitleView::ResizeSelectedColumn(BPoint position, bool preferred)
|
|||||||
SetViewCursor(fMaxResizeCursor, true);
|
SetViewCursor(fMaxResizeCursor, true);
|
||||||
else
|
else
|
||||||
SetViewCursor(fResizeCursor, true);
|
SetViewCursor(fResizeCursor, true);
|
||||||
|
|
||||||
|
ColumnResized(fSelectedColumn, oldWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2526,6 +2531,22 @@ TitleView::DrawTitle(BView* view, BRect rect, BColumn* column, bool depressed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float
|
||||||
|
TitleView::_VirtualWidth() const
|
||||||
|
{
|
||||||
|
float width = 0.0f;
|
||||||
|
|
||||||
|
int32 count = fColumns->CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
BColumn* column = reinterpret_cast<BColumn*>(fColumns->ItemAt(i));
|
||||||
|
width += column->Width();
|
||||||
|
}
|
||||||
|
|
||||||
|
return width + MAX(kLeftMargin,
|
||||||
|
fMasterView->LatchWidth()) + kRightMargin * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TitleView::Draw(BRect invalidRect)
|
TitleView::Draw(BRect invalidRect)
|
||||||
{
|
{
|
||||||
@@ -2588,8 +2609,7 @@ TitleView::ScrollTo(BPoint position)
|
|||||||
|
|
||||||
// Perform the little trick if the user is scrolled over too far.
|
// Perform the little trick if the user is scrolled over too far.
|
||||||
// See OutlineView::ScrollTo for a more in depth explanation
|
// See OutlineView::ScrollTo for a more in depth explanation
|
||||||
float maxScrollBarValue = fColumnsWidth + MAX(kLeftMargin,
|
float maxScrollBarValue = _VirtualWidth() - fVisibleRect.Width();
|
||||||
fMasterView->LatchWidth()) + kRightMargin * 2 - fVisibleRect.Width();
|
|
||||||
BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL);
|
BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL);
|
||||||
float min, max;
|
float min, max;
|
||||||
hScrollBar->GetRange(&min, &max);
|
hScrollBar->GetRange(&min, &max);
|
||||||
@@ -4761,6 +4781,13 @@ OutlineView::GetColumnPreferredWidth(BColumn* column)
|
|||||||
preferred = width;
|
preferred = width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Constrain to preferred width. This makes the method do a little
|
||||||
|
// more than asked, but it's for convenience.
|
||||||
|
if (preferred < column->MinWidth())
|
||||||
|
preferred = column->MinWidth();
|
||||||
|
else if (preferred > column->MaxWidth())
|
||||||
|
preferred = column->MaxWidth();
|
||||||
|
|
||||||
return preferred;
|
return preferred;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user