* Add previous/next block navigation buttons.

* Fix a calculation error with respect to the last line of the block.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42216 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent
2011-06-16 22:45:40 +00:00
parent 71b9d8cf3b
commit 21e484aea9
3 changed files with 82 additions and 23 deletions
@@ -9,7 +9,9 @@
#include <Alert.h>
#include <Application.h>
#include <Autolock.h>
#include <Button.h>
#include <ControlLook.h>
#include <LayoutBuilder.h>
#include <ScrollView.h>
#include <TextControl.h>
@@ -22,6 +24,12 @@
#include "UserInterface.h"
enum {
MSG_NAVIGATE_PREVIOUS_BLOCK = 'npbl',
MSG_NAVIGATE_NEXT_BLOCK = 'npnl'
};
InspectorWindow::InspectorWindow(::Team* team, UserInterfaceListener* listener)
:
BWindow(BRect(100, 100, 700, 500), "Inspector", B_TITLED_WINDOW,
@@ -99,9 +107,15 @@ InspectorWindow::_Init()
BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(4.0f, 4.0f, 4.0f, 4.0f)
.Add(fAddressInput = new BTextControl("addrInput",
.AddGroup(B_HORIZONTAL, 4.0f)
.Add(fAddressInput = new BTextControl("addrInput",
"Target Address:", "",
new BMessage(MSG_INSPECT_ADDRESS)))
.Add(fPreviousBlockButton = new BButton("navPrevious", "<",
new BMessage(MSG_NAVIGATE_PREVIOUS_BLOCK)))
.Add(fNextBlockButton = new BButton("navNext", ">",
new BMessage(MSG_NAVIGATE_NEXT_BLOCK)))
.End()
.AddGroup(B_HORIZONTAL, 4.0f)
.Add(fHexMode = new BMenuField("outputStyle", "Hex Mode:",
hexMenu))
@@ -119,6 +133,10 @@ InspectorWindow::_Init()
scrollView->SetTarget(fMemoryView = MemoryView::Create());
fAddressInput->SetTarget(this);
fPreviousBlockButton->SetTarget(this);
fNextBlockButton->SetTarget(this);
fPreviousBlockButton->SetEnabled(false);
fNextBlockButton->SetEnabled(false);
hexMenu->SetLabelFromMarked(true);
hexMenu->SetTargetForItems(fMemoryView);
@@ -138,27 +156,36 @@ InspectorWindow::MessageReceived(BMessage* msg)
switch (msg->what) {
case MSG_INSPECT_ADDRESS:
{
ExpressionParser parser;
parser.SetSupportHexInput(true);
target_addr_t address = 0;
const char* addressExpression = fAddressInput->Text();
BString errorMessage;
try {
address = parser.EvaluateToInt64(addressExpression);
} catch(ParseException parseError) {
errorMessage.SetToFormat("Failed to parse address: %s",
parseError.message.String());
} catch(...) {
errorMessage.SetToFormat(
"Unknown error while parsing address");
bool addressValid = false;
if (msg->FindUInt64("address", &address) != B_OK)
{
ExpressionParser parser;
parser.SetSupportHexInput(true);
const char* addressExpression = fAddressInput->Text();
BString errorMessage;
try {
address = parser.EvaluateToInt64(addressExpression);
} catch(ParseException parseError) {
errorMessage.SetToFormat("Failed to parse address: %s",
parseError.message.String());
} catch(...) {
errorMessage.SetToFormat(
"Unknown error while parsing address");
}
if (errorMessage.Length() > 0) {
BAlert* alert = new(std::nothrow) BAlert("Inspect Address",
errorMessage.String(), "Close");
if (alert != NULL)
alert->Go();
} else
addressValid = true;
} else {
addressValid = true;
}
if (errorMessage.Length() > 0) {
BAlert* alert = new(std::nothrow) BAlert("Inspect Address",
errorMessage.String(), "Close");
if (alert != NULL)
alert->Go();
} else {
if (addressValid) {
if (fCurrentBlock != NULL
&& !fCurrentBlock->Contains(address)) {
fCurrentBlock->ReleaseReference();
@@ -177,6 +204,31 @@ InspectorWindow::MessageReceived(BMessage* msg)
}
break;
}
case MSG_NAVIGATE_PREVIOUS_BLOCK:
case MSG_NAVIGATE_NEXT_BLOCK:
{
if (fCurrentBlock != NULL)
{
target_addr_t address = fCurrentBlock->BaseAddress();
if (msg->what == MSG_NAVIGATE_PREVIOUS_BLOCK)
address -= fCurrentBlock->Size();
else
address += fCurrentBlock->Size();
BMessage setMessage(MSG_INSPECT_ADDRESS);
setMessage.AddUInt64("address", address);
PostMessage(&setMessage);
}
break;
}
{
break;
}
default:
{
BWindow::MessageReceived(msg);
break;
}
}
}
@@ -192,6 +244,11 @@ InspectorWindow::QuitRequested()
void
InspectorWindow::MemoryBlockRetrieved(TeamMemoryBlock* block)
{
fCurrentBlock = block;
fMemoryView->SetTargetAddress(block, fCurrentAddress);
BAutolock lock(this);
if (lock.IsLocked()) {
fCurrentBlock = block;
fMemoryView->SetTargetAddress(block, fCurrentAddress);
fPreviousBlockButton->SetEnabled(true);
fNextBlockButton->SetEnabled(true);
}
}
@@ -45,6 +45,8 @@ private:
BMenuField* fHexMode;
BMenuField* fTextMode;
MemoryView* fMemoryView;
BButton* fPreviousBlockButton;
BButton* fNextBlockButton;
TeamMemoryBlock* fCurrentBlock;
target_addr_t fCurrentAddress;
::Team* fTeam;
@@ -163,11 +163,11 @@ MemoryView::Draw(BRect rect)
PopState();
if (fHexMode != HexModeNone) {
if (currentAddress + (currentBlocksPerLine * hexBlockSize)
if (currentAddress + (currentBlocksPerLine * blockByteSize)
> maxAddress) {
currentCharsPerLine = maxAddress - currentAddress;
currentBlocksPerLine = currentCharsPerLine
/ hexBlockSize;
/ blockByteSize;
}
for (int32 j = 0; j < currentBlocksPerLine; j++) {