Skip to content

Commit c25a4b8

Browse files
authored
debugger cleanup: use enums for m_views indices (#13687)
For the wininfos that participate as individual panes in the main console window, their viewinfos are referenced via the m_views[] array with hard-coded indices of 0, 1, and 2. - Define & use enums for those indices (VIEW_IDX_DISASM, VIEW_IDX_STATE, VIEW_IDX_CONSOLE) - Change MAX_VIEWS from a hard-coded constant of 4 to the last enum in that list, which changes it to 3. (I don't think it should have been 4 in the first place.) - wininfos that NEVER appear as panes in the main console window (e.g., logwin_info, pointswin_info, etc.) continue to use m_views[0]
1 parent d772a53 commit c25a4b8

File tree

8 files changed

+75
-47
lines changed

8 files changed

+75
-47
lines changed

src/osd/modules/debugger/win/consolewininfo.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ consolewin_info::consolewin_info(debugger_windows_interface &debugger) :
214214
m_current_cpu(nullptr),
215215
m_devices_menu(nullptr)
216216
{
217-
if (!window() || !m_views[0])
217+
if (!window() || !m_views[VIEW_IDX_DISASM])
218218
goto cleanup;
219219

220220
// create the views
221-
m_views[1].reset(new debugview_info(debugger, *this, window(), DVT_STATE));
222-
if (!m_views[1]->is_valid())
221+
m_views[VIEW_IDX_STATE].reset(new debugview_info(debugger, *this, window(), DVT_STATE));
222+
if (!m_views[VIEW_IDX_STATE]->is_valid())
223223
goto cleanup;
224-
m_views[2].reset(new debugview_info(debugger, *this, window(), DVT_CONSOLE));
225-
if (!m_views[2]->is_valid())
224+
m_views[VIEW_IDX_CONSOLE].reset(new debugview_info(debugger, *this, window(), DVT_CONSOLE));
225+
if (!m_views[VIEW_IDX_CONSOLE]->is_valid())
226226
goto cleanup;
227227

228228
{
@@ -257,12 +257,20 @@ consolewin_info::consolewin_info(debugger_windows_interface &debugger) :
257257

258258
// adjust the min/max sizes for the window style
259259
bounds.top = bounds.left = 0;
260-
bounds.right = bounds.bottom = EDGE_WIDTH + m_views[1]->maxwidth() + (2 * EDGE_WIDTH) + 100 + EDGE_WIDTH;
260+
bounds.right = bounds.bottom =
261+
EDGE_WIDTH + m_views[VIEW_IDX_STATE]->maxwidth() +
262+
(2 * EDGE_WIDTH) + 100 + EDGE_WIDTH;
261263
AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX);
262264
set_minwidth(bounds.right - bounds.left);
263265

264266
bounds.top = bounds.left = 0;
265-
bounds.right = bounds.bottom = EDGE_WIDTH + m_views[1]->maxwidth() + (2 * EDGE_WIDTH) + std::max(m_views[0]->maxwidth(), m_views[2]->maxwidth()) + EDGE_WIDTH;
267+
bounds.right = bounds.bottom =
268+
EDGE_WIDTH + m_views[VIEW_IDX_STATE]->maxwidth() +
269+
(2 * EDGE_WIDTH) +
270+
std::max(
271+
m_views[VIEW_IDX_DISASM]->maxwidth(),
272+
m_views[VIEW_IDX_CONSOLE]->maxwidth()) +
273+
EDGE_WIDTH;
266274
AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX);
267275
set_maxwidth(bounds.right - bounds.left);
268276

@@ -283,9 +291,9 @@ consolewin_info::consolewin_info(debugger_windows_interface &debugger) :
283291
return;
284292

285293
cleanup:
286-
m_views[2].reset();
287-
m_views[1].reset();
288-
m_views[0].reset();
294+
m_views[VIEW_IDX_CONSOLE].reset();
295+
m_views[VIEW_IDX_STATE].reset();
296+
m_views[VIEW_IDX_DISASM].reset();
289297
}
290298

291299

@@ -301,8 +309,8 @@ void consolewin_info::set_cpu(device_t &device)
301309
m_current_cpu = &device;
302310

303311
// first set all the views to the new cpu number
304-
m_views[0]->set_source_for_device(device);
305-
m_views[1]->set_source_for_device(device);
312+
m_views[VIEW_IDX_DISASM]->set_source_for_device(device);
313+
m_views[VIEW_IDX_STATE]->set_source_for_device(device);
306314

307315
// then update the caption
308316
std::string title = string_format("Debug: %s - %s '%s'", device.machine().system().name, device.name(), device.tag());
@@ -327,7 +335,7 @@ void consolewin_info::recompute_children()
327335
regrect.top = parent.top + EDGE_WIDTH;
328336
regrect.bottom = parent.bottom - EDGE_WIDTH;
329337
regrect.left = parent.left + EDGE_WIDTH;
330-
regrect.right = regrect.left + m_views[1]->maxwidth();
338+
regrect.right = regrect.left + m_views[VIEW_IDX_STATE]->maxwidth();
331339

332340
// edit box goes at the bottom of the remaining area
333341
RECT editrect;
@@ -350,9 +358,9 @@ void consolewin_info::recompute_children()
350358
conrect.right = parent.right - EDGE_WIDTH;
351359

352360
// set the bounds of things
353-
m_views[0]->set_bounds(disrect);
354-
m_views[1]->set_bounds(regrect);
355-
m_views[2]->set_bounds(conrect);
361+
m_views[VIEW_IDX_DISASM]->set_bounds(disrect);
362+
m_views[VIEW_IDX_STATE]->set_bounds(regrect);
363+
m_views[VIEW_IDX_CONSOLE]->set_bounds(conrect);
356364
set_editwnd_bounds(editrect);
357365
}
358366

