xref: /haiku/src/apps/debugger/user_interface/gui/team_window/VariablesView.h (revision bf57c148f7787f0df15980976997c6dfb70ee067)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Copyright 2012-2014, 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 
18 class ActionMenuItem;
19 class CpuState;
20 class SettingsMenu;
21 class StackFrame;
22 class Thread;
23 class Type;
24 class TypeComponentPath;
25 class ValueNode;
26 class ValueNodeChild;
27 class ValueNodeContainer;
28 class Value;
29 class Variable;
30 class VariablesViewState;
31 class VariablesViewStateHistory;
32 
33 
34 class VariablesView : public BGroupView, private TreeTableListener,
35 	private ExpressionInfo::Listener {
36 public:
37 	class Listener;
38 
39 public:
40 								VariablesView(Listener* listener);
41 								~VariablesView();
42 
43 	static	VariablesView*		Create(Listener* listener);
44 									// throws
45 
46 			void				SetStackFrame(Thread* thread,
47 									StackFrame* stackFrame);
48 
49 	virtual	void				MessageReceived(BMessage* message);
50 
51 	virtual	void				DetachedFromWindow();
52 
53 			void				LoadSettings(const BMessage& settings);
54 			status_t			SaveSettings(BMessage& settings);
55 
56 			void				SetStackFrameClearPending();
57 
58 private:
59 	// TreeTableListener
60 	virtual	void				TreeTableNodeExpandedChanged(TreeTable* table,
61 									const TreeTablePath& path, bool expanded);
62 
63 	virtual	void				TreeTableCellMouseDown(TreeTable* table,
64 									const TreeTablePath& path,
65 									int32 columnIndex, BPoint screenWhere,
66 									uint32 buttons);
67 
68 	// ExpressionInfo::Listener
69 	virtual	void				ExpressionEvaluated(ExpressionInfo* info,
70 									status_t result, ExpressionResult* value);
71 
72 private:
73 			class ContainerListener;
74 			class ExpressionVariableID;
75 			class ModelNode;
76 			class VariableValueColumn;
77 			class VariableTableModel;
78 			class ContextMenu;
79 			class TableCellContextMenuTracker;
80 			typedef BObjectList<ActionMenuItem> ContextActionList;
81 			typedef BObjectList<ExpressionInfo> ExpressionInfoList;
82 			typedef BObjectList<ValueNodeChild> ExpressionChildList;
83 
84 			struct FunctionKey;
85 			struct ExpressionInfoEntry;
86 			struct ExpressionInfoEntryHashDefinition;
87 
88 			typedef BOpenHashTable<ExpressionInfoEntryHashDefinition>
89 				ExpressionInfoTable;
90 
91 private:
92 			void				_Init();
93 
94 			void				_RequestNodeValue(ModelNode* node);
95 			status_t			_GetContextActionsForNode(ModelNode* node,
96 									ContextActionList*& _preActions,
97 									ContextActionList*& _postActions);
98 			status_t			_AddContextAction(const char* action,
99 									uint32 what, ContextActionList* actions,
100 									BMessage*& _message);
101 			void				_FinishContextMenu(bool force);
102 			void				_SaveViewState(bool updateValues) const;
103 			void				_RestoreViewState();
104 			status_t			_AddViewStateDescendentNodeInfos(
105 									VariablesViewState* viewState,
106 									void* parent,
107 									TreeTablePath& path,
108 									bool updateValues) const;
109 			status_t			_ApplyViewStateDescendentNodeInfos(
110 									VariablesViewState* viewState,
111 									void* parent,
112 									TreeTablePath& path);
113 			void				_CopyVariableValueToClipboard();
114 
115 			status_t			_AddExpression(const char* expression,
116 									ExpressionInfo*& _info);
117 			void				_RemoveExpression(ModelNode* node);
118 
119 			void				_RestoreExpressionNodes();
120 
121 			void				_AddExpressionNode(ExpressionInfo* info,
122 									status_t result, ExpressionResult* value);
123 
124 			status_t			_GetTypeForTypeCode(int32 typeCode,
125 									Type*& _resultType) const;
126 
127 private:
128 			Thread*				fThread;
129 			StackFrame*			fStackFrame;
130 			TreeTable*			fVariableTable;
131 			VariableTableModel*	fVariableTableModel;
132 			ContainerListener*	fContainerListener;
133 			VariablesViewState*	fPreviousViewState;
134 			VariablesViewStateHistory* fViewStateHistory;
135 			ExpressionInfoTable* fExpressions;
136 			ExpressionChildList	fExpressionChildren;
137 			TableCellContextMenuTracker* fTableCellContextMenuTracker;
138 			bool				fFrameClearPending;
139 			Listener*			fListener;
140 };
141 
142 
143 class VariablesView::Listener {
144 public:
145 	virtual						~Listener();
146 
147 	virtual	void				ValueNodeValueRequested(CpuState* cpuState,
148 									ValueNodeContainer* container,
149 									ValueNode* valueNode) = 0;
150 
151 	virtual	void				ExpressionEvaluationRequested(
152 									ExpressionInfo* info,
153 									StackFrame* frame,
154 									Thread* thread) = 0;
155 };
156 
157 
158 #endif	// VARIABLES_VIEW_H
159