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
This commit is contained in:
Axel Dörfler
2004-02-18 15:02:31 +00:00
parent 8b876a958c
commit 075968bf03
2 changed files with 35 additions and 14 deletions
+34 -14
View File
@@ -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 int32
DataView::PositionAt(view_focus focus, BPoint point, view_focus *_newFocus) DataView::PositionAt(view_focus focus, BPoint point, view_focus *_newFocus)
{ {
if (!Bounds().Contains(point)) // clip the point into our data bounds
return -1;
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 left = fCharWidth * (fPositionLength + kBlockSpace) + kHorizontalSpace;
float hexWidth = fCharWidth * kBlockSize * kHexByteWidth; float hexWidth = fCharWidth * kBlockSize * kHexByteWidth;
@@ -662,7 +681,12 @@ DataView::MouseMoved(BPoint where, uint32 transit, const BMessage */*dragMessage
if (fMouseSelectionStart == -1) if (fMouseSelectionStart == -1)
return; 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); BRect frame = SelectionFrame(fFocus, fStart, fStart);
frame.OffsetBy(0, Bounds().Height()); frame.OffsetBy(0, Bounds().Height());
float lastLine = fFontHeight * ((fDataSize - 1) / kBlockSize) + kVerticalSpace; float lastLine = DataBounds().Height() - 1 - kVerticalSpace;
if (frame.top > lastLine) if (frame.top > lastLine)
frame.top = lastLine; frame.top = lastLine;
ScrollBy(0, Bounds().Height()); ScrollBy(0, Bounds().Height());
@@ -795,16 +819,12 @@ DataView::SetFontSize(float point)
void void
DataView::GetPreferredSize(float *_width, float *_height) DataView::GetPreferredSize(float *_width, float *_height)
{ {
if (_width) { BRect bounds = DataBounds();
BFont font;
GetFont(&font);
*_width = fCharWidth * (kBlockSize * 4 + fPositionLength + 6)
+ 2 * kHorizontalSpace;
}
if (_height) { if (_width)
*_height = fFontHeight * ((fDataSize + kBlockSize - 1) / kBlockSize) *_width = bounds.Width();
+ 2 * kVerticalSpace;
} if (_height)
*_height = bounds.Height();
} }
+1
View File
@@ -61,6 +61,7 @@ class DataView : public BView {
void SetBase(base_type type); void SetBase(base_type type);
private: private:
BRect DataBounds() const;
BRect SelectionFrame(view_focus which, int32 start, int32 end); BRect SelectionFrame(view_focus which, int32 start, int32 end);
int32 PositionAt(view_focus focus, BPoint point, view_focus *_newFocus = NULL); int32 PositionAt(view_focus focus, BPoint point, view_focus *_newFocus = NULL);