adapted ram search/watch fixes/improvements from desmume

This commit is contained in:
gocha 2010-10-07 13:32:42 +00:00
parent 795de75419
commit 422dd2783d
3 changed files with 2112 additions and 2060 deletions

View File

@ -1086,8 +1086,8 @@ void RefreshRamListSelectedCountControlStatus(HWND hDlg)
{
if(selCount < 2 || prevSelCount < 2)
{
EnableWindow(GetDlgItem(hDlg, IDC_C_WATCH), (selCount == 1 && WatchCount < MAX_WATCH_COUNT) ? TRUE : FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_C_ADDCHEAT), (selCount == 1) ? TRUE : FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_C_WATCH), (selCount >= 1 && WatchCount < MAX_WATCH_COUNT) ? TRUE : FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_C_ADDCHEAT), (selCount >= 1) ? TRUE : FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_C_ELIMINATE), (selCount >= 1) ? TRUE : FALSE);
}
prevSelCount = selCount;
@ -1134,7 +1134,7 @@ void signal_new_size ()
int addr = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_last_type_size,rs_t=='s',rs_last_no_misalign, watchIndex);
if(!selHardwareAddrs.empty() && addr == selHardwareAddrs.back().End())
selHardwareAddrs.back().size += size;
else
else if (!(noMisalign && oldSize < newSize && addr % newSize != 0))
selHardwareAddrs.push_back(AddrRange(addr,size));
}
}
@ -1164,15 +1164,11 @@ void signal_new_size ()
if(selRangeTop == -1)
continue;
// select the entire range at once without deselecting the other ranges
// looks hacky but it works, and the only documentation I found on how to do this was blatantly false and equally hacky anyway
POINT pos;
ListView_EnsureVisible(lv, selRangeTop, 0);
ListView_GetItemPosition(lv, selRangeTop, &pos);
SendMessage(lv, WM_LBUTTONDOWN, MK_LBUTTON|MK_CONTROL, MAKELONG(pos.x,pos.y));
ListView_EnsureVisible(lv, selRangeBottom, 0);
ListView_GetItemPosition(lv, selRangeBottom, &pos);
SendMessage(lv, WM_LBUTTONDOWN, MK_LBUTTON|MK_CONTROL|MK_SHIFT, MAKELONG(pos.x,pos.y));
// select the entire range
for (int j = selRangeTop; j <= selRangeBottom; j++)
{
ListView_SetItemState(lv, j, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
}
}
// restore previous scroll position
@ -1192,6 +1188,7 @@ void signal_new_size ()
ListView_Update(lv, -1);
}
InvalidateRect(lv, NULL, TRUE);
//SetFocus(lv);
}
@ -1498,7 +1495,8 @@ LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
case LVN_ITEMCHANGED: // selection changed event
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lP;
if(pNMListView->uNewState & LVIS_FOCUSED)
if(pNMListView->uNewState & LVIS_FOCUSED ||
(pNMListView->uNewState ^ pNMListView->uOldState) & LVIS_SELECTED)
{
// disable buttons that we don't have the right number of selected items for
RefreshRamListSelectedCountControlStatus(hDlg);
@ -1701,8 +1699,9 @@ LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
} {rv = true; break;}
case IDC_C_ADDCHEAT:
{
int watchItemIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_RAMLIST));
if(watchItemIndex >= 0)
HWND ramListControl = GetDlgItem(hDlg,IDC_RAMLIST);
int watchItemIndex = ListView_GetNextItem(ramListControl, -1, LVNI_SELECTED);
while (watchItemIndex >= 0)
{
unsigned long address = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_type_size,rs_t=='s',noMisalign, watchItemIndex);
unsigned long curvalue = CALL_WITH_T_SIZE_TYPES_1(GetCurValueFromItemIndex, rs_type_size,rs_t=='s',noMisalign, watchItemIndex);
@ -1743,6 +1742,8 @@ LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
UpdateCheatsAdded();
watchItemIndex = ListView_GetNextItem(ramListControl, watchItemIndex, LVNI_SELECTED);
}
} {rv = true; break;}
case IDC_C_RESET:
@ -1831,8 +1832,12 @@ invalid_field:
}
case IDC_C_WATCH:
{
int watchItemIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_RAMLIST));
if(watchItemIndex >= 0)
HWND ramListControl = GetDlgItem(hDlg,IDC_RAMLIST);
int selCount = ListView_GetSelectedCount(ramListControl);
bool inserted = false;
int watchItemIndex = ListView_GetNextItem(ramListControl, -1, LVNI_SELECTED);
while (watchItemIndex >= 0)
{
AddressWatcher tempWatch;
tempWatch.Address = CALL_WITH_T_SIZE_TYPES_1(GetHardwareAddressFromItemIndex, rs_type_size,rs_t=='s',noMisalign, watchItemIndex);
@ -1841,14 +1846,17 @@ invalid_field:
tempWatch.WrongEndian = 0; //Replace when I get little endian working
tempWatch.comment = NULL;
bool inserted = InsertWatch(tempWatch, hDlg);
//ListView_Update(GetDlgItem(hDlg,IDC_RAMLIST), -1);
if (selCount == 1)
inserted |= InsertWatch(tempWatch, hDlg);
else
inserted |= InsertWatch(tempWatch, "");
watchItemIndex = ListView_GetNextItem(ramListControl, watchItemIndex, LVNI_SELECTED);
}
// bring up the ram watch window if it's not already showing so the user knows where the watch went
if(inserted && !RamWatchHWnd)
SendMessage(hWnd, WM_COMMAND, ID_RAM_WATCH, 0);
SetForegroundWindow(RamSearchHWnd);
}
{rv = true; break;}
}

