]> granicus.if.org Git - nethack/commitdiff
Fixes:
authornethack.allison <nethack.allison>
Sun, 27 Jan 2002 23:28:02 +0000 (23:28 +0000)
committernethack.allison <nethack.allison>
Sun, 27 Jan 2002 23:28:02 +0000 (23:28 +0000)
- B1026  [confirmed] win32: setting multiple options
- bugfix: menu: set focus to the item and make it visible when it is
selected  with accelerator key.
- increased menu font size by 1 point
- layout the main window on WM_MOVE message so the menu windows stays with
the main window  (it was not changing the location before)
- got rid of WinCE specific define (ARM)
- handle all keyboard input via WM_KEYDOWN instead WM_CHAR

Files affected: config1.h mhmsg.h mhmain.c mhmenu.c mswproc.c resource.h
winhack.rc

Notes:
 That overrides Yitzhak's mhmenu patch - I don't like the menu prompt on the
title bar since it can be null and in most cases it is. It looks much better
as a header column in the list and is displayed only if present.

I moved ARM-related (processor) defines to wceconf.h  You cannot undef ARM
before windows.h is processed - ARM version won't compile.

.rc files are generated by IDE - you cannot edit them directly or your
changes will be gone next time the file is saved. If anything needs to be
added to winhack.rc file manually it has to be marked by the following
defines or via menu option View->Resource Includes:
#define APSTUDIO_READONLY_SYMBOLS
...
#undef APSTUDIO_READONLY_SYMBOLS

include/config1.h
win/win32/mhfont.c
win/win32/mhmain.c
win/win32/mhmap.c
win/win32/mhmenu.c
win/win32/mhmsg.h
win/win32/mswproc.c
win/win32/winhack.rc

index 2f485b2019565991db05ba8be719d0a06c13192b..167c811eea95470f52d49a99fe95a50fa4d5faf2 100644 (file)
 # define USE_STDARG
 # define NEED_VARARGS
 
-/* ARM - the processor; avoids conflict with ARM in hack.h */
-# ifdef ARM
-# undef ARM
-# endif
 #endif
 
 
index 0755e64443d7935406621471fdc4219dca68d781..3d0c77902c1f4ba9da205bcb067fd97a7c581166 100644 (file)
@@ -54,7 +54,7 @@ HGDIOBJ mswin_create_font(int win_type, int attr, HDC hdc)
                break;
 
        case NHW_MENU:
-               font_size = (attr==ATR_INVERSE)? 7 : 7;
+               font_size = (attr==ATR_INVERSE)? 8 : 8;
                lgfnt.lfHeight                  =       -font_size*GetDeviceCaps(hdc, LOGPIXELSY)/72;    // height of font
                lgfnt.lfWidth                   =       0;                                   // average character width
                lgfnt.lfEscapement              =       0;                                       // angle of escapement
index 48d282926f69298e62e4c9a5693b168303433b04..c6e904480bacab71eede1664e3007b0661a75c19 100644 (file)
@@ -79,7 +79,7 @@ void register_main_window_class()
 
        RegisterClass(&wcex);
 }
