From f51f117b00758246741af116a3f07a8b5e8e3a2d Mon Sep 17 00:00:00 2001 From: PeterN Date: Wed, 14 Jun 2023 17:24:14 +0100 Subject: [PATCH] Change: Add window description flag to disallow interactive window closing. (#11008) This replaces/simplifies testing for a closebox to allow closing a window with right-click, and testing for specific window classes when closing all windows by hotkey. This allows right-click closing of dropdowns and the high-score window. --- src/bootstrap_gui.cpp | 8 ++++---- src/intro_gui.cpp | 2 +- src/main_gui.cpp | 2 +- src/misc_gui.cpp | 2 +- src/statusbar_gui.cpp | 2 +- src/toolbar_gui.cpp | 4 ++-- src/window.cpp | 13 +++---------- src/window_gui.h | 1 + 8 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/bootstrap_gui.cpp b/src/bootstrap_gui.cpp index b8439a89e5..b77e72049b 100644 --- a/src/bootstrap_gui.cpp +++ b/src/bootstrap_gui.cpp @@ -42,7 +42,7 @@ static const struct NWidgetPart _background_widgets[] = { static WindowDesc _background_desc( WDP_MANUAL, nullptr, 0, 0, WC_BOOTSTRAP, WC_NONE, - 0, + WDF_NO_CLOSE, _background_widgets, lengthof(_background_widgets) ); @@ -80,7 +80,7 @@ static const NWidgetPart _nested_bootstrap_errmsg_widgets[] = { static WindowDesc _bootstrap_errmsg_desc( WDP_CENTER, nullptr, 0, 0, WC_BOOTSTRAP, WC_NONE, - WDF_MODAL, + WDF_MODAL | WDF_NO_CLOSE, _nested_bootstrap_errmsg_widgets, lengthof(_nested_bootstrap_errmsg_widgets) ); @@ -137,7 +137,7 @@ static const NWidgetPart _nested_bootstrap_download_status_window_widgets[] = { static WindowDesc _bootstrap_download_status_window_desc( WDP_CENTER, nullptr, 0, 0, WC_NETWORK_STATUS_WINDOW, WC_NONE, - WDF_MODAL, + WDF_MODAL | WDF_NO_CLOSE, _nested_bootstrap_download_status_window_widgets, lengthof(_nested_bootstrap_download_status_window_widgets) ); @@ -191,7 +191,7 @@ static const NWidgetPart _bootstrap_query_widgets[] = { static WindowDesc _bootstrap_query_desc( WDP_CENTER, nullptr, 0, 0, WC_CONFIRM_POPUP_QUERY, WC_NONE, - 0, + WDF_NO_CLOSE, _bootstrap_query_widgets, lengthof(_bootstrap_query_widgets) ); diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index f445b0d62d..06be8a8530 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -494,7 +494,7 @@ static const NWidgetPart _nested_select_game_widgets[] = { static WindowDesc _select_game_desc( WDP_CENTER, nullptr, 0, 0, WC_SELECT_GAME, WC_NONE, - 0, + WDF_NO_CLOSE, _nested_select_game_widgets, lengthof(_nested_select_game_widgets) ); diff --git a/src/main_gui.cpp b/src/main_gui.cpp index b7757e87cb..5961b90fd2 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -510,7 +510,7 @@ struct MainWindow : Window static WindowDesc _main_window_desc( WDP_MANUAL, nullptr, 0, 0, WC_MAIN_WINDOW, WC_NONE, - 0, + WDF_NO_CLOSE, _nested_main_window_widgets, lengthof(_nested_main_window_widgets), &MainWindow::hotkeys ); diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 2efc9cb28e..9fa845a312 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -654,7 +654,7 @@ static const NWidgetPart _nested_tooltips_widgets[] = { static WindowDesc _tool_tips_desc( WDP_MANUAL, nullptr, 0, 0, // Coordinates and sizes are not used, WC_TOOLTIPS, WC_NONE, - WDF_NO_FOCUS, + WDF_NO_FOCUS | WDF_NO_CLOSE, _nested_tooltips_widgets, lengthof(_nested_tooltips_widgets) ); diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index ee505f7334..ce8acf86ef 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -230,7 +230,7 @@ static const NWidgetPart _nested_main_status_widgets[] = { static WindowDesc _main_status_desc( WDP_MANUAL, nullptr, 0, 0, WC_STATUS_BAR, WC_NONE, - WDF_NO_FOCUS, + WDF_NO_FOCUS | WDF_NO_CLOSE, _nested_main_status_widgets, lengthof(_nested_main_status_widgets) ); diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 168e110c8d..95a480790c 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -2251,7 +2251,7 @@ static const NWidgetPart _nested_toolbar_normal_widgets[] = { static WindowDesc _toolb_normal_desc( WDP_MANUAL, nullptr, 0, 0, WC_MAIN_TOOLBAR, WC_NONE, - WDF_NO_FOCUS, + WDF_NO_FOCUS | WDF_NO_CLOSE, _nested_toolbar_normal_widgets, lengthof(_nested_toolbar_normal_widgets), &MainToolbarWindow::hotkeys ); @@ -2591,7 +2591,7 @@ static const NWidgetPart _nested_toolb_scen_widgets[] = { static WindowDesc _toolb_scen_desc( WDP_MANUAL, nullptr, 0, 0, WC_MAIN_TOOLBAR, WC_NONE, - WDF_NO_FOCUS, + WDF_NO_FOCUS | WDF_NO_CLOSE, _nested_toolb_scen_widgets, lengthof(_nested_toolb_scen_widgets), &ScenarioEditorToolbarWindow::hotkeys ); diff --git a/src/window.cpp b/src/window.cpp index 5c31411468..4622411060 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -820,7 +820,7 @@ static void DispatchRightClickEvent(Window *w, int x, int y) } /* Right-click close is enabled and there is a closebox */ - if (_settings_client.gui.right_mouse_wnd_close && w->nested_root->GetWidgetOfType(WWT_CLOSEBOX)) { + if (_settings_client.gui.right_mouse_wnd_close && (w->window_desc->flags & WDF_NO_CLOSE) == 0) { w->Close(); } else if (_settings_client.gui.hover_delay_ms == 0 && !w->OnTooltip(pt, wid->index, TCC_RIGHT_CLICK) && wid->tool_tip != 0) { GuiShowTooltips(w, wid->tool_tip, 0, nullptr, TCC_RIGHT_CLICK); @@ -3293,11 +3293,7 @@ void CloseNonVitalWindows() { /* Note: the container remains stable, even when deleting windows. */ for (Window *w : Window::Iterate()) { - if (w->window_class != WC_MAIN_WINDOW && - w->window_class != WC_SELECT_GAME && - w->window_class != WC_MAIN_TOOLBAR && - w->window_class != WC_STATUS_BAR && - w->window_class != WC_TOOLTIPS && + if ((w->window_desc->flags & WDF_NO_CLOSE) == 0 && (w->flags & WF_STICKY) == 0) { // do not delete windows which are 'pinned' w->Close(); @@ -3314,12 +3310,9 @@ void CloseNonVitalWindows() */ void CloseAllNonVitalWindows() { - /* Close every window except for stickied ones, then sticky ones as well */ - CloseNonVitalWindows(); - /* Note: the container remains stable, even when closing windows. */ for (Window *w : Window::Iterate()) { - if (w->flags & WF_STICKY) { + if ((w->window_desc->flags & WDF_NO_CLOSE) == 0) { w->Close(); } } diff --git a/src/window_gui.h b/src/window_gui.h index b29912dbd2..8ed060b3c3 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -138,6 +138,7 @@ enum WindowDefaultFlag { WDF_CONSTRUCTION = 1 << 0, ///< This window is used for construction; close it whenever changing company. WDF_MODAL = 1 << 1, ///< The window is a modal child of some other window, meaning the parent is 'inactive' WDF_NO_FOCUS = 1 << 2, ///< This window won't get focus/make any other window lose focus when click + WDF_NO_CLOSE = 1 << 3, ///< This window can't be interactively closed }; /**