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>
TRUE );
break;
+ case NHW_TEXT: // same as the map window
case NHW_MAP:
MoveWindow(GetNHApp()->windowlist[i].win,
map_org.x,
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,
/*-----------------------------------------------------------------------------*/
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;
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 ) {
}
}
- /* 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;
}
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 ) {
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)
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);
}
}
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>
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);
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
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