View File

@ -57,6 +57,8 @@ void init_list_box(HWND Box, const char* Strs[], int numColumns, int *columnWidt
bool QuickSaveWatches();
bool ResetWatches();
void RefreshWatchListSelectedCountControlStatus(HWND hDlg);
unsigned int GetCurrentValue(AddressWatcher& watch)
{
//TODO: A similar if for 4-byte just to be through, but there shouldn't be any reason to have 4-byte on the NES!
@ -449,8 +451,10 @@ void OpenRWRecentFile(int memwRFileNumber)
}
fclose(WatchFile);
if (RamWatchHWnd)
if (RamWatchHWnd) {
ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
RefreshWatchListSelectedCountControlStatus(RamWatchHWnd);
}
RWfileChanged=false;
return;
}
@ -646,8 +650,10 @@ bool ResetWatches()
rswatches[WatchCount].comment = NULL;
}
WatchCount++;
if (RamWatchHWnd)
if (RamWatchHWnd) {
ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
RefreshWatchListSelectedCountControlStatus(RamWatchHWnd);
}
RWfileChanged = false;
currentWatch[0] = NULL;
return true;
@ -827,6 +833,38 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
void RamWatchEnableCommand(HWND hDlg, HMENU hMenu, UINT uIDEnableItem, bool enable)
{
EnableWindow(GetDlgItem(hDlg, uIDEnableItem), (enable?TRUE:FALSE));
if (hMenu != NULL) {
if (uIDEnableItem == ID_WATCHES_UPDOWN) {
EnableMenuItem(hMenu, IDC_C_WATCH_UP, MF_BYCOMMAND | (enable?MF_ENABLED:MF_GRAYED));
EnableMenuItem(hMenu, IDC_C_WATCH_DOWN, MF_BYCOMMAND | (enable?MF_ENABLED:MF_GRAYED));
}
else
EnableMenuItem(hMenu, uIDEnableItem, MF_BYCOMMAND | (enable?MF_ENABLED:MF_GRAYED));
}
}
void RefreshWatchListSelectedCountControlStatus(HWND hDlg)
{
static int prevSelCount=-1;
int selCount = ListView_GetSelectedCount(GetDlgItem(hDlg,IDC_WATCHLIST));
if(selCount != prevSelCount)
{
if(selCount < 2 || prevSelCount < 2)
{
RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_WATCH_EDIT, selCount == 1);
RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_WATCH_REMOVE, selCount >= 1);
RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_WATCH, selCount == 1);
RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_WATCH_DUPLICATE, selCount == 1);
RamWatchEnableCommand(hDlg, ramwatchmenu, IDC_C_ADDCHEAT, selCount == 1);
RamWatchEnableCommand(hDlg, ramwatchmenu, ID_WATCHES_UPDOWN, selCount == 1);
}
prevSelCount = selCount;
}
}
LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT r;
@ -914,6 +952,7 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
DragAcceptFiles(hDlg, TRUE);
RefreshWatchListSelectedCountControlStatus(hDlg);
return false;
} break;
@ -950,10 +989,11 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
case LVN_ITEMCHANGED: // selection changed event
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lP;
if(pNMListView->uNewState & LVIS_FOCUSED)
if(pNMListView->uNewState & LVIS_FOCUSED ||
(pNMListView->uNewState ^ pNMListView->uOldState) & LVIS_SELECTED)
{
// disable buttons that we don't have the right number of selected items for
RefreshWatchListSelectedItemControlStatus(hDlg);
RefreshWatchListSelectedCountControlStatus(hDlg);
}
} break;
@ -1028,15 +1068,19 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
ResetWatches();
return true;
case IDC_C_WATCH_REMOVE:
watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST));
if(watchIndex != -1)
{
HWND watchListControl = GetDlgItem(hDlg, IDC_WATCHLIST);
watchIndex = ListView_GetNextItem(watchListControl, -1, LVNI_ALL | LVNI_SELECTED);
while (watchIndex >= 0)
{
RemoveWatch(watchIndex);
ListView_SetItemCount(GetDlgItem(hDlg,IDC_WATCHLIST),WatchCount);
ListView_DeleteItem(watchListControl, watchIndex);
watchIndex = ListView_GetNextItem(watchListControl, -1, LVNI_ALL | LVNI_SELECTED);
}
RWfileChanged=true;
SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST));
}
return true;
}
case IDC_C_WATCH_EDIT:
watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST));
if(watchIndex != -1)

View File

@ -1638,7 +1638,7 @@ CAPTION " RAM Watch"
MENU RAMWATCH_MENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_WATCHLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP,9,9,210,279,WS_EX_CLIENTEDGE
CONTROL "",IDC_WATCHLIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDATA | WS_BORDER | WS_TABSTOP,9,9,210,279,WS_EX_CLIENTEDGE
PUSHBUTTON "Edit",IDC_C_WATCH_EDIT,226,66,34,14
PUSHBUTTON "Remove",IDC_C_WATCH_REMOVE,226,83,34,14
PUSHBUTTON "New",IDC_C_WATCH,226,100,34,14