From c4bf762ec193606433184c90daf5a701912b08c6 Mon Sep 17 00:00:00 2001 From: Alex Kompel Date: Sun, 3 Jan 2016 19:52:05 -0800 Subject: [PATCH] win32_gui: mimic tty interface when "Nethack mode" is selected (remove window features) --- sys/winnt/defaults.nh | 4 +++ win/win32/mhmain.c | 62 ++++++++++++++++++++++++++++++------------- win/win32/mhmap.c | 2 ++ win/win32/mhmenu.c | 25 ++++++++--------- win/win32/mhmsgwnd.c | 4 ++- win/win32/mhstatus.c | 3 +++ win/win32/mhtext.c | 51 ++++++++++++++++++++--------------- win/win32/mswproc.c | 4 +-- win/win32/winMS.h | 1 + win/win32/winhack.rc | 4 +-- 10 files changed, 101 insertions(+), 59 deletions(-) diff --git a/sys/winnt/defaults.nh b/sys/winnt/defaults.nh index 562f2267d..50e801f03 100644 --- a/sys/winnt/defaults.nh +++ b/sys/winnt/defaults.nh @@ -100,6 +100,10 @@ OPTIONS=hilite_pet,!toptenwin # window, windowframe, windowtext. #OPTIONS=windowcolors:status windowtext/window message windowtext/window +# "Nethack mode" colors +OPTIONS=windowcolors:status white/#000000 message white/#000000 text white/#000000 menu white/#000000 menutext white/#000000 +OPTIONS=vary_msgcount:1 + # *** LOCATIONS *** # IMPORTANT: If you change any of these locations, the directories they # point at must exist. NetHack will not create them for you. diff --git a/win/win32/mhmain.c b/win/win32/mhmain.c index 2bf5029df..2b52f71cf 100644 --- a/win/win32/mhmain.c +++ b/win/win32/mhmain.c @@ -34,6 +34,7 @@ static int menuid2mapmode(int menuid); static int mapmode2menuid(int map_mode); static void nhlock_windows(BOOL lock); static char *nh_compose_ascii_screenshot(); +static void mswin_apply_window_style_all(); // returns strdup() created pointer - callee assumes the ownership HWND @@ -711,11 +712,12 @@ mswin_layout_main_window(HWND changed_child) /* kludge - inventory window should have its own type (same as menu-text as a matter of fact) */ - if (flags.perm_invent && i == WIN_INVEN) + if (flags.perm_invent && i == WIN_INVEN) { mswin_get_window_placement(NHW_INVEN, &rt); - else + } else { mswin_get_window_placement(GetNHApp()->windowlist[i].type, &rt); + } MoveWindow(GetNHApp()->windowlist[i].win, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, TRUE); @@ -879,6 +881,7 @@ onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) case IDM_NHMODE: { GetNHApp()->regNetHackMode = GetNHApp()->regNetHackMode ? 0 : 1; mswin_menu_check_intf_mode(); + mswin_apply_window_style_all(); break; } case IDM_CLEARSETTINGS: { @@ -1099,29 +1102,50 @@ mapmode2menuid(int map_mode) void nhlock_windows(BOOL lock) { - int i; + /* update menu */ + GetNHApp()->bWindowsLocked = lock; + CheckMenuItem(GetMenu(GetNHApp()->hMainWnd), IDM_SETTING_LOCKWINDOWS, + MF_BYCOMMAND | (lock ? MF_CHECKED : MF_UNCHECKED)); - /* go through the windows list and adjust sizes */ + /* restyle windows */ + mswin_apply_window_style_all(); +} + +void +mswin_apply_window_style(HWND hwnd) { + DWORD style = 0, exstyle = 0; + + style = GetWindowLong(hwnd, GWL_STYLE); + exstyle = GetWindowLong(hwnd, GWL_EXSTYLE); + + if( !GetNHApp()->bWindowsLocked ) { + style = WS_CHILD|WS_CLIPSIBLINGS|WS_CAPTION|WS_SIZEBOX|(style & (WS_VISIBLE|WS_VSCROLL|WS_HSCROLL)); + exstyle = WS_EX_WINDOWEDGE; + } else if (GetNHApp()->regNetHackMode) { + /* do away borders */ + style = WS_CHILD|WS_CLIPSIBLINGS|(style & (WS_VISIBLE|WS_VSCROLL|WS_HSCROLL)); + exstyle = 0; + } else { + style = WS_CHILD|WS_CLIPSIBLINGS|WS_THICKFRAME|(style & (WS_VISIBLE|WS_VSCROLL|WS_HSCROLL)); + exstyle = WS_EX_WINDOWEDGE; + } + + SetWindowLong(hwnd, GWL_STYLE, style); + SetWindowLong(hwnd, GWL_EXSTYLE, exstyle); + SetWindowPos(hwnd, NULL, 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOCOPYBITS); +} + +void +mswin_apply_window_style_all() { + int i; for (i = 0; i < MAXWINDOWS; i++) { if (IsWindow(GetNHApp()->windowlist[i].win) && !GetNHApp()->windowlist[i].dead) { - DWORD style; - style = GetWindowLong(GetNHApp()->windowlist[i].win, GWL_STYLE); - if (lock) - style &= ~WS_CAPTION; - else - style |= WS_CAPTION; - SetWindowLong(GetNHApp()->windowlist[i].win, GWL_STYLE, style); - SetWindowPos(GetNHApp()->windowlist[i].win, NULL, 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER - | SWP_FRAMECHANGED); + mswin_apply_window_style(GetNHApp()->windowlist[i].win); } } - - /* update menu */ - GetNHApp()->bWindowsLocked = lock; - CheckMenuItem(GetMenu(GetNHApp()->hMainWnd), IDM_SETTING_LOCKWINDOWS, - MF_BYCOMMAND | (lock ? MF_CHECKED : MF_UNCHECKED)); + mswin_layout_main_window(NULL); } // returns strdup() created pointer - callee assumes the ownership diff --git a/win/win32/mhmap.c b/win/win32/mhmap.c index 23501575e..5e9ac2630 100644 --- a/win/win32/mhmap.c +++ b/win/win32/mhmap.c @@ -89,6 +89,8 @@ mswin_init_map_window() /* Set window caption */ SetWindowText(ret, "Map"); + mswin_apply_window_style(ret); + return ret; } diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index 258eed46d..2a65afc85 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -119,15 +119,7 @@ mswin_init_menu_window(int type) /* Set window caption */ SetWindowText(ret, "Menu/Text"); - if (!GetNHApp()->bWindowsLocked) { - DWORD style; - style = GetWindowLong(ret, GWL_STYLE); - style |= WS_CAPTION; - SetWindowLong(ret, GWL_STYLE, style); - SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE - | SWP_NOZORDER - | SWP_FRAMECHANGED); - } + mswin_apply_window_style(ret); SetMenuType(ret, type); return ret; @@ -155,7 +147,7 @@ mswin_menu_window_select_menu(HWND hWnd, int how, MENU_ITEM_P **_selected, activate = TRUE; } - data->is_active = activate; + data->is_active = activate && !GetNHApp()->regNetHackMode; /* set menu type */ SetMenuListType(hWnd, how); @@ -485,7 +477,12 @@ MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); } } - return FALSE; + return FALSE; + + case WM_CTLCOLORDLG: + return (INT_PTR)(text_bg_brush + ? text_bg_brush + : SYSCLR_TO_BRUSH(DEFAULT_COLOR_BG_TEXT)); case WM_DESTROY: if (data) { @@ -801,17 +798,17 @@ SetMenuListType(HWND hWnd, int how) switch (how) { case PICK_NONE: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; break; case PICK_ONE: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; break; case PICK_ANY: - dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD | WS_VSCROLL + dwStyles = WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_VSCROLL | WS_HSCROLL | LVS_REPORT | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; break; diff --git a/win/win32/mhmsgwnd.c b/win/win32/mhmsgwnd.c index 44ec78103..e30a099b3 100644 --- a/win/win32/mhmsgwnd.c +++ b/win/win32/mhmsgwnd.c @@ -9,7 +9,7 @@ #define MSG_WRAP_TEXT -#define MSG_VISIBLE_LINES max(iflags.wc_vary_msgcount, 2) +#define MSG_VISIBLE_LINES max(iflags.wc_vary_msgcount, 1) #define MAX_MSG_LINES 128 #define MSG_LINES (int) min(iflags.msg_history, MAX_MSG_LINES) #define MAXWINDOWTEXT TBUFSZ @@ -108,6 +108,8 @@ mswin_init_message_window() /* Set window caption */ SetWindowText(ret, "Messages"); + mswin_apply_window_style(ret); + return ret; } diff --git a/win/win32/mhstatus.c b/win/win32/mhstatus.c index 21d3b7bf2..fce51f268 100644 --- a/win/win32/mhstatus.c +++ b/win/win32/mhstatus.c @@ -80,6 +80,9 @@ mswin_init_status_window() ZeroMemory(data, sizeof(NHStatusWindow)); SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data); + + mswin_apply_window_style(ret); + return ret; } diff --git a/win/win32/mhtext.c b/win/win32/mhtext.c index 4dd7a1059..626e46e2b 100644 --- a/win/win32/mhtext.c +++ b/win/win32/mhtext.c @@ -51,15 +51,6 @@ mswin_init_text_window() /* Set window caption */ SetWindowText(ret, "Text"); - if (!GetNHApp()->bWindowsLocked) { - DWORD style; - style = GetWindowLong(ret, GWL_STYLE); - style |= WS_CAPTION; - SetWindowLong(ret, GWL_STYLE, style); - SetWindowPos(ret, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE - | SWP_NOZORDER - | SWP_FRAMECHANGED); - } /* create and set window data */ data = (PNHTextWindow) malloc(sizeof(NHTextWindow)); @@ -67,6 +58,9 @@ mswin_init_text_window() panic("out of memory"); ZeroMemory(data, sizeof(NHTextWindow)); SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data); + + mswin_apply_window_style(ret); + return ret; } @@ -239,20 +233,35 @@ LayoutText(HWND hWnd) /* get window coordinates */ GetClientRect(hWnd, &clrt); - /* set window placements */ - GetWindowRect(btn_ok, &rt); - sz_ok.cx = clrt.right - clrt.left; - sz_ok.cy = rt.bottom - rt.top; - pt_ok.x = clrt.left; - pt_ok.y = clrt.bottom - sz_ok.cy; + if( !GetNHApp()->regNetHackMode ) { + /* set window placements */ + GetWindowRect(btn_ok, &rt); + sz_ok.cx = clrt.right - clrt.left; + sz_ok.cy = rt.bottom - rt.top; + pt_ok.x = clrt.left; + pt_ok.y = clrt.bottom - sz_ok.cy; + + pt_elem.x = clrt.left; + pt_elem.y = clrt.top; + sz_elem.cx = clrt.right - clrt.left; + sz_elem.cy = pt_ok.y; + + MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE); + MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE); + } else { + sz_ok.cx = sz_ok.cy = 0; + + pt_ok.x = pt_ok.y = 0; + pt_elem.x = clrt.left; + pt_elem.y = clrt.top; - pt_elem.x = clrt.left; - pt_elem.y = clrt.top; - sz_elem.cx = clrt.right - clrt.left; - sz_elem.cy = pt_ok.y; + sz_elem.cx = clrt.right - clrt.left; + sz_elem.cy = clrt.bottom - clrt.top; - MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE); - MoveWindow(btn_ok, pt_ok.x, pt_ok.y, sz_ok.cx, sz_ok.cy, TRUE); + ShowWindow(btn_ok, SW_HIDE); + MoveWindow(text, pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE ); + } + mswin_apply_window_style(text); } /* Edit box hook */ diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 073cd1501..e386ee50e 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -210,7 +210,7 @@ mswin_init_nhwindows(int *argc, char **argv) */ iflags.toptenwin = 1; set_option_mod_status("toptenwin", SET_IN_FILE); - set_option_mod_status("perm_invent", SET_IN_FILE); + //set_option_mod_status("perm_invent", SET_IN_FILE); /* initialize map tiles bitmap */ initMapTiles(); @@ -2279,7 +2279,7 @@ mswin_read_reg() is read from the registry, so these defaults apply. */ GetNHApp()->saveRegistrySettings = 1; /* Normally, we always save */ - GetNHApp()->regNetHackMode = 0; + GetNHApp()->regNetHackMode = TRUE; if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key) != ERROR_SUCCESS) diff --git a/win/win32/winMS.h b/win/win32/winMS.h index e2720fccc..7938d83d1 100644 --- a/win/win32/winMS.h +++ b/win/win32/winMS.h @@ -201,6 +201,7 @@ void mswin_write_reg(void); void mswin_get_window_placement(int type, LPRECT rt); void mswin_update_window_placement(int type, LPRECT rt); +void mswin_apply_window_style(HWND hwnd); int NHMessageBox(HWND hWnd, LPCTSTR text, UINT type); diff --git a/win/win32/winhack.rc b/win/win32/winhack.rc index 44a5de42e..fbe856b42 100644 --- a/win/win32/winhack.rc +++ b/win/win32/winhack.rc @@ -135,9 +135,9 @@ STYLE WS_CHILD | WS_CLIPSIBLINGS | WS_THICKFRAME EXSTYLE WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT FONT 8, "MS Sans Serif", 0, 0 BEGIN - LISTBOX IDC_MENU_LIST,10,10,170,55,LBS_SORT + LISTBOX IDC_MENU_LIST,10,10,170,55,LBS_SORT | NOT WS_BORDER EDITTEXT IDC_MENU_TEXT,10,70,170,60,ES_MULTILINE | ES_OEMCONVERT | - ES_READONLY | WS_VSCROLL | WS_HSCROLL | NOT WS_TABSTOP + ES_READONLY | WS_VSCROLL | WS_HSCROLL | NOT WS_TABSTOP | NOT WS_BORDER DEFPUSHBUTTON "OK",IDOK,7,132,50,14,BS_FLAT | NOT WS_TABSTOP PUSHBUTTON "Cancel",IDCANCEL,130,132,50,14,BS_FLAT | NOT WS_TABSTOP END -- 2.40.0