src/osd/modules/debugger/win/debugwininfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ void debugwin_info::restore_configuration_from_node(util::xml::data_node const &
353353
recompute_children();
354354
}
355355

356-
356+
// Set the bounds for the corresponding debug_viewinfo. This implementation
357+
// is only intended for use with win_infos that appear solely as an
358+
// independent free-floating window. win_infos that can appear as a frame
359+
// within the main consolewin_info should override this.
357360
void debugwin_info::recompute_children()
358361
{
359362
if (m_views[0] != nullptr)

src/osd/modules/debugger/win/debugwininfo.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class debugwin_info : protected debugbase_info
5858
static DWORD const DEBUG_WINDOW_STYLE = (WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN) & (~WS_MINIMIZEBOX & ~WS_MAXIMIZEBOX);
5959
static DWORD const DEBUG_WINDOW_STYLE_EX = 0;
6060

61-
static int const MAX_VIEWS = 4;
6261
static int const EDGE_WIDTH = 3;
6362

6463
enum
@@ -122,6 +121,19 @@ class debugwin_info : protected debugbase_info
122121
ID_DEVICE_OPTIONS // always keep this at the end
123122
};
124123

124+
// Indices for use with m_views. Each *win_info class that can appear
125+
// as a frame within the main consolewin_info should use these
126+
// indices to find its *view_info class, even when it's currently
127+
// shown as an independent free-floating window. All other *win_info
128+
// classes (e.g., logwin_info, pointswin_info, etc.) just use m_views[0]
129+
enum
130+
{
131+
VIEW_IDX_DISASM,
132+
VIEW_IDX_STATE,
133+
VIEW_IDX_CONSOLE,
134+
MAX_VIEWS
135+
};
136+
125137
debugwin_info(debugger_windows_interface &debugger, bool is_main_console, LPCSTR title, WNDPROC handler);
126138

127139
bool is_main_console() const { return m_is_main_console; }

