windows: improve multiple selection support of ram tools.

This commit is contained in:
gocha 2010-10-03 10:16:51 +00:00
parent 520bd4e712
commit ad0689009d
4 changed files with 87 additions and 23 deletions

View File

@ -761,7 +761,8 @@ INT_PTR CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM l
case LVN_ITEMCHANGED:
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lparam;
if((pNMListView->uOldState ^ pNMListView->uNewState) & LVIS_SELECTED) // on selection changed
if(pNMListView->uNewState & LVIS_FOCUSED ||
(pNMListView->uOldState ^ pNMListView->uNewState) & LVIS_SELECTED) // on selection changed
{
int selCount = ListView_GetSelectedCount(cheatListView);
EnableWindow(GetDlgItem(dialog, IDC_BEDIT), (selCount == 1) ? TRUE : FALSE);
@ -1005,8 +1006,7 @@ void CheatsAddDialog(HWND parentHwnd, u32 address, u32 value, u8 size, const cha
//
//char buf[256];
//cheats->get(&tempCheat, cheatEditPos);
//if (tempCheat.enabled)
// ListView_SetItemText(cheatListView, cheatEditPos, 0, "X");
//ListView_SetCheckState(cheatListView, cheatEditPos, 0, tempCheat.enabled);
//wsprintf(buf, "0x02%06X", tempCheat.code[0][0]);
//ListView_SetItemText(cheatListView, cheatEditPos, 1, buf);
//ltoa(tempCheat.code[0][1], buf, 10);

View File

@ -1049,8 +1049,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;
@ -1485,7 +1485,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);
@ -1688,13 +1689,15 @@ LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
} {rv = true; break;}
case IDC_C_ADDCHEAT:
{
int cheatItemIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_RAMLIST));
if(cheatItemIndex >= 0)
HWND ramListControl = GetDlgItem(hDlg,IDC_RAMLIST);
int cheatItemIndex = ListView_GetNextItem(ramListControl, -1, LVNI_SELECTED);
while (cheatItemIndex >= 0)
{
u32 address = CALL_WITH_T_SIZE_TYPES(GetHardwareAddressFromItemIndex, rs_type_size,rs_t=='s',noMisalign, cheatItemIndex);
u8 size = (rs_type_size=='b') ? 1 : (rs_type_size=='w' ? 2 : 4);
u32 value = CALL_WITH_T_SIZE_TYPES(GetCurValueFromItemIndex, rs_type_size,rs_t=='s',noMisalign, cheatItemIndex);
CheatsAddDialog(hDlg, address, value, size);
cheatItemIndex = ListView_GetNextItem(ramListControl, cheatItemIndex, LVNI_SELECTED);
}
{rv = true; break;}
}
@ -1781,8 +1784,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(GetHardwareAddressFromItemIndex, rs_type_size,rs_t=='s',noMisalign, watchItemIndex);
@ -1791,14 +1798,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, "");
// bring up the ram watch window if it's not already showing so the user knows where the watch went
if(inserted && !RamWatchHWnd)
SendMessage(MainWindow->getHWnd(), WM_COMMAND, ID_RAM_WATCH, 0);
SetForegroundWindow(RamSearchHWnd);
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(MainWindow->getHWnd(), WM_COMMAND, ID_RAM_WATCH, 0);
SetForegroundWindow(RamSearchHWnd);
{rv = true; break;}
}

View File

@ -38,6 +38,8 @@ int WatchCount=0;
bool QuickSaveWatches();
bool ResetWatches();
void RefreshWatchListSelectedCountControlStatus(HWND hDlg);
unsigned int GetCurrentValue(AddressWatcher& watch)
{
char buf[4];
@ -547,8 +549,10 @@ bool Load_Watches(bool clear, const char* filename)
}
fclose(WatchFile);
if (RamWatchHWnd)
if (RamWatchHWnd) {
ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
RefreshWatchListSelectedCountControlStatus(RamWatchHWnd);
}
RWfileChanged=false;
return true;
}
@ -608,8 +612,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;
@ -785,6 +791,38 @@ void init_list_box(HWND Box, const char* Strs[], int numColumns, int *columnWidt
ListView_SetExtendedListViewStyle(Box, LVS_EX_FULLROWSELECT);
}
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;
@ -865,6 +903,7 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
Update_RAM_Watch();
DragAcceptFiles(hDlg, TRUE);
RefreshWatchListSelectedCountControlStatus(hDlg);
return true;
break;
}
@ -898,6 +937,17 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
LPNMHDR lP = (LPNMHDR) lParam;
switch (lP->code)
{
case LVN_ITEMCHANGED: // selection changed event
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lP;
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
RefreshWatchListSelectedCountControlStatus(hDlg);
}
} break;
case LVN_GETDISPINFO:
{
LV_DISPINFO *Item = (LV_DISPINFO *)lParam;
@ -966,15 +1016,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);
RWfileChanged=true;
SetFocus(GetDlgItem(hDlg,IDC_WATCHLIST));
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)

Binary file not shown.