From 2a32330257b96922d9ed274baf6fc96abca957f0 Mon Sep 17 00:00:00 2001 From: Oriko Date: Mon, 16 Mar 2020 13:36:21 +0200 Subject: LibGUI: Add a ThemeChange event --- Libraries/LibGUI/Window.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'Libraries/LibGUI/Window.cpp') diff --git a/Libraries/LibGUI/Window.cpp b/Libraries/LibGUI/Window.cpp index 60c583802b..9cb37b02c5 100644 --- a/Libraries/LibGUI/Window.cpp +++ b/Libraries/LibGUI/Window.cpp @@ -334,6 +334,22 @@ void Window::event(Core::Event& event) return result.widget->dispatch_event(*local_event, this); } + if (event.type() == Event::ThemeChange) { + if (!m_main_widget) + return; + auto theme_event = static_cast(event); + auto dispatch_theme_change = [&](auto& widget, auto recursive) { + widget.dispatch_event(theme_event, this); + widget.for_each_child_widget([&](auto& widget) -> IterationDecision { + widget.dispatch_event(theme_event, this); + recursive(widget, recursive); + return IterationDecision::Continue; + }); + }; + dispatch_theme_change(*m_main_widget.ptr(), dispatch_theme_change); + return; + } + Core::Object::event(event); } @@ -635,6 +651,14 @@ void Window::schedule_relayout() }); } +void Window::for_each_window(Badge, Function callback) +{ + for (auto& e : *reified_windows) { + ASSERT(e.value); + callback(*e.value); + } +} + void Window::update_all_windows(Badge) { for (auto& e : *reified_windows) { -- cgit v1.2.3