]> granicus.if.org Git - nethack/commitdiff
win32 (from <Someone>)
authornethack.allison <nethack.allison>
Wed, 28 Aug 2002 04:53:50 +0000 (04:53 +0000)
committernethack.allison <nethack.allison>
Wed, 28 Aug 2002 04:53:50 +0000 (04:53 +0000)
This patch is an improvement for menu/text dialogs.
This is a code carried over from Windows CE port. It changes
text and menu windows from "system popup" to plain "child"
windows of the main nethack window. Nethack main window can
now be resized/moved/minimized when menu/text window is up.
Menu/text windows will always stay inside the main window and
move along with it.

<Someone>

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

index 6f0d04007fcb8186ef9fa5b9a625e00b44126756..76ffa581e90671ce46c6bd7b24ccaf87079a235e 100644 (file)
@@ -651,6 +651,7 @@ void mswin_layout_main_window(HWND changed_child)
                                                   TRUE );
                                break;
 
+                       case NHW_TEXT: // same as the map window
                        case NHW_MAP:
                                MoveWindow(GetNHApp()->windowlist[i].win, 
                                               map_org.x, 
@@ -675,7 +676,6 @@ void mswin_layout_main_window(HWND changed_child)
 
                                pt.x = map_org.x + max(0, (int)(map_size.cx-menu_size.cx));
                                pt.y = map_org.y;
-                               ClientToScreen(GetNHApp()->hMainWnd, &pt);
                                MoveWindow(GetNHApp()->windowlist[i].win, 
                                                   pt.x, 
                                                   pt.y,
index b562645629b9da36f0c243353fc76733325fb1ec..94fc0cb09d1b44dfe799d6908de41bfddf9f6b0c 100644 (file)
@@ -103,7 +103,6 @@ HWND mswin_init_menu_window (int type) {
 /*-----------------------------------------------------------------------------*/
 int mswin_menu_window_select_menu (HWND hWnd, int how, MENU_ITEM_P ** _selected)
 {
-       MSG msg;
        PNHMenuWindow data;
        int ret_val;
     MENU_ITEM_P *selected = NULL;
@@ -157,28 +156,7 @@ int mswin_menu_window_select_menu (HWND hWnd, int how, MENU_ITEM_P ** _selected)
                reset_menu_count(NULL, data);
        }
 
-       /* activate the menu window */
-       GetNHApp()->hPopupWnd = hWnd;
-
-       mswin_layout_main_window(hWnd);
-
-       /* disable game windows */
-       EnableWindow(mswin_hwnd_from_winid(WIN_MAP), FALSE);
-       EnableWindow(mswin_hwnd_from_winid(WIN_MESSAGE), FALSE);
-       EnableWindow(mswin_hwnd_from_winid(WIN_STATUS), FALSE);
-
-       /* bring menu window on top */
-       SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
-
-       /* go into message loop */
-       while( IsWindow(hWnd) && 
-                  !data->done &&
-                  GetMessage(&msg, NULL, 0, 0)!=0 ) {
-               if( !IsDialogMessage(hWnd, &msg) ) {
-                       TranslateMessage(&msg);
-                       DispatchMessage(&msg);
-               }
-       }
+       mswin_popup_display(hWnd, &data->done);
 
        /* get the result */
        if( data->result != -1 ) {
@@ -215,19 +193,7 @@ int mswin_menu_window_select_menu (HWND hWnd, int how, MENU_ITEM_P ** _selected)
                }
        }
 
-       /* restore window state */
-       EnableWindow(mswin_hwnd_from_winid(WIN_MAP), TRUE);
-       EnableWindow(mswin_hwnd_from_winid(WIN_MESSAGE), TRUE);
-       EnableWindow(mswin_hwnd_from_winid(WIN_STATUS), TRUE);
-
-       SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
-       GetNHApp()->hPopupWnd = NULL;
-       mswin_window_mark_dead( mswin_winid_from_handle(hWnd) );
-       DestroyWindow(hWnd);
-
-       mswin_layout_main_window(hWnd);
-
-       SetFocus(GetNHApp()->hMainWnd );
+       mswin_popup_destroy(hWnd);
 
        return ret_val;
 }
index 0119918b9616a97aff0a3b3b11696bf17ad6fbe6..3d541d5f36f9d9c440b0e8631c2c43527ed49c88 100644 (file)
@@ -44,10 +44,7 @@ HWND mswin_init_text_window () {
 
 void mswin_display_text_window (HWND hWnd)
 {
-       MSG msg;
-       RECT rt;
        PNHTextWindow data;
-       HWND mapWnd;
        
        data = (PNHTextWindow)GetWindowLong(hWnd, GWL_USERDATA);
        if( data && data->window_text ) {
@@ -57,22 +54,8 @@ void mswin_display_text_window (HWND hWnd)
                SetWindowText(GetDlgItem(hWnd, IDC_TEXT_CONTROL), data->window_text);
        }
 
-       GetNHApp()->hPopupWnd = hWnd;
-       mapWnd = mswin_hwnd_from_winid(WIN_MAP);
-       if( !IsWindow(mapWnd) ) mapWnd = GetNHApp()->hMainWnd;
-       GetWindowRect(mapWnd, &rt);
-       MoveWindow(hWnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
-       ShowWindow(hWnd, SW_SHOW);
-
-       while( IsWindow(hWnd) && 
-                  GetMessage(&msg, NULL, 0, 0)!=0 ) {
-               if( !IsDialogMessage(hWnd, &msg) ) {
-                       TranslateMessage(&msg);
-                       DispatchMessage(&msg);
-               }
-       }
-
-       GetNHApp()->hPopupWnd = NULL;
+       mswin_popup_display(hWnd, NULL);
+       mswin_popup_destroy(hWnd);
 }
     
 BOOL CALLBACK NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
index e146334684b8441d53df30b5101e17313d0a861f..7a49ba57ddff5289efdca867f712071b6aa5745c 100644 (file)
@@ -999,24 +999,21 @@ void mswin_display_file(const char *filename,BOOLEAN_P must_exist)
                        MessageBox(GetNHApp()->hMainWnd, message, TEXT("ERROR"), MB_OK | MB_ICONERROR );
                } 
        } else {
-               HWND hwnd;
+               winid text;
                char line[LLEN];
 
-               hwnd = mswin_init_text_window();
+               text = mswin_create_nhwindow(NHW_TEXT);
 
                while (dlb_fgets(line, LLEN, f)) {
-                        MSNHMsgPutstr data;
                         size_t len;
-
                         len = strlen(line);
                         if( line[len-1]=='\n' ) line[len-1]='\x0';
-                        data.attr = 0;
-                        data.text = line;
-                        SendMessage( hwnd, WM_MSNH_COMMAND, (WPARAM)MSNH_MSG_PUTSTR, (LPARAM)&data );
+                               mswin_putstr(text, ATR_NONE, line);
                }
                (void) dlb_fclose(f);
 
-               mswin_display_text_window(hwnd);
+               mswin_display_nhwindow(text, 1);
+               mswin_destroy_nhwindow(text);
        }
 }
 
