]> granicus.if.org Git - nethack/commitdiff
(from <Someone>)
authornethack.allison <nethack.allison>
Fri, 8 Mar 2002 22:23:04 +0000 (22:23 +0000)
committernethack.allison <nethack.allison>
Fri, 8 Mar 2002 22:23:04 +0000 (22:23 +0000)
This patch implements Michael's idea to have a "NetHack mode" for
keypresses. It only does the Alt-keys now, but it should be easy
to extend to pressing space in dialogs; I left that out as we still
have to agree on a new dialog look.

The setting that you choose from the menu is stored in the registry.
Reading and writing the registry is done on init_nhwindows and
exit_nhwindows; there also is a menu item to delete the registry
settings (which makes sure they are not stored again this session.)
This provides a framework for future registry settings.

Also,
Alt-tab should show the app title when a menu or text window is up.

I left the app title as it was, although I still favour "Graphical
Version" or "With Graphics"; Anyway, that's only one resource string.

win/win32/mhmain.c
win/win32/mhmain.h
win/win32/mhmenu.c
win/win32/mhtext.c
win/win32/mswproc.c
win/win32/resource.h
win/win32/winMS.h
win/win32/winhack.rc

index 4bdc18db593a15cd5b89b040d90439b9424a71ef..7164dc427310f3b9a6c037b1950944443fec2a44 100644 (file)
@@ -12,8 +12,6 @@
 #include "mhmsgwnd.h"
 #include "mhmap.h"
 
-#define MAX_LOADSTRING 100
-
 typedef struct mswin_nethack_main_window {
        int mapAcsiiModeSave;
 } NHMainWindow, *PNHMainWindow;
@@ -125,9 +123,6 @@ numpad[KEY_LAST][3] = {
        {'.', ':', ':'} /* Del */
 };
 
-static const unsigned char alt_commands[] = "acdeijlnNopqrstuvw?2";
-/* original: "acdefijlmnNopqrstuvw?2"; */ 
-
 #define STATEON(x) ((GetKeyState(x) & 0xFFFE) != 0)
 #define KEYTABLE(x) ((iflags.num_pad ? numpad : keypad)[x] \
 [(STATEON(VK_SHIFT) ? 1 : STATEON(VK_CONTROL) ? 2 : 0)])
@@ -366,24 +361,21 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
                        } /* end switch */
                } break;
 
-        case WM_SYSKEYDOWN:
-               {
-                       /* see if this is something we need */
-                       WORD c;
-                       BYTE kbd_state[256];
-
-                       c = 0;
-                       ZeroMemory(kbd_state, sizeof(kbd_state));
-                       GetKeyboardState(kbd_state);
-
-                       if( ToAscii( wParam, (lParam>>16)&0xFF, kbd_state, &c, 0) &&
-                               index(alt_commands, c&0xFF) ) {
-                               NHEVENT_KBD( M(c&0xFF) );
+        case WM_SYSCHAR: /* Alt-char pressed */
+        {
+            /*
+              If not nethackmode, don't handle Alt-keys here.
+              If no Alt-key pressed it can never be an extended command 
+            */
+            if (GetNHApp()->regNetHackMode && (lParam & 1<<29))
+            {
+                unsigned char c = (unsigned char)(wParam & 0xFF);
+                               NHEVENT_KBD(M(c));
                                return 0;
-                       } else {
-                               return DefWindowProc(hWnd, message, wParam, lParam);
-                       }
-               } break;
+            }
+            return DefWindowProc(hWnd, message, wParam, lParam);
+        } 
+        break;
 
                case WM_COMMAND:
                        /* process commands - menu commands mostly */
@@ -687,6 +679,21 @@ LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
                        }
                        break;
 
