Add listener interface to MemoryView.

- When the target address of the memory view changes, an attached
  listener is now notified. This lets the inspector window's text input
  keep in sync with the current address when keyboard navigating the
  memory view.
This commit is contained in:
Rene Gollent 2013-05-05 16:08:31 -04:00
parent 5af6169bb2
commit 1b10489347
4 changed files with 65 additions and 18 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011, Rene Gollent, rene@gollent.com. All rights reserved.
* Copyright 2011-2013, Rene Gollent, rene@gollent.com. All rights reserved.
* Distributed under the terms of the MIT License.
*/
@ -156,7 +156,7 @@ InspectorWindow::_Init()
int32 targetEndian = fTeam->GetArchitecture()->IsBigEndian()
? EndianModeBigEndian : EndianModeLittleEndian;
scrollView->SetTarget(fMemoryView = MemoryView::Create(fTeam));
scrollView->SetTarget(fMemoryView = MemoryView::Create(fTeam, this));
fAddressInput->SetTarget(this);
fPreviousBlockButton->SetTarget(this);
@ -221,6 +221,7 @@ InspectorWindow::MessageReceived(BMessage* msg)
}
if (addressValid) {
fCurrentAddress = address;
if (fCurrentBlock != NULL
&& !fCurrentBlock->Contains(address)) {
fCurrentBlock->ReleaseReference();
@ -231,11 +232,6 @@ InspectorWindow::MessageReceived(BMessage* msg)
fListener->InspectRequested(address, this);
else
fMemoryView->SetTargetAddress(fCurrentBlock, address);
fCurrentAddress = address;
BString computedAddress;
computedAddress.SetToFormat("0x%" B_PRIx64, address);
fAddressInput->SetText(computedAddress.String());
}
break;
}
@ -289,6 +285,19 @@ InspectorWindow::MemoryBlockRetrieved(TeamMemoryBlock* block)
}
void
InspectorWindow::TargetAddressChanged(target_addr_t address)
{
AutoLocker<BLooper> lock(this);
if (lock.IsLocked()) {
fCurrentAddress = address;
BString computedAddress;
computedAddress.SetToFormat("0x%" B_PRIx64, address);
fAddressInput->SetText(computedAddress.String());
}
}
status_t
InspectorWindow::LoadSettings(const GuiTeamUiSettings& settings)
{

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011, Rene Gollent, rene@gollent.com. All rights reserved.
* Copyright 2011-2013, Rene Gollent, rene@gollent.com. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef INSPECTOR_WINDOW_H
@ -8,6 +8,7 @@
#include <Window.h>
#include "MemoryView.h"
#include "TeamMemoryBlock.h"
#include "Types.h"
@ -17,13 +18,13 @@ class BMenuField;
class BMessenger;
class BTextControl;
class GuiTeamUiSettings;
class MemoryView;
class Team;
class UserInterfaceListener;
class InspectorWindow : public BWindow,
public TeamMemoryBlock::Listener {
public TeamMemoryBlock::Listener,
public MemoryView::Listener {
public:
InspectorWindow(::Team* team,
UserInterfaceListener* listener,
@ -38,8 +39,12 @@ public:
virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();
// TeamMemoryBlock::Listener
virtual void MemoryBlockRetrieved(TeamMemoryBlock* block);
// MemoryView::Listener
virtual void TargetAddressChanged(target_addr_t address);
status_t LoadSettings(
const GuiTeamUiSettings& settings);
status_t SaveSettings(

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011, Rene Gollent, rene@gollent.com. All rights reserved.
* Copyright 2011-2013, Rene Gollent, rene@gollent.com. All rights reserved.
* Distributed under the terms of the MIT License.
*/
@ -26,7 +26,7 @@ enum {
};
MemoryView::MemoryView(::Team* team)
MemoryView::MemoryView(::Team* team, Listener* listener)
:
BView("memoryView", B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE
| B_SUBPIXEL_PRECISE),
@ -38,7 +38,8 @@ MemoryView::MemoryView(::Team* team)
fTextCharsPerLine(0),
fHexBlocksPerLine(0),
fHexMode(HexMode8BitInt),
fTextMode(TextModeASCII)
fTextMode(TextModeASCII),
fListener(listener)
{
Architecture* architecture = team->GetArchitecture();
fTargetAddressSize = architecture->AddressSize() * 2;
@ -56,9 +57,9 @@ MemoryView::~MemoryView()
/*static */ MemoryView*
MemoryView::Create(::Team* team)
MemoryView::Create(::Team* team, Listener* listener)
{
MemoryView* self = new MemoryView(team);
MemoryView* self = new MemoryView(team, listener);
try {
self->_Init();
@ -85,6 +86,13 @@ MemoryView::SetTargetAddress(TeamMemoryBlock* block, target_addr_t address)
}
void
MemoryView::UnsetListener()
{
fListener = NULL;
}
void
MemoryView::AttachedToWindow()
{
@ -329,6 +337,8 @@ MemoryView::MessageReceived(BMessage* message)
_RecalcScrollBars();
ScrollToSelection();
Invalidate();
if (fListener != NULL)
fListener->TargetAddressChanged(fTargetAddress);
break;
}
case MSG_SET_HEX_MODE:
@ -546,3 +556,11 @@ MemoryView::_GetNextHexBlock(char* buffer, int32 bufferSize,
}
}
}
//#pragma mark - Listener
MemoryView::Listener::~Listener()
{
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2011, Rene Gollent, rene@gollent.com. All rights reserved.
* Copyright 2011-2013, Rene Gollent, rene@gollent.com. All rights reserved.
* Distributed under the terms of the MIT License.
*/
@ -46,15 +46,19 @@ class TeamMemoryBlock;
class MemoryView : public BView {
public:
MemoryView(::Team* team);
class Listener;
MemoryView(::Team* team, Listener* listener);
virtual ~MemoryView();
static MemoryView* Create(::Team* team);
static MemoryView* Create(::Team* team, Listener* listener);
// throws
void SetTargetAddress(TeamMemoryBlock* block,
target_addr_t address);
void UnsetListener();
virtual void AttachedToWindow();
virtual void Draw(BRect rect);
virtual void FrameResized(float width, float height);
@ -83,6 +87,17 @@ private:
int32 fCurrentEndianMode;
int32 fHexMode;
int32 fTextMode;
Listener* fListener;
};
class MemoryView::Listener {
public:
virtual ~Listener();
virtual void TargetAddressChanged(target_addr_t address)
= 0;
};
#endif // MEMORY_VIEW_H