* The previous change to reorder item->Update() and _RecalcItemTops() obviously

broke everything. If the added item has no chance to calculate it's height,
  _RecalcItemTops() won't work of course. Whatever this was supposed to fix,
  there has to be a correct way.
* Override BView::SetFont() to update all the items. I remember wanting to
  implement this, that's why I refactored a _FontChanged() method, but I
  obviousy never did...
* Moved the AttachedToWindow() and FrameMoved() implementations to a more
  logical position in the file.
* Implement B_PAGE_UP/DOWN key presses. Don't know if that's what the BeOS
  implementation did, will check later.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28671 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2008-11-16 22:34:11 +00:00
parent 231cbd908e
commit fa6cd8ad6a
2 changed files with 54 additions and 27 deletions

View File

@ -41,7 +41,11 @@ class BListView : public BView, public BInvoker {
virtual void MouseDown(BPoint where);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MakeFocus(bool state = true);
virtual void AttachedToWindow();
virtual void FrameResized(float newWidth, float newHeight);
virtual void FrameMoved(BPoint newPosition);
virtual void SetFont(const BFont* font,
uint32 mask = B_FONT_ALL);
virtual void TargetedByScrollView(BScrollView* scroller);
virtual void ScrollTo(BPoint where);
inline void ScrollTo(float x, float y);
@ -98,9 +102,6 @@ class BListView : public BView, public BInvoker {
bool MoveItem(int32 from, int32 to);
bool ReplaceItem(int32 index, BListItem* item);
virtual void AttachedToWindow();
virtual void FrameMoved(BPoint newPosition);
BRect ItemFrame(int32 index);
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,

View File

@ -427,6 +427,25 @@ BListView::KeyDown(const char *bytes, int32 numBytes)
ScrollToSelection();
break;
case B_PAGE_UP:
{
BPoint scrollOffset(LeftTop());
scrollOffset.y = max_c(0, scrollOffset.y - Bounds().Height());
ScrollTo(scrollOffset);
break;
}
case B_PAGE_DOWN:
{
BPoint scrollOffset(LeftTop());
if (BListItem* item = LastItem()) {
scrollOffset.y += Bounds().Height();
scrollOffset.y = min_c(item->Bottom() - Bounds().Height(),
scrollOffset.y);
}
ScrollTo(scrollOffset);
break;
}
case B_RETURN:
case B_SPACE:
Invoke();
@ -450,6 +469,19 @@ BListView::MakeFocus(bool focused)
fScrollView->SetBorderHighlighted(focused);
}
// AttachedToWindow
void
BListView::AttachedToWindow()
{
BView::AttachedToWindow();
_FontChanged();
if (!Messenger().IsValid())
SetTarget(Window(), NULL);
_FixupScrollBar();
}
// FrameResized
void
BListView::FrameResized(float width, float height)
@ -457,6 +489,21 @@ BListView::FrameResized(float width, float height)
_FixupScrollBar();
}
// FrameMoved
void
BListView::FrameMoved(BPoint new_position)
{
BView::FrameMoved(new_position);
}
// SetFont
void
BListView::SetFont(const BFont* font, uint32 mask)
{
BView::SetFont(font, mask);
_FontChanged();
}
// TargetedByScrollView
void
BListView::TargetedByScrollView(BScrollView *view)
@ -486,9 +533,9 @@ BListView::AddItem(BListItem *item, int32 index)
if (Window()) {
BFont font;
GetFont(&font);
_RecalcItemTops(index);
item->Update(this, &font);
_RecalcItemTops(index);
_FixupScrollBar();
_InvalidateFrom(index);
}
@ -508,9 +555,8 @@ BListView::AddItem(BListItem* item)
if (Window()) {
BFont font;
GetFont(&font);
_RecalcItemTops(CountItems() - 1);
item->Update(this, &font);
_RecalcItemTops(CountItems() - 1);
_FixupScrollBar();
InvalidateItem(CountItems() - 1);
@ -992,26 +1038,6 @@ BListView::ReplaceItem(int32 index, BListItem *item)
return DoMiscellaneous(B_REPLACE_OP, &data);
}
// AttachedToWindow
void
BListView::AttachedToWindow()
{
BView::AttachedToWindow();
_FontChanged();
if (!Messenger().IsValid())
SetTarget(Window(), NULL);
_FixupScrollBar();
}
// FrameMoved
void
BListView::FrameMoved(BPoint new_position)
{
BView::FrameMoved(new_position);
}
// ItemFrame
BRect
BListView::ItemFrame(int32 index)