+        case IDM_NHMODE:
+        {
+            GetNHApp()->regNetHackMode = GetNHApp()->regNetHackMode ? 0 : 1;
+            mswin_menu_check_intf_mode();
+            break;
+        }
+        case IDM_CLEARSETTINGS:
+        {
+            mswin_destroy_reg();
+            /* Notify the user that windows settings will not be saved this time. */
+            MessageBox(GetNHApp()->hMainWnd, 
+                "Your Windows Settings will not be stored when you exit this time.", 
+                "NetHack", MB_OK | MB_ICONINFORMATION);
+            break;
+        }
                case IDM_HELP_LONG:     
                        display_file(HELP, TRUE);  
                        break;
@@ -783,6 +790,17 @@ LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     return FALSE;
 }
 
+void mswin_menu_check_intf_mode()
+{
+    HMENU hMenu = GetMenu(GetNHApp()->hMainWnd);
+
+    if (GetNHApp()->regNetHackMode)
+        CheckMenuItem(hMenu, IDM_NHMODE, MF_CHECKED);
+    else
+        CheckMenuItem(hMenu, IDM_NHMODE, MF_UNCHECKED);
+
+}
+
 void mswin_select_map_mode(int mode)
 {
        PNHMainWindow  data;
index efcebfd6c37990c5b2f0b7cca5269f43b1f5bfe3..276a7ff4980929977bd9bbebddeda3d716fe6e63 100644 (file)
@@ -11,5 +11,6 @@
 HWND mswin_init_main_window (void);
 void mswin_layout_main_window(HWND changed_child);
 void mswin_select_map_mode(int map_mode);
+void mswin_menu_check_intf_mode();
 
 #endif /* MSWINMainWindow_h */
index 21f916ea8b11073c1a5689278e36bd193719b152..23c8ee6d36910fd3eeac3a49f75e63a45e2b27ee 100644 (file)
@@ -229,6 +229,8 @@ BOOL CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
        PNHMenuWindow data;
        HWND control;
        HDC  hdc;
+    TCHAR title[MAX_LOADSTRING];
+
 
        data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);
        switch (message) 
@@ -254,6 +256,11 @@ BOOL CALLBACK MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                /* subclass edit control */
                editControlWndProc = (WNDPROC)GetWindowLong(control, GWL_WNDPROC);
                SetWindowLong(control, GWL_WNDPROC, (LONG)NHMenuTextWndProc);
+
+        /* Even though the dialog has no caption, you can still set the title 
+           which shows on Alt-Tab */
+        LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING);
+        SetWindowText(hWnd, title);
        break;
 
        case WM_MSNH_COMMAND:
index 0ca9b72e1d097fb79345bdc6c1ced151d518b831..d14bc2fff6fe9c42dbac67347740720ba1aab831 100644 (file)
@@ -80,6 +80,7 @@ BOOL CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
        HWND control;
        HDC hdc;
        PNHTextWindow data;
+    TCHAR title[MAX_LOADSTRING];
        
        data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA);
        switch (message) 
@@ -100,6 +101,11 @@ BOOL CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
                SetWindowLong(control, GWL_WNDPROC, (LONG)NHEditHookWndProc);
 
                SetFocus(control);
+
+        /* Even though the dialog has no caption, you can still set the title 
+           which shows on Alt-Tab */
+        LoadString(GetNHApp()->hApp, IDS_APP_TITLE, title, MAX_LOADSTRING);
+        SetWindowText(hWnd, title);
        return FALSE;
 
        case WM_MSNH_COMMAND:
index 1b58e3248025c048e9aa7d7dd683b0895e70ffd3..eac6485f95c3e6a1587a286013f10e95a79e68e8 100644 (file)
@@ -123,7 +123,13 @@ void mswin_init_nhwindows(int* argc, char** argv)
 #endif
     mswin_nh_input_init();
 
-       /* check default values */
+
+    /* Read Windows settings from the reqistry */
+    mswin_read_reg();
+    /* Set menu check mark for interface mode */
+    mswin_menu_check_intf_mode();
+
+    /* check default values */
        if( iflags.wc_fontsiz_status<NHFONT_SIZE_MIN || 
                iflags.wc_fontsiz_status>NHFONT_SIZE_MAX )
                iflags.wc_fontsiz_status = NHFONT_DEFAULT_SIZE;
