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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
// bpt.cpp : implementation file
//
#include "stdafx.h"
#include "bpt.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBpt
IMPLEMENT_DYNCREATE(CBpt, CView)
/* There is only one of these, perhaps it should belong
to the app ? */
CBreakInfoList the_breakinfo_list;
extern CGuiApp theApp;
void redraw_allbptwins()
{
redraw_allwins(theApp.m_bptTemplate);
}
CFontInfo bptfontinfo ("BptFont", redraw_allbptwins);
CFontInfo buttonfontinfo ("ButtonFont", redraw_allbptwins);
CBpt::CBpt()
{
inchanged = 0;
}
CBpt::~CBpt()
{
}
BEGIN_MESSAGE_MAP(CBpt, CView)
//{{AFX_MSG_MAP(CBpt)
ON_WM_ERASEBKGND()
ON_WM_SIZE()
ON_WM_CREATE()
ON_COMMAND(ID_REAL_CMD_BUTTON_SET_BREAKPOINT, OnSetBreak)
ON_UPDATE_COMMAND_UI(ID_REAL_CMD_BUTTON_SET_BREAKPOINT, OnUpdateSetBreak)
ON_BN_CLICKED(ID_CMD_BUTTON_CLEAR_ALL, OnClearAll)
ON_LBN_SELCHANGE(ID_CMD_BUTTON_BREAKPOINT_LIST, on_list_changed)
ON_LBN_DBLCLK(ID_CMD_BUTTON_BREAKPOINT_LIST, OnDblclkBreakpointList)
ON_BN_CLICKED(ID_CMD_BUTTON_CLEAR_BREAKPOINT, OnClearBreakpoint)
ON_EN_CHANGE(ID_CMD_BUTTON_BREAKPOINT, on_edit_changed)
ON_BN_CLICKED(ID_CMD_BUTTON_DISABLE, OnDisable)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBpt drawing
void CBpt::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
list.SetFont(&bptfontinfo.m_font, TRUE);
edit.SetFont(&bptfontinfo.m_font, TRUE);
for (int i= 0; i < 4; i++)
buttons[i].SetFont(&buttonfontinfo.m_font, TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// CBpt message handlers
BOOL CBpt::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
BOOL CBpt::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
return CView::DestroyWindow();
}
BOOL CBpt::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CBrush b (RGB(192,192,192));
CBrush *old = pDC->SelectObject(&b);
CRect rect;
pDC->GetClipBox(&rect);
pDC->PatBlt(rect.left, rect.top,rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(old);
return TRUE;
}
#define R(x) x.left, x.top, x.Width(), x.Height()
void CBpt::OnSize(UINT nType, int cx, int cy)
{
CRect wholebox;
CRect shrunkbox;
int dx = bptfontinfo.dunits.cx;
int dy = bptfontinfo.dunits.cy;
int bx = buttonfontinfo.dunits.cx;
int by = buttonfontinfo.dunits.cy;
int hgap = dy ;
int indent = dx;
GetClientRect(wholebox);
shrunkbox = wholebox;
shrunkbox.InflateRect(-indent, -hgap);
CRect editbox = shrunkbox;
editbox.bottom = editbox.top + dy *2;
edit.SetWindowPos (NULL, R(editbox), 0);
CRect listbox = shrunkbox;
int bwidth = bx * 14;
listbox.top = editbox.bottom + hgap;
listbox.right = shrunkbox.right - bwidth;
listbox.bottom = shrunkbox.bottom;
list.SetWindowPos (NULL, R(listbox), 0);
/* Set, clear, disable, clearall on the bottom row */
CRect boxx = listbox;
boxx.left = shrunkbox.right - bwidth +hgap;
boxx.right = shrunkbox.right;
int boxheight = by * 2;
int boxgap = by * 3;
for (int i = 0; i < 4; i++)
{
boxx.top = listbox.top + i * boxgap;
boxx.bottom = boxx.top + boxheight;
buttons[i].SetWindowPos(0,R(boxx),0);
}
}
int CBpt::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CRect rc (10,10,100,100);
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
int i;
buttons[0].Create("&Set",WS_TABSTOP| BS_DEFPUSHBUTTON|WS_CHILD|WS_VISIBLE, rc, this, ID_REAL_CMD_BUTTON_SET_BREAKPOINT);
buttons[1].Create("&Clear",WS_TABSTOP|WS_CHILD|WS_VISIBLE, rc, this, ID_CMD_BUTTON_CLEAR_BREAKPOINT);
buttons[2].Create("&Disable",WS_TABSTOP|WS_CHILD|WS_VISIBLE, rc, this, ID_CMD_BUTTON_DISABLE);
buttons[3].Create("Clear &All",WS_TABSTOP|WS_CHILD|WS_VISIBLE , rc, this, ID_CMD_BUTTON_CLEAR_ALL);
list.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL
|WS_BORDER
| LBS_DISABLENOSCROLL | LBS_USETABSTOPS | WS_TABSTOP
| LBS_NOTIFY,
rc,
this,
ID_CMD_BUTTON_BREAKPOINT_LIST);
edit.Create(WS_TABSTOP|WS_CHILD|WS_VISIBLE|WS_BORDER, rc, this, ID_CMD_BUTTON_BREAKPOINT);
return 0;
}
void CBpt::OnSetBreak()
{
CString c;
edit.GetWindowText(c);
togdb_bpt_set ((const char *)c);
edit.SetWindowText("");
update_list();
update_buttons();
}
void CBpt::OnUpdateSetBreak(CCmdUI* pCmdUI)
{
pCmdUI->Enable(togdb_target_has_execution());
}
void CBpt::Initialize()
{
bptfontinfo.Initialize();
buttonfontinfo.Initialize();
}
void CBpt::Terminate()
{
bptfontinfo.Terminate();
buttonfontinfo.Terminate();
}
void CBpt::update_list()
{
char buf[200];
int cursel = list.GetCurSel();
static int tstops[] = {10,20,30,40};
list.ResetContent();
list.SetTabStops (4,tstops);
int i;
int size = the_breakinfo_list.GetSize();
for (i = 0; i < size; i++) {
char buf[200];
CBreakInfo *bi = the_breakinfo_list.GetAt(i);
if (bi->GetAddress()) {
sprintf(buf,"%s\t%d\t%s\t%s",
bi->GetEnable() ? "+" : "-",
i,
paddr(bi->GetAddress()),
bi->GetAddrString());
list.AddString(buf);
}
}
list.SetCurSel(cursel);
if (cursel >= 0 && cursel < list.GetCount())
{
CBreakInfo *bi = the_breakinfo_list.GetAt(cursel);
sprintf(buf,"%s:%d",
the_breakinfo_list.GetAt(cursel)->GetSourceFile(),
the_breakinfo_list.GetAt(cursel)->GetLineNumber());
edit.SetWindowText(buf);
}
}
void CBpt::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
update_list();
update_buttons();
}
void CBpt::update_buttons()
{
/* Set the set button correctly */
CString c;
int cursel = list.GetCurSel();
edit.GetWindowText(c);
const char *s = (const char *)c;
buttons[B_SETBUTTON].EnableWindow (strlen(s));
buttons[B_DISABLE].EnableWindow(cursel >= 0);
buttons[B_CLEAR].EnableWindow(cursel >= 0);
buttons[B_CLEARALL].EnableWindow(the_breakinfo_list.GetSize() > 0);
if (cursel >= 0) {
CBreakInfo *bi = the_breakinfo_list.GetAt(cursel);
if (bi->GetEnable())
buttons[B_DISABLE].SetWindowText("&Disable");
else
buttons[B_DISABLE].SetWindowText("&Enable");
}
}
void CBpt::on_edit_changed()
{
update_buttons();
}
void CBpt::on_list_changed()
{
update_list();
update_buttons();
}
void CBpt::OnDblclkBreakpointList()
{
int cursel = list.GetCurSel();
if (cursel >= 0) {
CBreakInfo *bi = the_breakinfo_list.GetAt(cursel);
/* goto where this line is */
theApp_show_at (bi->GetAddress());
}
}
void CBpt::OnClearAll()
{
the_breakinfo_list.DeleteAll();
update_list();
update_buttons();
}
void CBpt::OnClearBreakpoint()
{
int cursel = list.GetCurSel();
if (cursel >= 0) {
the_breakinfo_list.Delete(cursel);
if (cursel < list.GetCount()) {
list.SetCurSel(cursel);
}
}
update_list();
update_buttons();
}
void CBpt::OnDisable()
{
int cursel =list.GetCurSel();
if (cursel >= 0)
{
CBreakInfo *bi = the_breakinfo_list.GetAt(cursel);
if (bi->GetEnable())
the_breakinfo_list.Disable(cursel);
else
the_breakinfo_list.Enable(cursel);
}
update_list();
update_buttons();
}
void CBpt::OnInitialUpdate()
{
GetParentFrame()->SetWindowPos(0,0,0,
bptfontinfo.dunits.cx * 45,
bptfontinfo.dunits.cy * 30,
SWP_NOMOVE);
CView::OnInitialUpdate();
}
|