Ignored the file size - it would have shown imaginary contents of a file
in its last block. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6710 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
84a09d60e1
commit
9ee2211f9a
@ -58,7 +58,11 @@ DataView::DataView(BRect rect, DataEditor &editor)
|
|||||||
fStart = fEnd = 0;
|
fStart = fEnd = 0;
|
||||||
fMouseSelectionStart = -1;
|
fMouseSelectionStart = -1;
|
||||||
|
|
||||||
|
if (fEditor.Lock()) {
|
||||||
fDataSize = fEditor.ViewSize();
|
fDataSize = fEditor.ViewSize();
|
||||||
|
fEditor.Unlock();
|
||||||
|
} else
|
||||||
|
fDataSize = 512;
|
||||||
fData = (uint8 *)malloc(fDataSize);
|
fData = (uint8 *)malloc(fDataSize);
|
||||||
|
|
||||||
SetFontSize(12.0);
|
SetFontSize(12.0);
|
||||||
@ -95,6 +99,12 @@ DataView::UpdateFromEditor(BMessage */*message*/)
|
|||||||
|
|
||||||
if (fEditor.Lock()) {
|
if (fEditor.Lock()) {
|
||||||
fOffset = fEditor.ViewOffset();
|
fOffset = fEditor.ViewOffset();
|
||||||
|
fFileSize = fEditor.FileSize();
|
||||||
|
|
||||||
|
if (fOffset + fDataSize > fFileSize)
|
||||||
|
fSizeInView = fFileSize - fOffset;
|
||||||
|
else
|
||||||
|
fSizeInView = fDataSize;
|
||||||
|
|
||||||
const uint8 *data;
|
const uint8 *data;
|
||||||
if (fEditor.GetViewBuffer(&data) == B_OK)
|
if (fEditor.GetViewBuffer(&data) == B_OK)
|
||||||
@ -166,13 +176,18 @@ DataView::MessageReceived(BMessage *message)
|
|||||||
void
|
void
|
||||||
DataView::ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size)
|
DataView::ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size)
|
||||||
{
|
{
|
||||||
|
if (size == 0) {
|
||||||
|
line[0] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
line += sprintf(line, fBase == kHexBase ? "%0*Lx: " : "%0*Ld: ",
|
line += sprintf(line, fBase == kHexBase ? "%0*Lx: " : "%0*Ld: ",
|
||||||
(int)fPositionLength, offset);
|
(int)fPositionLength, offset);
|
||||||
|
|
||||||
for (uint32 i = 0; i < kBlockSize; i++) {
|
for (uint32 i = 0; i < kBlockSize; i++) {
|
||||||
if (i >= size) {
|
if (i >= size) {
|
||||||
strcpy(line, " ");
|
strcpy(line, " ");
|
||||||
line += 2;
|
line += kHexByteWidth;
|
||||||
} else
|
} else
|
||||||
line += sprintf(line, "%02x ", *(unsigned char *)(buffer + i));
|
line += sprintf(line, "%02x ", *(unsigned char *)(buffer + i));
|
||||||
}
|
}
|
||||||
@ -207,8 +222,8 @@ DataView::Draw(BRect updateRect)
|
|||||||
char line[255];
|
char line[255];
|
||||||
BPoint location(kHorizontalSpace, kVerticalSpace + fAscent);
|
BPoint location(kHorizontalSpace, kVerticalSpace + fAscent);
|
||||||
|
|
||||||
for (uint32 i = 0; i < fDataSize; i += kBlockSize) {
|
for (uint32 i = 0; i < fSizeInView; i += kBlockSize) {
|
||||||
ConvertLine(line, /*fOffset + */i, fData + i, fDataSize - i);
|
ConvertLine(line, /*fOffset + */i, fData + i, fSizeInView - i);
|
||||||
DrawString(line, location);
|
DrawString(line, location);
|
||||||
|
|
||||||
location.y += fFontHeight;
|
location.y += fFontHeight;
|
||||||
@ -220,11 +235,12 @@ DataView::Draw(BRect updateRect)
|
|||||||
|
|
||||||
|
|
||||||
BRect
|
BRect
|
||||||
DataView::DataBounds() const
|
DataView::DataBounds(bool inView) const
|
||||||
{
|
{
|
||||||
return BRect(0, 0,
|
return BRect(0, 0,
|
||||||
fCharWidth * (kBlockSize * 4 + fPositionLength + 6) + 2 * kHorizontalSpace,
|
fCharWidth * (kBlockSize * 4 + fPositionLength + 6) + 2 * kHorizontalSpace,
|
||||||
fFontHeight * ((fDataSize + kBlockSize - 1) / kBlockSize) + 2 * kVerticalSpace);
|
fFontHeight * (((inView ? fSizeInView : fDataSize) + kBlockSize - 1) / kBlockSize)
|
||||||
|
+ 2 * kVerticalSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -233,7 +249,7 @@ DataView::PositionAt(view_focus focus, BPoint point, view_focus *_newFocus)
|
|||||||
{
|
{
|
||||||
// clip the point into our data bounds
|
// clip the point into our data bounds
|
||||||
|
|
||||||
BRect bounds = DataBounds();
|
BRect bounds = DataBounds(true);
|
||||||
if (point.x < bounds.left)
|
if (point.x < bounds.left)
|
||||||
point.x = bounds.left;
|
point.x = bounds.left;
|
||||||
else if (point.x > bounds.right)
|
else if (point.x > bounds.right)
|
||||||
@ -481,11 +497,11 @@ DataView::SetSelection(int32 start, int32 end, view_focus focus)
|
|||||||
|
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
start = 0;
|
start = 0;
|
||||||
else if (start > (int32)fDataSize - 1)
|
else if (start > (int32)fSizeInView - 1)
|
||||||
start = (int32)fDataSize - 1;
|
start = (int32)fSizeInView - 1;
|
||||||
|
|
||||||
if (end > (int32)fDataSize - 1)
|
if (end > (int32)fSizeInView - 1)
|
||||||
end = (int32)fDataSize - 1;
|
end = (int32)fSizeInView - 1;
|
||||||
else if (end < 0)
|
else if (end < 0)
|
||||||
end = 0;
|
end = 0;
|
||||||
|
|
||||||
@ -788,9 +804,9 @@ DataView::KeyDown(const char *bytes, int32 numBytes)
|
|||||||
case B_DOWN_ARROW:
|
case B_DOWN_ARROW:
|
||||||
{
|
{
|
||||||
int32 end = fEnd + int32(kBlockSize);
|
int32 end = fEnd + int32(kBlockSize);
|
||||||
if (end >= int32(fDataSize)) {
|
if (end >= int32(fSizeInView)) {
|
||||||
if (modifiers & B_SHIFT_KEY)
|
if (modifiers & B_SHIFT_KEY)
|
||||||
end = int32(fDataSize) - 1;
|
end = int32(fSizeInView) - 1;
|
||||||
else
|
else
|
||||||
end = fEnd;
|
end = fEnd;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ class DataView : public BView {
|
|||||||
void SetBase(base_type type);
|
void SetBase(base_type type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BRect DataBounds() const;
|
BRect DataBounds(bool inView = false) 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);
|
||||||
|
|
||||||
@ -75,6 +75,8 @@ class DataView : public BView {
|
|||||||
int32 fPositionLength;
|
int32 fPositionLength;
|
||||||
uint8 *fData;
|
uint8 *fData;
|
||||||
size_t fDataSize;
|
size_t fDataSize;
|
||||||
|
off_t fFileSize;
|
||||||
|
size_t fSizeInView;
|
||||||
off_t fOffset;
|
off_t fOffset;
|
||||||
float fAscent;
|
float fAscent;
|
||||||
int32 fFontHeight;
|
int32 fFontHeight;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user