@@ -268,6 +274,8 @@ void mswin_get_nh_event(void)
 void mswin_exit_nhwindows(const char *str)
 {
        logDebug("mswin_exit_nhwindows(%s)\n", str);
+    /* Write Window settings to the registry */
+    mswin_write_reg();
 }
 
 /* Prepare the window to be suspended. */
@@ -1399,3 +1407,98 @@ logDebug(const char *fmt, ...)
 }
 
 #endif
+
+
+/* Reading and writing settings from the registry. */
+#define CATEGORYKEY "Software"
+#define COMPANYKEY  "NetHack"
+#define PRODUCTKEY  "NetHack 3.4.0"
+#define SETTINGSKEY     "Settings"
+
+/* #define all the subkeys here */
+#define INTFKEY "Interface"
+
+void
+mswin_read_reg()
+{
+    HKEY key;
+    DWORD size;
+    char keystring[MAX_PATH];
+
+    sprintf(keystring, "%s\\%s\\%s\\%s", 
+        CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY);
+
+    /* Set the defaults here. The very first time the app is started, nothing is 
+       read from the registry, so these defaults apply. */
+    GetNHApp()->saveRegistrySettings = 1;   /* Normally, we always save */
+    GetNHApp()->regNetHackMode = 0;
+
+    if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key) 
+            != ERROR_SUCCESS)
+        return;
+
+    /* Read the keys here. */
+    size = sizeof(DWORD);
+    RegQueryValueEx(key, INTFKEY, 0, NULL, 
+        (unsigned char *)(&(GetNHApp()->regNetHackMode)), &size);
+    
+    RegCloseKey(key);
+}
+
+void
+mswin_write_reg()
+{
+    HKEY key;
+    DWORD disposition;
+
+    if (GetNHApp()->saveRegistrySettings)
+    {
+        char keystring[MAX_PATH];
+
+        sprintf(keystring, "%s\\%s\\%s\\%s", 
+            CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY);
+
+        if (RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_WRITE, &key) != ERROR_SUCCESS)
+        {
+            RegCreateKeyEx(HKEY_CURRENT_USER, keystring, 0, "",
+                REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, &disposition);
+        }
+
+        /* Write the keys here */
+        RegSetValueEx(key, INTFKEY, 0, REG_DWORD, (unsigned char *)(&(GetNHApp()->regNetHackMode)), sizeof(DWORD));
+
+        RegCloseKey(key);
+    }
+}
+
+void
+mswin_destroy_reg()
+{
+    char keystring[MAX_PATH];
+    HKEY key;
+    DWORD nrsubkeys;
+
+    /* Delete keys one by one, as NT does not delete trees */
+    sprintf(keystring, "%s\\%s\\%s\\%s", 
+        CATEGORYKEY, COMPANYKEY, PRODUCTKEY, SETTINGSKEY);
+    RegDeleteKey(HKEY_CURRENT_USER, keystring);
+    sprintf(keystring, "%s\\%s\\%s", 
+        CATEGORYKEY, COMPANYKEY, PRODUCTKEY);
+    RegDeleteKey(HKEY_CURRENT_USER, keystring);
+    /* The company key will also contain information about newer versions
+       of nethack (e.g. a subkey called NetHack 4.0), so only delete that
+       if it's empty now. */
+    sprintf(keystring, "%s\\%s", CATEGORYKEY, COMPANYKEY);
+    /* If we cannot open it, we probably cannot delete it either... Just
+       go on and see what happens. */
+    RegOpenKeyEx(HKEY_CURRENT_USER, keystring, 0, KEY_READ, &key); 
+    nrsubkeys = 0;
+    RegQueryInfoKey(key, NULL, NULL, NULL, &nrsubkeys, NULL, NULL, NULL, 
+        NULL, NULL, NULL, NULL);
+    RegCloseKey(key);
+    if (nrsubkeys == 0)
+        RegDeleteKey(HKEY_CURRENT_USER, keystring);
+
+    /* Prevent saving on exit */
+    GetNHApp()->saveRegistrySettings = 0;
+}
index 31bc6d0818fdb7fad38f6f59a32d9b9876c420b4..43e672b304bc6dc422686fee381550466457d270 100644 (file)
@@ -25,9 +25,9 @@
 #define IDB_PETMARK                     143
 #define IDB_MENU_SEL_COUNT              144
 #define IDD_NHRIP                       145