-    
+
 /*
  * Keypad keys are translated to the normal values below.
  * Shifted keypad keys are translated to the
@@ -87,55 +87,56 @@ void register_main_window_class()
  */
 
 enum KEY_INDEXES {
-       KEY_NW, KEY_N, KEY_NE, KEY_MINUS,
-       KEY_W, KEY_STAY, KEY_E, KEY_PLUS,
-       KEY_SW, KEY_S, KEY_SE,
-       KEY_INV, KEY_WAITLOOK,
-       KEY_LAST};
-
-       static const unsigned char
-       /* normal, shift, control */
- keypad[KEY_LAST][3] = {
-                       {'y', 'Y', C('y')},             /* 7 */
-                       {'k', 'K', C('k')},             /* 8 */
-                       {'u', 'U', C('u')},             /* 9 */
-                       {'m', C('p'), C('p')},  /* - */
-                       {'h', 'H', C('h')},             /* 4 */
-                       {'g', 'g', 'g'},                /* 5 */
-                       {'l', 'L', C('l')},             /* 6 */
-                       {'p', 'P', C('p')},             /* + */
-                       {'b', 'B', C('b')},             /* 1 */
-                       {'j', 'J', C('j')},             /* 2 */
-                       {'n', 'N', C('n')},             /* 3 */
-                       {'i', 'I', C('i')},             /* Ins */
-                       {'.', ':', ':'}                 /* Del */
-}, numpad[KEY_LAST][3] = {
-                       {'7', M('7'), '7'},             /* 7 */
-                       {'8', M('8'), '8'},             /* 8 */
-                       {'9', M('9'), '9'},             /* 9 */
-                       {'m', C('p'), C('p')},  /* - */
-                       {'4', M('4'), '4'},             /* 4 */
-                       {'g', 'G', 'g'},                /* 5 */
-                       {'6', M('6'), '6'},             /* 6 */
-                       {'p', 'P', C('p')},             /* + */
-                       {'1', M('1'), '1'},             /* 1 */
-                       {'2', M('2'), '2'},             /* 2 */
-                       {'3', M('3'), '3'},             /* 3 */
-                       {'i', 'I', C('i')},             /* Ins */
-                       {'.', ':', ':'}                 /* Del */
+KEY_NW, KEY_N, KEY_NE, KEY_MINUS,
+KEY_W, KEY_STAY, KEY_E, KEY_PLUS,
+KEY_SW, KEY_S, KEY_SE,
+KEY_INV, KEY_WAITLOOK,
+KEY_LAST};
+
+static const unsigned char
+/* normal, shift, control */
+keypad[KEY_LAST][3] = {
+       {'y', 'Y', C('y')}, /* 7 */
+       {'k', 'K', C('k')}, /* 8 */
+       {'u', 'U', C('u')}, /* 9 */
+       {'m', C('p'), C('p')}, /* - */
+       {'h', 'H', C('h')}, /* 4 */
+       {'g', 'g', 'g'}, /* 5 */
+       {'l', 'L', C('l')}, /* 6 */
+       {'p', 'P', C('p')}, /* + */
+       {'b', 'B', C('b')}, /* 1 */
+       {'j', 'J', C('j')}, /* 2 */
+       {'n', 'N', C('n')}, /* 3 */
+       {'i', 'I', C('i')}, /* Ins */
+       {'.', ':', ':'} /* Del */
+}, 
+numpad[KEY_LAST][3] = {
+       {'7', M('7'), '7'}, /* 7 */
+       {'8', M('8'), '8'}, /* 8 */
+       {'9', M('9'), '9'}, /* 9 */
+       {'m', C('p'), C('p')}, /* - */
+       {'4', M('4'), '4'}, /* 4 */
+       {'g', 'G', 'g'}, /* 5 */
+       {'6', M('6'), '6'}, /* 6 */
+       {'p', 'P', C('p')}, /* + */
+       {'1', M('1'), '1'}, /* 1 */
+       {'2', M('2'), '2'}, /* 2 */
+       {'3', M('3'), '3'}, /* 3 */
+       {'i', 'I', C('i')}, /* Ins */
+       {'.', ':', ':'} /* Del */
 };
 
 
 #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)])
-
+[(STATEON(VK_SHIFT) ? 1 : STATEON(VK_CONTROL) ? 2 : 0)])
+  
+    
 /*
 //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
 //
 //  PURPOSE:  Processes messages for the main window.
 */
-
 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
        PNHMainWindow data;
