From 075968bf034c4246edc7d9203d1ddb9ad5c1f591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 18 Feb 2004 15:02:31 +0000 Subject: [PATCH] Now has one central DataBounds() method that's used by GetPreferredSize() and others. MouseMoved() no longer passes an invalid position to SetSelection() (avoiding the selection to be changed unexpectedly). It will now also make sure that the position hovered by the mouse is visible. PositionAt() no longer skips points that are not inside the valid bounds (even the wrong bounds), but clips the point to be inside of it. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6636 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskprobe/DataView.cpp | 48 +++++++++++++++++++++++---------- src/apps/diskprobe/DataView.h | 1 + 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/apps/diskprobe/DataView.cpp b/src/apps/diskprobe/DataView.cpp index 8a34e859b9..99f022a8ad 100644 --- a/src/apps/diskprobe/DataView.cpp +++ b/src/apps/diskprobe/DataView.cpp @@ -167,11 +167,30 @@ DataView::Draw(BRect updateRect) } +BRect +DataView::DataBounds() const +{ + return BRect(0, 0, + fCharWidth * (kBlockSize * 4 + fPositionLength + 6) + 2 * kHorizontalSpace, + fFontHeight * ((fDataSize + kBlockSize - 1) / kBlockSize) + 2 * kVerticalSpace); +} + + int32 DataView::PositionAt(view_focus focus, BPoint point, view_focus *_newFocus) { - if (!Bounds().Contains(point)) - return -1; + // clip the point into our data bounds + + BRect bounds = DataBounds(); + if (point.x < bounds.left) + point.x = bounds.left; + else if (point.x > bounds.right) + point.x = bounds.right; + + if (point.y < bounds.top) + point.y = bounds.top; + else if (point.y >= bounds.bottom - kVerticalSpace) + point.y = bounds.bottom - kVerticalSpace - 1; float left = fCharWidth * (fPositionLength + kBlockSpace) + kHorizontalSpace; float hexWidth = fCharWidth * kBlockSize * kHexByteWidth; @@ -662,7 +681,12 @@ DataView::MouseMoved(BPoint where, uint32 transit, const BMessage */*dragMessage if (fMouseSelectionStart == -1) return; - SetSelection(fMouseSelectionStart, PositionAt(fFocus, where)); + int32 end = PositionAt(fFocus, where); + if (end == -1) + return; + + SetSelection(fMouseSelectionStart, end); + MakeVisible(end); } @@ -740,7 +764,7 @@ DataView::KeyDown(const char *bytes, int32 numBytes) BRect frame = SelectionFrame(fFocus, fStart, fStart); frame.OffsetBy(0, Bounds().Height()); - float lastLine = fFontHeight * ((fDataSize - 1) / kBlockSize) + kVerticalSpace; + float lastLine = DataBounds().Height() - 1 - kVerticalSpace; if (frame.top > lastLine) frame.top = lastLine; ScrollBy(0, Bounds().Height()); @@ -795,16 +819,12 @@ DataView::SetFontSize(float point) void DataView::GetPreferredSize(float *_width, float *_height) { - if (_width) { - BFont font; - GetFont(&font); - *_width = fCharWidth * (kBlockSize * 4 + fPositionLength + 6) - + 2 * kHorizontalSpace; - } + BRect bounds = DataBounds(); - if (_height) { - *_height = fFontHeight * ((fDataSize + kBlockSize - 1) / kBlockSize) - + 2 * kVerticalSpace; - } + if (_width) + *_width = bounds.Width(); + + if (_height) + *_height = bounds.Height(); } diff --git a/src/apps/diskprobe/DataView.h b/src/apps/diskprobe/DataView.h index d23ac0358f..3045399889 100644 --- a/src/apps/diskprobe/DataView.h +++ b/src/apps/diskprobe/DataView.h @@ -61,6 +61,7 @@ class DataView : public BView { void SetBase(base_type type); private: + BRect DataBounds() const; BRect SelectionFrame(view_focus which, int32 start, int32 end); int32 PositionAt(view_focus focus, BPoint point, view_focus *_newFocus = NULL);