@@ -1956,6 +1953,84 @@ BOOL initMapTiles(void)
        return TRUE;
 }
 
+void mswin_popup_display(HWND hWnd, int* done_indicator)
+{
+       MSG msg;
+       HWND hChild;
+       HMENU hMenu;
+       int mi_count;
+       int i;
+
+       /* activate the menu window */
+       GetNHApp()->hPopupWnd = hWnd;
+
+       mswin_layout_main_window(hWnd);
+
+       /* disable game windows */
+       for( hChild=GetWindow(GetNHApp()->hMainWnd, GW_CHILD);
+                hChild;
+                hChild = GetWindow(hChild, GW_HWNDNEXT) ) {
+               if( hChild!= hWnd) EnableWindow(hChild, FALSE);
+       }
+
+       /* disable menu */
+       hMenu = GetMenu( GetNHApp()->hMainWnd );
+       mi_count = GetMenuItemCount( hMenu );
+       for( i=0; i<mi_count; i++ ) {
+               EnableMenuItem(hMenu, i, MF_BYPOSITION | MF_GRAYED);
+       }
+       DrawMenuBar( GetNHApp()->hMainWnd );
+
+       /* bring menu window on top */
+       SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
+
+       /* go into message loop */
+       while( IsWindow(hWnd) && 
+                  (done_indicator==NULL || !*done_indicator) &&
+                  GetMessage(&msg, NULL, 0, 0)!=0 ) {
+               if( !IsDialogMessage(hWnd, &msg) ) {
+                       if (!TranslateAccelerator(msg.hwnd, GetNHApp()->hAccelTable, &msg)) {
+                               TranslateMessage(&msg);
+                               DispatchMessage(&msg);
+                       }
+               }
+       }
+}
+
+void mswin_popup_destroy(HWND hWnd)
+{
+       HWND hChild;
+       HMENU hMenu;
+       int mi_count;
+       int i;
+
+       /* enable game windows */
+       for( hChild=GetWindow(GetNHApp()->hMainWnd, GW_CHILD);
+                hChild;
+                hChild = GetWindow(hChild, GW_HWNDNEXT) ) {
+               if( hChild!= hWnd) {
+                       EnableWindow(hChild, TRUE);
+               }
+       }
+
+       /* enable menu */
+       hMenu = GetMenu( GetNHApp()->hMainWnd );
+       mi_count = GetMenuItemCount( hMenu );
+       for( i=0; i<mi_count; i++ ) {
+               EnableMenuItem(hMenu, i, MF_BYPOSITION | MF_ENABLED);
+       }
+       DrawMenuBar( GetNHApp()->hMainWnd );
+
+       SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
+       GetNHApp()->hPopupWnd = NULL;
+       mswin_window_mark_dead( mswin_winid_from_handle(hWnd) );
+       DestroyWindow(hWnd);
+
+       mswin_layout_main_window(hWnd);
+
+       SetFocus(GetNHApp()->hMainWnd );
+}
+
 #ifdef _DEBUG
 #include <stdarg.h>
 