@@ -161,64 +162,74 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
                        /* translate arrow keys into nethack commands */
             switch (wParam) 
             { 
-            case VK_LEFT: 
+                       case VK_LEFT:
                                NHEVENT_KBD(KEYTABLE(KEY_W));
-                return 0; 
+                       return 0;
 
-            case VK_RIGHT: 
+                       case VK_RIGHT:
                                NHEVENT_KBD(KEYTABLE(KEY_E));
-                return 0; 
+                       return 0;
 
-            case VK_UP: 
+                       case VK_UP:
                                NHEVENT_KBD(KEYTABLE(KEY_N));
-                return 0; 
+                       return 0;
 
-            case VK_DOWN: 
+                       case VK_DOWN:
                                NHEVENT_KBD(KEYTABLE(KEY_S));
-                return 0; 
+                       return 0;
 
-            case VK_HOME: 
+                       case VK_HOME:
                                NHEVENT_KBD(KEYTABLE(KEY_NW));
-                return 0; 
+                       return 0;
 
-            case VK_END: 
+                       case VK_END:
                                NHEVENT_KBD(KEYTABLE(KEY_SW));
-                return 0; 
+                       return 0;
 
-            case VK_PRIOR: 
+                       case VK_PRIOR:
                                NHEVENT_KBD(KEYTABLE(KEY_NE));
-                return 0; 
+                       return 0;
 
-            case VK_NEXT: 
+                       case VK_NEXT:
                                NHEVENT_KBD(KEYTABLE(KEY_SE));
-                return 0; 
+                       return 0;
 
                        case VK_DECIMAL:
-            case VK_DELETE: 
+                       case VK_DELETE:
                                NHEVENT_KBD(KEYTABLE(KEY_WAITLOOK));
-                return 0; 
+                       return 0;
 
                        case VK_INSERT:
                        case VK_NUMPAD0:
                                NHEVENT_KBD(KEYTABLE(KEY_INV));
-                               return 0;
+                       return 0;
 
                        case VK_SUBTRACT:
-                               return 0;
                                NHEVENT_KBD(KEYTABLE(KEY_MINUS));
+                       return 0;
 
                        case VK_ADD:
-                               return 0;
                                NHEVENT_KBD(KEYTABLE(KEY_PLUS));
-            }
-                       return 1;
+                       return 0;
+
+                       default: {
+                               WORD c[4];
+                               BYTE kbd_state[256];
+                               
+                               ZeroMemory(kbd_state, sizeof(kbd_state));
+                               ZeroMemory(c, sizeof(c));
+                               GetKeyboardState(kbd_state);
+                               
+                               if( ToAscii( LOWORD(wParam), 0, kbd_state, c, 0)==1 ) {
+                                       NHEVENT_KBD(c[0]);
+                                       return 0;
+                               } else {
+                                       return 1;
+                               }
+                       } 
+                       }
                } break;
 
-               case WM_CHAR:
-                       /* all characters go to nethack */
-                       NHEVENT_KBD(wParam);
-               return 0;
-
                case WM_COMMAND:
                        /* process commands - menu commands mostly */
                        if( onWMCommand(hWnd, wParam, lParam) )
@@ -226,6 +237,7 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
                        else
                                return 0;
 
+               case WM_MOVE:
                case WM_SIZE:
                        mswin_layout_main_window(NULL);
                        break;
index 29e8e71faf8dc9a68325442ae42841cd54db1301..15d1684433b5200c4025e922a5e9fe6b3633301a 100644 (file)
@@ -815,7 +815,7 @@ void nhglyph2charcolor(short g, uchar* ch, int* color)
 COLORREF nhcolor_to_RGB(int c)
 {
        switch(c) {
-       case CLR_BLACK:                 return RGB(85, 85, 85);
+       case CLR_BLACK:                 return RGB( 85,  85,   85);             
        case CLR_RED:                   return RGB(255,   0,   0);              
        case CLR_GREEN:                 return RGB(  0, 128,   0);              
        case CLR_BROWN:                 return RGB(165,  42,   42);
index b8cf502fb39256afbb838f7c1549929093e754c3..de15457110547334d9c9e6cdd4f993a048861a1f 100644 (file)
@@ -7,7 +7,6 @@
 #include "mhmain.h"
 #include "mhmsg.h"
 #include "mhfont.h"
-#include <commctrl.h>
 
 #define MENU_MARGIN                    0
 #define NHMENU_STR_SIZE     BUFSZ
@@ -35,6 +34,7 @@ typedef struct mswin_nethack_menu_window {
                        PNHMenuItem              items;                 /* menu items */
                        char                     gacc[QBUFSZ];  /* group accelerators */
                        BOOL                     counting;              /* counting flag */
+                       char                     prompt[QBUFSZ]; /* menu prompt */
                } menu;
 
                struct menu_text {
@@ -468,6 +468,17 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
 
                data->menu.size++;
        } break;
+
+       case MSNH_MSG_ENDMENU:
+       {
+               PMSNHMsgEndMenu msg_data = (PMSNHMsgEndMenu)lParam;
+               if( msg_data->text ) {
+                       strncpy( data->menu.prompt, msg_data->text, sizeof(data->menu.prompt)-1 );
+               } else {
+                       ZeroMemory(data->menu.prompt, sizeof(data->menu.prompt));
+               }
+       } break;
+
        }
 }
 
