Started to implement the DataView class that will be the view to the editor.

For your entertaining it already shows the first block of the file/device.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6567 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-02-12 03:07:15 +00:00
parent f748e2d460
commit 990e75bacf
3 changed files with 185 additions and 0 deletions
+145
View File
@@ -0,0 +1,145 @@
/*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include "DataView.h"
#include "DataEditor.h"
#include <Messenger.h>
static const uint32 kBlockSize = 16;
DataView::DataView(BRect rect, DataEditor &editor)
: BView(rect, "dataView", B_FOLLOW_NONE, B_WILL_DRAW),
fEditor(editor)
{
fPositionLength = 4;
fDataSize = fEditor.ViewSize();
fData = (uint8 *)malloc(fDataSize);
fFontHeight = 15;
UpdateFromEditor();
SetFont(be_fixed_font);
}
DataView::~DataView()
{
}
void
DataView::DetachedFromWindow()
{
fEditor.StopWatching(this);
}
void
DataView::AttachedToWindow()
{
fEditor.StartWatching(this);
}
void
DataView::UpdateFromEditor(BMessage */*message*/)
{
if (fData == NULL)
return;
if (fEditor.Lock()) {
fOffset = fEditor.ViewOffset();
const uint8 *data;
if (fEditor.GetViewBuffer(&data) == B_OK)
memcpy(fData, data, fDataSize);
fEditor.Unlock();
}
}
void
DataView::MessageReceived(BMessage *message)
{
switch (message->what) {
case B_OBSERVER_NOTICE_CHANGE: {
int32 what;
if (message->FindInt32(B_OBSERVE_WHAT_CHANGE, &what) != B_OK)
break;
switch (what) {
case kMsgDataEditorUpdate:
UpdateFromEditor(message);
break;
}
break;
}
default:
BView::MessageReceived(message);
}
}
void
DataView::ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size)
{
line += sprintf(line, "%0*Lx: ", (int)fPositionLength, offset);
for (uint32 i = 0; i < kBlockSize; i++) {
if (!(i % 4))
*line++ = ' ';
if (i >= size) {
strcpy(line, " ");
line += 2;
} else
line += sprintf(line, "%02x", *(unsigned char *)(buffer + i));
}
strcpy(line, " ");
line += 3;
for (uint32 i = 0; i < kBlockSize; i++) {
if (i < size) {
char c = buffer[i];
if (c < 30)
*line++ = '.';
else
*line++ = c;
} else
break;
}
*line = '\0';
}
void
DataView::Draw(BRect updateRect)
{
if (fData == NULL)
return;
// ToDo: take "updateRect" into account!
char line[255];
BPoint location(8, fFontHeight);
for (uint32 i = 0; i < fDataSize; i += kBlockSize) {
ConvertLine(line, fOffset + i, fData + i, fDataSize - i);
DrawString(line, location);
location.y += fFontHeight;
}
// ToDo: clear unused space!
}
+39
View File
@@ -0,0 +1,39 @@
/*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#ifndef DATA_VIEW_H
#define DATA_VIEW_H
#include <View.h>
#include <String.h>
#include <Path.h>
class DataEditor;
class DataView : public BView {
public:
DataView(BRect rect, DataEditor &editor);
virtual ~DataView();
virtual void DetachedFromWindow();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
virtual void Draw(BRect updateRect);
private:
void UpdateFromEditor(BMessage *message = NULL);
void ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size);
DataEditor &fEditor;
int32 fPositionLength;
uint8 *fData;
uint32 fDataSize;
off_t fOffset;
float fFontHeight;
};
#endif /* DATA_VIEW_H */
+1
View File
@@ -7,6 +7,7 @@ AddResources DiskProbe : DiskProbe.rdef ;
App DiskProbe : App DiskProbe :
DiskProbe.cpp DiskProbe.cpp
DataEditor.cpp DataEditor.cpp
DataView.cpp
ProbeWindow.cpp ProbeWindow.cpp
ProbeView.cpp ProbeView.cpp
OpenWindow.cpp OpenWindow.cpp