From dabf2ede67916c02f8cfa2760d5ad7af522051e1 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 4 May 2025 17:48:33 +0100 Subject: [PATCH] Change: Add methods to close child windows with a specific window number. --- src/window.cpp | 35 ++++++++++++++++++++++++++++++++--- src/window_gui.h | 2 ++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index 3386cc1d42..651bbfde9d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1024,9 +1024,8 @@ void Window::SetShaded(bool make_shaded) /** * Find the Window whose parent pointer points to this window - * @param w parent Window to find child of - * @param wc Window class of the window to remove; #WC_INVALID if class does not matter - * @return a Window pointer that is the child of \a w, or \c nullptr otherwise + * @param wc Window class of the window to find; #WC_INVALID if class does not matter + * @return a Window pointer that is the child of this window, or \c nullptr otherwise */ Window *Window::FindChildWindow(WindowClass wc) const { @@ -1037,6 +1036,21 @@ Window *Window::FindChildWindow(WindowClass wc) const return nullptr; } +/** + * Find the Window whose parent pointer points to this window + * @param wc Window class of the window to find. + * @param number Window number of the window to find. + * @return a Window pointer that is the child of this window, or \c nullptr otherwise + */ +Window *Window::FindChildWindowById(WindowClass wc, WindowNumber number) const +{ + for (Window *v : Window::Iterate()) { + if (wc == v->window_class && number == v->window_number && v->parent == this) return v; + } + + return nullptr; +} + /** * Close all children a window might have in a head-recursive manner * @param wc Window class of the window to remove; #WC_INVALID if class does not matter @@ -1050,6 +1064,21 @@ void Window::CloseChildWindows(WindowClass wc) const } } + +/** + * Close all children a window might have in a head-recursive manner + * @param wc Window class of the window to remove. + * @param number Window number of the window to remove. + */ +void Window::CloseChildWindowById(WindowClass wc, WindowNumber number) const +{ + Window *child = this->FindChildWindowById(wc, number); + while (child != nullptr) { + child->Close(); + child = this->FindChildWindowById(wc, number); + } +} + /** * Hide the window and all its child windows, and mark them for a later deletion. */ diff --git a/src/window_gui.h b/src/window_gui.h index 41fa29f5db..4e42450777 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -546,7 +546,9 @@ public: static int SortButtonWidth(); Window *FindChildWindow(WindowClass wc = WC_INVALID) const; + Window *FindChildWindowById(WindowClass wc, WindowNumber number) const; void CloseChildWindows(WindowClass wc = WC_INVALID) const; + void CloseChildWindowById(WindowClass wc, WindowNumber number) const; virtual void Close(int data = 0); static void DeleteClosedWindows();