From e805d89711f54937624a70f0fd8b0cf0790c1031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 18 Feb 2004 03:28:37 +0000 Subject: [PATCH] Added support for different number bases in the offset column. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6622 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskprobe/DataView.cpp | 26 ++++++++++++++++++++++++-- src/apps/diskprobe/DataView.h | 11 +++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/apps/diskprobe/DataView.cpp b/src/apps/diskprobe/DataView.cpp index 3f0c33e2a5..96c9100e00 100644 --- a/src/apps/diskprobe/DataView.cpp +++ b/src/apps/diskprobe/DataView.cpp @@ -7,7 +7,6 @@ #include "DataView.h" #include "DataEditor.h" -//#include #include #include @@ -25,6 +24,7 @@ DataView::DataView(BRect rect, DataEditor &editor) : BView(rect, "dataView", B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS), fEditor(editor), fFocus(kHexFocus), + fBase(kHexBase), fIsActive(true) { fPositionLength = 4; @@ -95,6 +95,16 @@ DataView::MessageReceived(BMessage *message) break; } + case kMsgBaseType: + { + int32 type; + if (message->FindInt32("base", &type) != B_OK) + break; + + SetBase((base_type)type); + break; + } + default: BView::MessageReceived(message); } @@ -104,7 +114,8 @@ DataView::MessageReceived(BMessage *message) void DataView::ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size) { - line += sprintf(line, "%0*Lx: ", (int)fPositionLength, offset); + line += sprintf(line, fBase == kHexBase ? "%0*Lx: " : "%0*Ld: ", + (int)fPositionLength, offset); for (uint32 i = 0; i < kBlockSize; i++) { if (i >= size) { @@ -453,6 +464,17 @@ DataView::InvalidateRange(int32 start, int32 end) } +void +DataView::SetBase(base_type type) +{ + if (fBase == type) + return; + + fBase = type; + Invalidate(); +} + + void DataView::SetFocus(view_focus which) { diff --git a/src/apps/diskprobe/DataView.h b/src/apps/diskprobe/DataView.h index 952b4c6494..171749b835 100644 --- a/src/apps/diskprobe/DataView.h +++ b/src/apps/diskprobe/DataView.h @@ -13,6 +13,13 @@ class DataEditor; +static const uint32 kMsgBaseType = 'base'; + +enum base_type { + kHexBase, + kDecimalBase +}; + enum view_focus { kNoFocus, kHexFocus, @@ -45,6 +52,9 @@ class DataView : public BView { void GetSelection(int32 &start, int32 &end); void InvalidateRange(int32 start, int32 end); + base_type Base() const { return fBase; } + void SetBase(base_type type); + private: BRect SelectionFrame(view_focus which, int32 start, int32 end); int32 PositionAt(view_focus focus, BPoint point, view_focus *_newFocus = NULL); @@ -66,6 +76,7 @@ class DataView : public BView { int32 fFontHeight; float fCharWidth; view_focus fFocus; + base_type fBase; bool fIsActive; int32 fStart, fEnd; int32 fMouseSelectionStart;