From 71eb636e14d223dd4338c70edcdc7d00d0ee342c Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Wed, 28 Aug 2002 04:53:50 +0000 Subject: [PATCH] win32 (from ) 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. --- win/win32/mhmain.c | 2 +- win/win32/mhmenu.c | 38 +----------------- win/win32/mhtext.c | 21 +--------- win/win32/mswproc.c | 91 ++++++++++++++++++++++++++++++++++++++++---- win/win32/winMS.h | 3 ++ win/win32/winhack.rc | 4 +- 6 files changed, 93 insertions(+), 66 deletions(-) diff --git a/win/win32/mhmain.c b/win/win32/mhmain.c index 6f0d04007..76ffa581e 100644 --- a/win/win32/mhmain.c +++ b/win/win32/mhmain.c @@ -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, diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index b56264562..94fc0cb09 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -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; } diff --git a/win/win32/mhtext.c b/win/win32/mhtext.c index 0119918b9..3d541d5f3 100644 --- a/win/win32/mhtext.c +++ b/win/win32/mhtext.c @@ -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) diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index e14633468..7a49ba57d 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -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; ihMainWnd ); + + /* 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; ihMainWnd ); + + 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 diff --git a/win/win32/winMS.h b/win/win32/winMS.h index 0e685dc34..b424799ca 100644 --- a/win/win32/winMS.h +++ b/win/win32/winMS.h @@ -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); diff --git a/win/win32/winhack.rc b/win/win32/winhack.rc index cf47cb4dd..1daa8546f 100644 --- a/win/win32/winhack.rc +++ b/win/win32/winhack.rc @@ -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 -- 2.50.1