index 0e685dc34deeba65330c6e7c6122450d2308f171..b424799cafbcbc7d5fd9feae9bd3f3e4b6fb6f9e 100644 (file)
@@ -144,6 +144,9 @@ void nhapply_image_transparent(
        COLORREF cTransparent
 );
 
+void mswin_popup_display(HWND popup, int* done_indicator);
+void mswin_popup_destroy(HWND popup);
+
 void mswin_read_reg(void);
 void mswin_destroy_reg(void);
 void mswin_write_reg(void);
index cf47cb4ddb78dd3384220d0b90e5489a1a37c443..1daa8546fc5f80a72e03b4f713247b576588549d 100644 (file)
@@ -115,7 +115,7 @@ BEGIN
 END
 
 IDD_NHTEXT DIALOGEX 0, 0, 172, 178
-STYLE DS_SETFOREGROUND | WS_POPUP | WS_THICKFRAME
+STYLE DS_SETFOREGROUND | WS_CHILD | WS_THICKFRAME
 EXSTYLE WS_EX_STATICEDGE
 FONT 8, "MS Sans Serif"
 BEGIN
@@ -125,7 +125,7 @@ BEGIN
 END
 
 IDD_MENU DIALOGEX 0, 0, 187, 153
-STYLE WS_POPUP | WS_CLIPSIBLINGS | WS_THICKFRAME
+STYLE WS_CHILD | WS_CLIPSIBLINGS | WS_THICKFRAME
 EXSTYLE WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT | WS_EX_STATICEDGE
 FONT 8, "MS Sans Serif"
 BEGIN