-#define IDB_SPLASH                     146
-#define IDB_RIP                                147
-#define IDD_SPLASH                     148
+#define IDB_SPLASH                      146
+#define IDB_RIP                         147
+#define IDD_SPLASH                      148
 #define IDC_TEXT_VIEW                   1000
 #define IDC_TEXT_CONTROL                1000
 #define IDC_CMD_MOVE_NW                 1001
 #define IDM_MAP_ASCII12X16              32789
 #define IDM_MAP_ASCII10X18              32790
 #define IDM_MAP_FIT_TO_SCREEN           32791
+#define IDM_NHMODE                      32793
+#define IDM_CLEARSETTINGS               32794
 #define IDC_STATIC                      -1
 
 // Next default values for new objects
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        145
-#define _APS_NEXT_COMMAND_VALUE         32793
+#define _APS_NEXT_COMMAND_VALUE         32795
 #define _APS_NEXT_CONTROL_VALUE         1331
 #define _APS_NEXT_SYMED_VALUE           110
 #endif
index abbde807a35c68a6b1cb3221d962ed1dc64566a2..63ac6c05c8e45f7173a93535a1128d5ee5eb7f23 100644 (file)
@@ -33,6 +33,8 @@
 #define NHFONT_SIZE_MIN 3
 #define NHFONT_SIZE_MAX 20
 
+#define MAX_LOADSTRING 100
+
 typedef struct mswin_nhwindow_data {
   HWND       win;
   int            type;
@@ -62,6 +64,9 @@ typedef struct mswin_nhwindow_app {
        int                     mapDisplayModeSave;     /* saved map display mode */
 
        char*           saved_text;
+
+    DWORD       saveRegistrySettings; /* Flag if we should save this time */
+    DWORD       regNetHackMode;   /* NetHack mode means no Windows keys in some places */
 } NHWinApp, *PNHWinApp;
 
 #define E extern
@@ -129,6 +134,10 @@ void nhapply_image_transparent(
        COLORREF cTransparent
 );
 
+void mswin_read_reg();
+void mswin_destroy_reg();
+void mswin_write_reg();
+
 /* unicode stuff */
 #ifdef UNICODE
        #define NH_W2A(w, a, cb)     ( WideCharToMultiByte(                              \
index dfd7b661b357098d3a6c59028b67e1eb2c707bb0..7a752d14951673f70b2e5ebf0d4092f80f4e184e 100644 (file)
@@ -64,6 +64,12 @@ BEGIN
         MENUITEM SEPARATOR
         MENUITEM "&Fit To Screen ",             IDM_MAP_FIT_TO_SCREEN
     END
+    POPUP "Windows &Settings"
+    BEGIN
+        MENUITEM "NetHack Mode",                IDM_NHMODE
+        MENUITEM SEPARATOR
+        MENUITEM "&Clear All Settings",         IDM_CLEARSETTINGS
+    END
     POPUP "&Help"
     BEGIN
         MENUITEM "&About ...",                  IDM_ABOUT
@@ -240,7 +246,7 @@ IDB_MENU_UNSEL          BITMAP  DISCARDABLE     "mnunsel.bmp"
 IDB_PETMARK             BITMAP  DISCARDABLE     "petmark.bmp"
 IDB_MENU_SEL_COUNT      BITMAP  DISCARDABLE     "mnselcnt.bmp"
 IDB_RIP                 BITMAP  DISCARDABLE     "rip.bmp"
-IDB_SPLASH                 BITMAP  DISCARDABLE     "splash.bmp"
+IDB_SPLASH              BITMAP  DISCARDABLE     "splash.bmp"
 
 /////////////////////////////////////////////////////////////////////////////
 //