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:
parent
8b876a958c
commit
075968bf03
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user