-
-
Notifications
You must be signed in to change notification settings - Fork 335
/
MemoryView.h
142 lines (107 loc) · 3.14 KB
/
MemoryView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright 2011-2015, Rene Gollent, rene@gollent.com. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef MEMORY_VIEW_H
#define MEMORY_VIEW_H
#include <View.h>
#include "Types.h"
enum {
MSG_SET_HEX_MODE = 'sehe',
MSG_SET_ENDIAN_MODE = 'seme',
MSG_SET_TEXT_MODE = 'stme'
};
enum {
HexModeNone = 0,
HexMode8BitInt,
HexMode16BitInt,
HexMode32BitInt,
HexMode64BitInt
// TODO: floating point representation?
};
enum {
EndianModeLittleEndian = 0,
EndianModeBigEndian = 1
};
enum {
TextModeNone = 0,
TextModeASCII
};
class BMessageRunner;
class Team;
class TeamMemoryBlock;
class MemoryView : public BView {
public:
class Listener;
MemoryView(::Team* team, Listener* listener);
virtual ~MemoryView();
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);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MakeFocus(bool isFocused);
virtual void MessageReceived(BMessage* message);
virtual void MouseDown(BPoint point);
virtual void MouseMoved(BPoint point, uint32 transit,
const BMessage* dragMessage);
virtual void MouseUp(BPoint point);
void ScrollToSelection();
virtual void TargetedByScrollView(BScrollView* scrollView);
virtual BSize MinSize();
virtual BSize PreferredSize();
virtual BSize MaxSize();
private:
void _Init();
void _RecalcScrollBars();
void _GetNextHexBlock(char* buffer,
int32 bufferSize, const char* address);
int32 _GetOffsetAt(BPoint point) const;
BPoint _GetPointForOffset(int32 offset) const;
void _RecalcBounds();
float _GetAddressDisplayWidth() const;
inline int32 _GetHexDigitsPerBlock() const
{ return 1 << fHexMode; };
void _GetSelectionRegion(BRegion& region);
void _GetSelectedText(BString& text);
void _CopySelectionToClipboard();
void _HandleAutoScroll();
void _ScrollByLines(int32 lineCount);
void _HandleContextMenu(BPoint point);
private:
::Team* fTeam;
TeamMemoryBlock* fTargetBlock;
target_addr_t fTargetAddress;
float fCharWidth;
float fLineHeight;
int32 fTargetAddressSize;
int32 fTextCharsPerLine;
int32 fHexBlocksPerLine;
int32 fCurrentEndianMode;
int32 fHexMode;
int32 fTextMode;
float fHexLeft;
float fHexRight;
float fTextLeft;
float fTextRight;
int32 fSelectionBase;
int32 fSelectionStart;
int32 fSelectionEnd;
BMessageRunner* fScrollRunner;
bool fTrackingMouse;
Listener* fListener;
};
class MemoryView::Listener {
public:
virtual ~Listener();
virtual void TargetAddressChanged(target_addr_t address)
= 0;
virtual void HexModeChanged(int32 newMode) = 0;
virtual void TextModeChanged(int32 newMode) = 0;
virtual void EndianModeChanged(int32 newMode) = 0;
};
#endif // MEMORY_VIEW_H