1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2012-2015, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef VARIABLES_VIEW_H
7#define VARIABLES_VIEW_H
8
9
10#include <GroupView.h>
11#include <util/OpenHashTable.h>
12
13#include "table/TreeTable.h"
14
15#include "ExpressionInfo.h"
16
17
18class ActionMenuItem;
19class CpuState;
20class SettingsMenu;
21class StackFrame;
22class Thread;
23class Type;
24class TypeComponentPath;
25class ValueLocation;
26class ValueNode;
27class ValueNodeChild;
28class ValueNodeContainer;
29class ValueNodeManager;
30class Value;
31class Variable;
32class VariableEditWindow;
33class VariablesViewState;
34class VariablesViewStateHistory;
35
36
37class VariablesView : public BGroupView, private TreeTableListener,
38	private ExpressionInfo::Listener {
39public:
40	class Listener;
41
42public:
43								VariablesView(Listener* listener);
44								~VariablesView();
45
46	static	VariablesView*		Create(Listener* listener,
47									ValueNodeManager* manager);
48									// throws
49
50			void				SetStackFrame(Thread* thread,
51									StackFrame* stackFrame);
52
53	virtual	void				MessageReceived(BMessage* message);
54
55	virtual	void				DetachedFromWindow();
56
57			void				LoadSettings(const BMessage& settings);
58			status_t			SaveSettings(BMessage& settings);
59
60			void				SetStackFrameClearPending();
61
62private:
63	// TreeTableListener
64	virtual	void				TreeTableNodeExpandedChanged(TreeTable* table,
65									const TreeTablePath& path, bool expanded);
66	virtual	void				TreeTableNodeInvoked(TreeTable* table,
67									const TreeTablePath& path);
68	virtual	void				TreeTableCellMouseDown(TreeTable* table,
69									const TreeTablePath& path,
70									int32 columnIndex, BPoint screenWhere,
71									uint32 buttons);
72
73	// ExpressionInfo::Listener
74	virtual	void				ExpressionEvaluated(ExpressionInfo* info,
75									status_t result, ExpressionResult* value);
76
77private:
78			class ContainerListener;
79			class ExpressionVariableID;
80			class ModelNode;
81			class VariableValueColumn;
82			class VariableTableModel;
83			class ContextMenu;
84			class TableCellContextMenuTracker;
85			class VariablesExpressionInfo;
86			typedef BObjectList<ActionMenuItem> ContextActionList;
87			typedef BObjectList<ExpressionInfo> ExpressionInfoList;
88			typedef BObjectList<ValueNodeChild> ExpressionChildList;
89
90			struct FunctionKey;
91			struct ExpressionInfoEntry;
92			struct ExpressionInfoEntryHashDefinition;
93
94			typedef BOpenHashTable<ExpressionInfoEntryHashDefinition>
95				ExpressionInfoTable;
96
97private:
98			void				_Init(ValueNodeManager* manager);
99
100			void				_RequestNodeValue(ModelNode* node);
101			status_t			_GetContextActionsForNode(ModelNode* node,
102									ContextActionList*& _preActions,
103									ContextActionList*& _postActions);
104			status_t			_AddContextAction(const char* action,
105									uint32 what, ContextActionList* actions,
106									BMessage*& _message);
107			status_t			_CreateContextAction(const char* action,
108									uint32 what, ActionMenuItem*& _item);
109			status_t			_AddTypeHandlerMenuIfNeeded(ModelNode* node,
110									ContextActionList* actions);
111			void				_FinishContextMenu(bool force);
112			void				_SaveViewState(bool updateValues) const;
113			void				_RestoreViewState();
114			status_t			_AddViewStateDescendentNodeInfos(
115									VariablesViewState* viewState,
116									void* parent,
117									TreeTablePath& path,
118									bool updateValues) const;
119			status_t			_ApplyViewStateDescendentNodeInfos(
120									VariablesViewState* viewState,
121									void* parent,
122									TreeTablePath& path);
123			void				_CopyVariableValueToClipboard();
124
125			status_t			_AddExpression(const char* expression,
126									bool persistentExpression,
127									ExpressionInfo*& _info);
128			void				_RemoveExpression(ModelNode* node);
129
130			void				_RestoreExpressionNodes();
131
132			void				_AddExpressionNode(ExpressionInfo* info,
133									status_t result, ExpressionResult* value);
134
135			void				_HandleTypecastResult(status_t result,
136									ExpressionResult* value);
137
138			void				_HandleEditVariableRequest(ModelNode* node,
139									Value* value);
140
141			status_t			_GetTypeForTypeCode(int32 typeCode,
142									Type*& _resultType) const;
143
144private:
145			Thread*				fThread;
146			StackFrame*			fStackFrame;
147			TreeTable*			fVariableTable;
148			VariableTableModel*	fVariableTableModel;
149			ContainerListener*	fContainerListener;
150			VariablesViewState*	fPreviousViewState;
151			VariablesViewStateHistory* fViewStateHistory;
152			ExpressionInfoTable* fExpressions;
153			ExpressionChildList	fExpressionChildren;
154			TableCellContextMenuTracker* fTableCellContextMenuTracker;
155			VariablesExpressionInfo* fPendingTypecastInfo;
156			ExpressionInfo*		fTemporaryExpression;
157			bool				fFrameClearPending;
158			VariableEditWindow*	fEditWindow;
159			Listener*			fListener;
160};
161
162
163class VariablesView::Listener {
164public:
165	virtual						~Listener();
166
167	virtual	void				ValueNodeValueRequested(CpuState* cpuState,
168									ValueNodeContainer* container,
169									ValueNode* valueNode) = 0;
170
171	virtual	void				ExpressionEvaluationRequested(
172									ExpressionInfo* info,
173									StackFrame* frame,
174									Thread* thread) = 0;
175
176	virtual	void				ValueNodeWriteRequested(
177									ValueNode* node,
178									CpuState* state,
179									Value* newValue) = 0;
180
181};
182
183
184#endif	// VARIABLES_VIEW_H
185