From f72ed65d1ae2af141a125c48e76e019d11570641 Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Wed, 20 Mar 2002 13:05:58 +0000 Subject: [PATCH] (final patch from ) This patch implements two things: - space now dismisses a menu, text or menutext window when you are at the bottom of that window - Page scrolling in menus now works as follows: pressing PgDn (or Space in NH mode) moves the focus down one page, and moves the scroll position down one page. The effect of this is that you always get a full new page of items (which is what NetHack players expect), and that the focus moved down one page (what Windows users expect.) The same (revers) goes for scrolling up a page. A Windows user will still be a bit surprised when the focus is on the top item, and he presses '>': he gets a new page of things instead of the focus moving to the bottom of the page. However, the PgUp/PgDn keys (which he probably uses) still have the old Windows behaviour. --- win/win32/mhmenu.c | 49 ++++++++++++++++++++++++++++++++++++++++------ win/win32/mhtext.c | 11 ++++++++++- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index d222e0ca0..67eb9765d 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -865,7 +865,7 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch) { int i = 0; PNHMenuWindow data; - int topIndex, pageSize; + int curIndex, topIndex, pageSize; boolean is_accelerator = FALSE; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); @@ -886,16 +886,24 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch) case MENU_NEXT_PAGE: topIndex = ListView_GetTopIndex( hwndList ); pageSize = ListView_GetCountPerPage( hwndList ); - i = min(topIndex+pageSize, data->menu.size-1); + curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + /* Focus down one page */ + i = min(curIndex+pageSize, data->menu.size-1); ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + /* Scrollpos down one page */ + i = min(topIndex+(2*pageSize - 1), data->menu.size-1); ListView_EnsureVisible(hwndList, i, FALSE); return -2; case MENU_PREVIOUS_PAGE: topIndex = ListView_GetTopIndex( hwndList ); pageSize = ListView_GetCountPerPage( hwndList ); - i = max(topIndex-pageSize, 0); + curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + /* Focus up one page */ + i = max(curIndex-pageSize, 0); ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + /* Scrollpos up one page */ + i = max(topIndex-pageSize, 0); ListView_EnsureVisible(hwndList, i, FALSE); break; @@ -1020,13 +1028,32 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch) return -2; case ' ': + { if (GetNHApp()->regNetHackMode) { - /* NetHack mode: Scroll down one page */ + /* NetHack mode: Scroll down one page, + ends menu when on last page. */ + SCROLLINFO si; + + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; + GetScrollInfo(hwndList, SB_VERT, &si); + if ((si.nPos + (int)si.nPage) > (si.nMax - si.nMin)) { + /* We're at the bottom: dismiss. */ + data->done = 1; + data->result = 0; + return -2; + } + /* We're not at the bottom: page down. */ topIndex = ListView_GetTopIndex( hwndList ); pageSize = ListView_GetCountPerPage( hwndList ); - i = min(topIndex+pageSize, data->menu.size-1); + curIndex = ListView_GetNextItem(hwndList, -1, LVNI_FOCUSED); + /* Focus down one page */ + i = min(curIndex+pageSize, data->menu.size-1); ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED); + /* Scrollpos down one page */ + i = min(topIndex+(2*pageSize - 1), data->menu.size-1); ListView_EnsureVisible(hwndList, i, FALSE); + return -2; } else { /* Windows mode: ends menu for PICK_ONE/PICK_NONE @@ -1047,6 +1074,7 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch) } } } + } break; default: @@ -1299,11 +1327,20 @@ LRESULT CALLBACK NHMenuTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA /* close on space in Windows mode page down on space in NetHack mode */ case VK_SPACE: - if (GetNHApp()->regNetHackMode) + { + SCROLLINFO si; + + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; + GetScrollInfo(hWnd, SB_VERT, &si); + /* If nethackmode and not at the end of the list */ + if (GetNHApp()->regNetHackMode && + (si.nPos + (int)si.nPage) <= (si.nMax - si.nMin)) SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); else PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); return 0; + } case VK_NEXT: SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); return 0; diff --git a/win/win32/mhtext.c b/win/win32/mhtext.c index d54875666..11c5ed214 100644 --- a/win/win32/mhtext.c +++ b/win/win32/mhtext.c @@ -216,11 +216,20 @@ LRESULT CALLBACK NHEditHookWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA /* close on space in Windows mode page down on space in NetHack mode */ case VK_SPACE: - if (GetNHApp()->regNetHackMode) + { + SCROLLINFO si; + + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; + GetScrollInfo(hWnd, SB_VERT, &si); + /* If nethackmode and not at the end of the list */ + if (GetNHApp()->regNetHackMode && + (si.nPos + (int)si.nPage) <= (si.nMax - si.nMin)) SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); else PostMessage(GetParent(hWnd), WM_COMMAND, MAKELONG(IDOK, 0), 0); return 0; + } case VK_NEXT: SendMessage(hWnd, EM_SCROLL, SB_PAGEDOWN, 0); return 0; -- 2.40.0