From 1b104893478023f9d694271b701ca1e25c905322 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 5 May 2013 16:08:31 -0400 Subject: [PATCH] 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. --- .../gui/inspector_window/InspectorWindow.cpp | 23 ++++++++++----- .../gui/inspector_window/InspectorWindow.h | 11 ++++++-- .../gui/inspector_window/MemoryView.cpp | 28 +++++++++++++++---- .../gui/inspector_window/MemoryView.h | 21 ++++++++++++-- 4 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.cpp b/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.cpp index ed7ec9afd0..e3917f88fe 100644 --- a/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.cpp +++ b/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.cpp @@ -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 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) { diff --git a/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.h b/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.h index a145e1899c..320e344d9f 100644 --- a/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.h +++ b/src/apps/debugger/user_interface/gui/inspector_window/InspectorWindow.h @@ -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 +#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( diff --git a/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.cpp b/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.cpp index fe30580295..a59e96760e 100644 --- a/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.cpp +++ b/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.cpp @@ -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() +{ +} diff --git a/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.h b/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.h index 9f0dba6e4e..ca10a25c48 100644 --- a/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.h +++ b/src/apps/debugger/user_interface/gui/inspector_window/MemoryView.h @@ -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