@@ -558,22 +569,26 @@ void SetMenuListType(HWND hWnd, int how)
        switch(how) {
        case PICK_NONE: 
                dwStyles = WS_VISIBLE | WS_TABSTOP | WS_BORDER | WS_CHILD 
-                       | WS_VSCROLL | WS_HSCROLL | LVS_REPORT | LVS_NOCOLUMNHEADER 
+                       | 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 | WS_HSCROLL | LVS_REPORT | LVS_NOCOLUMNHEADER 
+                       | 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 | WS_HSCROLL | LVS_REPORT | LVS_NOCOLUMNHEADER 
+                       | WS_VSCROLL | WS_HSCROLL | LVS_REPORT  
                        | LVS_OWNERDRAWFIXED | LVS_SINGLESEL; 
                break;
        default: panic("how should be one of PICK_NONE, PICK_ONE or PICK_ANY");
        };
 
+       if( strlen(data->menu.prompt)==0 ) {
+               dwStyles |= LVS_NOCOLUMNHEADER ;
+       }
+
        GetWindowRect(GetDlgItem(hWnd, IDC_MENU_LIST), &rt);
        DestroyWindow(GetDlgItem(hWnd, IDC_MENU_LIST));
        control = CreateWindow(WC_LISTVIEW, NULL, 
@@ -598,8 +613,9 @@ void SetMenuListType(HWND hWnd, int how)
 
        /* add column to the list view */
        ZeroMemory(&lvcol, sizeof(lvcol));
-       lvcol.mask = LVCF_WIDTH;
-       lvcol.cx = 1024;
+       lvcol.mask = LVCF_WIDTH | LVCF_TEXT;
+       lvcol.cx = GetSystemMetrics(SM_CXFULLSCREEN);
+       lvcol.pszText = NH_A2W(data->menu.prompt, wbuf, BUFSZ);
        ListView_InsertColumn(control, 0, &lvcol);
 
        /* add items to the list view */
@@ -926,6 +942,8 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch)
                                                        i, 
                                                        -1
                                                );
+                                               ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED);
+                                               ListView_EnsureVisible(hwndList, i, FALSE);
                                                break;
                                        }
                                }
@@ -1021,6 +1039,7 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch)
                                                                NHMENU_IS_SELECTED(data->menu.items[i])? 0 : -1
                                                        );
                                                        ListView_SetItemState(hwndList, i, LVIS_FOCUSED, LVIS_FOCUSED);