src/osd/modules/debugger/win/disasmbasewininfo.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
namespace osd::debugger::win {
2424

2525
disasmbasewin_info::disasmbasewin_info(debugger_windows_interface &debugger, bool is_main_console, LPCSTR title, WNDPROC handler) :
26-
editwin_info(debugger, is_main_console, title, handler)
26+
editwin_info(debugger, is_main_console, VIEW_IDX_DISASM, title, handler)
2727
{
2828
if (!window())
2929
return;
3030

31-
m_views[0].reset(new disasmview_info(debugger, *this, window()));
32-
if (!m_views[0] || !m_views[0]->is_valid())
31+
m_views[VIEW_IDX_DISASM].reset(new disasmview_info(debugger, *this, window()));
32+
if (!m_views[VIEW_IDX_DISASM] || !m_views[VIEW_IDX_DISASM]->is_valid())
3333
{
34-
m_views[0].reset();
34+
m_views[VIEW_IDX_DISASM].reset();
3535
return;
3636
}
3737

@@ -47,8 +47,8 @@ disasmbasewin_info::disasmbasewin_info(debugger_windows_interface &debugger, boo
4747
AppendMenu(GetMenu(window()), MF_ENABLED | MF_POPUP, (UINT_PTR)optionsmenu, TEXT("Options"));
4848

4949
// set up the view to track the initial expression
50-
downcast<disasmview_info *>(m_views[0].get())->set_expression("curpc");
51-
m_views[0]->set_source_for_visible_cpu();
50+
downcast<disasmview_info *>(m_views[VIEW_IDX_DISASM].get())->set_expression("curpc");
51+
m_views[VIEW_IDX_DISASM]->set_source_for_visible_cpu();
5252
}
5353

5454

@@ -92,7 +92,7 @@ bool disasmbasewin_info::handle_key(WPARAM wparam, LPARAM lparam)
9292
return true;
9393

9494
case VK_RETURN:
95-
if (m_views[0]->cursor_visible() && m_views[0]->source_is_visible_cpu())
95+
if (m_views[VIEW_IDX_DISASM]->cursor_visible() && m_views[VIEW_IDX_DISASM]->source_is_visible_cpu())
9696
{
9797
SendMessage(window(), WM_COMMAND, ID_STEP, 0);
9898
return true;
@@ -108,7 +108,7 @@ void disasmbasewin_info::update_menu()
108108
{
109109
editwin_info::update_menu();
110110

111-
auto *const dasmview = downcast<disasmview_info *>(m_views[0].get());
111+
auto *const dasmview = downcast<disasmview_info *>(m_views[VIEW_IDX_DISASM].get());
112112
HMENU const menu = GetMenu(window());
113113

114114
bool const disasm_cursor_visible = dasmview->cursor_visible();
@@ -154,7 +154,7 @@ void disasmbasewin_info::update_menu()
154154

155155
bool disasmbasewin_info::handle_command(WPARAM wparam, LPARAM lparam)
156156
{
157-
auto *const dasmview = downcast<disasmview_info *>(m_views[0].get());
157+
auto *const dasmview = downcast<disasmview_info *>(m_views[VIEW_IDX_DISASM].get());
158158

159159
switch (HIWORD(wparam))
160160
{
@@ -270,14 +270,14 @@ bool disasmbasewin_info::handle_command(WPARAM wparam, LPARAM lparam)
270270
void disasmbasewin_info::restore_configuration_from_node(util::xml::data_node const &node)
271271
{
272272
editwin_info::restore_configuration_from_node(node);
273-
m_views[0]->restore_configuration_from_node(node);
273+
m_views[VIEW_IDX_DISASM]->restore_configuration_from_node(node);
274274
}
275275

276276

277277
void disasmbasewin_info::save_configuration_to_node(util::xml::data_node &node)
278278
{
279279
editwin_info::save_configuration_to_node(node);
280-
m_views[0]->save_configuration_to_node(node);
280+
m_views[VIEW_IDX_DISASM]->save_configuration_to_node(node);
281281
}
282282

283283
} // namespace osd::debugger::win

src/osd/modules/debugger/win/disasmwininfo.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ disasmwin_info::disasmwin_info(debugger_windows_interface &debugger) :
2424
disasmbasewin_info(debugger, false, "Disassembly", nullptr),
2525
m_combownd(nullptr)
2626
{
27-
if ((window() == nullptr) || (m_views[0] == nullptr))
27+
if ((window() == nullptr) || (m_views[VIEW_IDX_DISASM] == nullptr))
2828
return;
2929

3030
// set up the view to track the initial expression
@@ -33,7 +33,7 @@ disasmwin_info::disasmwin_info(debugger_windows_interface &debugger) :
3333
editwnd_select_all();
3434

3535
// create a combo box
36-
m_combownd = m_views[0]->create_source_combobox(window(), (LONG_PTR)this);
36+
m_combownd = m_views[VIEW_IDX_DISASM]->create_source_combobox(window(), (LONG_PTR)this);
3737

3838
// set the caption
3939
update_caption();
@@ -60,7 +60,7 @@ void disasmwin_info::recompute_children()
6060
// compute a client rect
6161
RECT bounds;
6262
bounds.top = bounds.left = 0;
63-
bounds.right = m_views[0]->prefwidth() + (2 * EDGE_WIDTH);
63+
bounds.right = m_views[VIEW_IDX_DISASM]->prefwidth() + (2 * EDGE_WIDTH);
6464
bounds.bottom = 200;
6565
AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX);
6666

@@ -93,7 +93,7 @@ void disasmwin_info::recompute_children()
9393
dasmrect.right = parent.right - EDGE_WIDTH;
9494

9595
// set the bounds of things
96-
m_views[0]->set_bounds(dasmrect);
96+
m_views[VIEW_IDX_DISASM]->set_bounds(dasmrect);
9797
set_editwnd_bounds(editrect);
9898
smart_set_window_bounds(m_combownd, window(), comborect);
9999
}
@@ -109,7 +109,7 @@ bool disasmwin_info::handle_command(WPARAM wparam, LPARAM lparam)
109109
int const sel = SendMessage((HWND)lparam, CB_GETCURSEL, 0, 0);
110110
if (sel != CB_ERR)
111111
{
112-
m_views[0]->set_source_index(sel);
112+
m_views[VIEW_IDX_DISASM]->set_source_index(sel);
113113
update_caption();
114114

115115
// reset the focus
@@ -134,7 +134,7 @@ void disasmwin_info::draw_contents(HDC dc)
134134
void disasmwin_info::process_string(const std::string &string)
135135
{
136136
// set the string to the disasm view
137-
downcast<disasmview_info *>(m_views[0].get())->set_expression(string);
137+
downcast<disasmview_info *>(m_views[VIEW_IDX_DISASM].get())->set_expression(string);
138138

139139
// select everything in the edit text box
140140
editwnd_select_all();
@@ -146,14 +146,15 @@ void disasmwin_info::process_string(const std::string &string)
146146

147147
void disasmwin_info::update_caption()
148148
{
149-
win_set_window_text_utf8(window(), std::string("Disassembly: ").append(m_views[0]->source_name()).c_str());
149+
win_set_window_text_utf8(window(), std::string("Disassembly: ").append(m_views[VIEW_IDX_DISASM]->source_name()).c_str());
150150
}
151151

152152

153153
void disasmwin_info::restore_configuration_from_node(util::xml::data_node const &node)
154154
{
155-
m_views[0]->set_source_index(node.get_attribute_int(ATTR_WINDOW_DISASSEMBLY_CPU, m_views[0]->source_index()));
156-
int const cursource = m_views[0]->source_index();
155+
m_views[VIEW_IDX_DISASM]->set_source_index(
156+
node.get_attribute_int(ATTR_WINDOW_DISASSEMBLY_CPU, m_views[VIEW_IDX_DISASM]->source_index()));
157+
int const cursource = m_views[VIEW_IDX_DISASM]->source_index();
157158
if (0 <= cursource)
158159
SendMessage(m_combownd, CB_SETCURSEL, cursource, 0);
159160
update_caption();
@@ -174,8 +175,10 @@ void disasmwin_info::save_configuration_to_node(util::xml::data_node &node)
174175
disasmbasewin_info::save_configuration_to_node(node);
175176

176177
node.set_attribute_int(ATTR_WINDOW_TYPE, WINDOW_TYPE_DISASSEMBLY_VIEWER);
177-
node.set_attribute_int(ATTR_WINDOW_DISASSEMBLY_CPU, m_views[0]->source_index());
178-
node.add_child(NODE_WINDOW_EXPRESSION, downcast<disasmview_info *>(m_views[0].get())->expression());
178+
node.set_attribute_int(ATTR_WINDOW_DISASSEMBLY_CPU, m_views[VIEW_IDX_DISASM]->source_index());
179+
node.add_child(
180+
NODE_WINDOW_EXPRESSION,
181+
downcast<disasmview_info *>(m_views[VIEW_IDX_DISASM].get())->expression());
179182
}
180183

181184
} // namespace osd::debugger::win

src/osd/modules/debugger/win/editwininfo.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ constexpr int HISTORY_LENGTH = 100;
3232
} // anonymous namespace
3333

3434

35-
editwin_info::editwin_info(debugger_windows_interface &debugger, bool is_main_console, LPCSTR title, WNDPROC handler) :
35+
editwin_info::editwin_info(debugger_windows_interface &debugger, bool is_main_console, int viewidx, LPCSTR title, WNDPROC handler) :
3636
debugwin_info(debugger, is_main_console, title, handler),
3737
m_editwnd(nullptr),
38+
m_viewidx(viewidx),
3839
m_edit_defstr(),
3940
m_original_editproc(nullptr),
4041
m_history(),
@@ -185,13 +186,13 @@ LRESULT editwin_info::edit_proc(UINT message, WPARAM wparam, LPARAM lparam)
185186
break;
186187

187188
case VK_PRIOR:
188-
if (m_views[0] != nullptr)
189-
m_views[0]->send_pageup();
189+
if (m_views[m_viewidx] != nullptr)
190+
m_views[m_viewidx]->send_pageup();
190191
break;
191192

192193
case VK_NEXT:
193-
if (m_views[0] != nullptr)
194-
m_views[0]->send_pagedown();
194+
if (m_views[m_viewidx] != nullptr)
195+
m_views[m_viewidx]->send_pagedown();
195196
break;
196197

197198
case VK_TAB:

src/osd/modules/debugger/win/editwininfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace osd::debugger::win {
2323
class editwin_info : public debugwin_info
2424
{
2525
public:
26-
editwin_info(debugger_windows_interface &debugger, bool is_main_console, LPCSTR title, WNDPROC handler);
26+
editwin_info(debugger_windows_interface &debugger, bool is_main_console, int viewidx, LPCSTR title, WNDPROC handler);
2727
virtual ~editwin_info();
2828

2929
virtual bool restore_field(HWND wnd) override;
@@ -55,6 +55,7 @@ class editwin_info : public debugwin_info
5555
static LRESULT CALLBACK static_edit_proc(HWND wnd, UINT message, WPARAM wparam, LPARAM lparam);
5656

5757
HWND m_editwnd;
58+
int m_viewidx;
5859
std::string m_edit_defstr;
5960
WNDPROC m_original_editproc;
6061
history_deque m_history;

src/osd/modules/debugger/win/memorywininfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace osd::debugger::win {
2222

2323
memorywin_info::memorywin_info(debugger_windows_interface &debugger) :
24-
editwin_info(debugger, false, "Memory", nullptr),
24+
editwin_info(debugger, false, 0 /* view index */, "Memory", nullptr),
2525
m_combownd(nullptr)
2626
{
2727
if (!window())

0 commit comments

Comments
 (0)