+                                                       ListView_EnsureVisible(hwndList, i, FALSE);
                                                        return -2;
                                                } else if( data->how == PICK_ONE ) {
                                                        SelectMenuItem(
@@ -1060,7 +1079,7 @@ void mswin_menu_window_size (HWND hWnd, LPSIZE sz)
        data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);
        if(data && data->type==MENU_TYPE_MENU ) {
                hdc = GetDC(GetMenuControl(hWnd));
-               saveFont = SelectObject(hdc, mswin_create_font(NHW_MENU, ATR_INVERSE, hdc));
+               saveFont = SelectObject(hdc, mswin_create_font(NHW_MENU, ATR_NONE, hdc));
                GetTextMetrics(hdc, &tm);
 
                /* Set the height of the list box items. */
index 0cc94114f993ff7d3b277356e7197af3f8362f5b..135e8d9422f0e7dccc1bbaf09537fcfff5ef8e5f 100644 (file)
@@ -15,6 +15,7 @@
 #define MSNH_MSG_STARTMENU             105
 #define MSNH_MSG_ADDMENU               106
 #define MSNH_MSG_CURSOR                        107
+#define MSNH_MSG_ENDMENU               108
 
 typedef struct mswin_nhmsg_add_wnd {
   winid                  wid;
@@ -51,4 +52,8 @@ typedef struct mswin_nhmsg_cursor {
   int                  y;
 } MSNHMsgCursor, *PMSNHMsgCursor;
 
+typedef struct mswin_nhmsg_end_menu {
+       const char* text;
+} MSNHMsgEndMenu, *PMSNHMsgEndMenu;
+
 #endif
index b94ddf17902d42ed69be9de437a808bb7767af07..d641951d687d1132129cb6fa5b596b5277e8702f 100644 (file)
@@ -580,15 +580,18 @@ end_menu(window, prompt)
 */
 void mswin_end_menu(winid wid, const char *prompt)
 {
-       TCHAR wbuf[255];
        logDebug("mswin_end_menu(%d, %s)\n", wid, prompt);
-       if ((wid >= 0) &&
+       if ((wid >= 0) && 
                (wid < MAXWINDOWS) &&
                (GetNHApp()->windowlist[wid].win != NULL))
        {
-               SetWindowText (
-                        GetNHApp()->windowlist[wid].win,
-                        NH_A2W(prompt, wbuf ,sizeof(wbuf))
+               MSNHMsgEndMenu data;
+               ZeroMemory(&data, sizeof(data));
+               data.text = prompt;
+
+               SendMessage( 
+                        GetNHApp()->windowlist[wid].win, 
+                        WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_ENDMENU, (LPARAM)&data
                );
        }
 }
index ee7e2e7eeea49b45343cda90122e9b4b6d189237..af8d91db76d7ab5418b75bbe7cdcef7eb0be2455 100644 (file)
@@ -1,9 +1,5 @@
 //Microsoft Developer Studio generated resource script.
 //
-#if defined(__BORLANDC__)
-LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US
-#endif
-
 #include "resource.h"
 
 #define APSTUDIO_READONLY_SYMBOLS
@@ -11,6 +7,9 @@ LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US
 //
 // Generated from the TEXTINCLUDE 2 resource.
 //
+#if defined(__BORLANDC__)
+LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US
+#endif
 #define APSTUDIO_HIDDEN_SYMBOLS
 #include "windows.h"
 #undef APSTUDIO_HIDDEN_SYMBOLS
@@ -42,7 +41,7 @@ IDI_NETHACKW            ICON    DISCARDABLE     "NETHACK.ICO"
 // Menu
 //
 
-IDC_NETHACKW MENU DISCARDABLE
+IDC_NETHACKW MENU DISCARDABLE 
 BEGIN
     POPUP "&File"
     BEGIN
@@ -85,7 +84,7 @@ END
 // Accelerator
 //
 
-IDC_NETHACKW ACCELERATORS MOVEABLE PURE
+IDC_NETHACKW ACCELERATORS MOVEABLE PURE 
 BEGIN
     "?",            IDM_ABOUT,              ASCII,  ALT
     "/",            IDM_ABOUT,              ASCII,  ALT
@@ -110,7 +109,7 @@ END
 IDD_NHTEXT DIALOGEX 0, 0, 172, 178
 STYLE DS_SETFOREGROUND | WS_POPUP | WS_THICKFRAME
 EXSTYLE WS_EX_STATICEDGE
-FONT 8, "MS Sans Serif"
+FONT 8, "MS Sans Serif", 0, 0, 0x1
 BEGIN
     DEFPUSHBUTTON   "OK",IDOK,54,163,50,14
     EDITTEXT        IDC_TEXT_CONTROL,0,0,170,160,ES_MULTILINE | 
@@ -118,12 +117,9 @@ BEGIN
 END
 
 IDD_MENU DIALOGEX 0, 0, 187, 153
-STYLE WS_POPUP | WS_CLIPSIBLINGS | WS_THICKFRAME | WS_CAPTION
+STYLE WS_POPUP | WS_CLIPSIBLINGS | WS_THICKFRAME
 EXSTYLE WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT | WS_EX_STATICEDGE
 FONT 8, "MS Sans Serif"
-#ifndef __BORLANDC__
-       , 0, 0, 0x1
-#endif
 BEGIN
     DEFPUSHBUTTON   "OK",IDOK,7,132,50,14,BS_FLAT
     PUSHBUTTON      "Cancel",IDCANCEL,130,132,50,14,BS_FLAT
@@ -193,6 +189,9 @@ END
 
 2 TEXTINCLUDE DISCARDABLE 
 BEGIN
+    "#if defined(__BORLANDC__)\r\n"
+    "LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US\r\n"
+    "#endif\r\n"
     "#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
     "#include ""windows.h""\r\n"
     "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"