From 6d5507313e6449ae1081ec7812c07a9c0fa708f5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 2 May 2019 03:46:37 +0200 Subject: [PATCH] GWidget: Add set_updates_enabled() for temporarily suppressing updates. --- LibGUI/GWidget.cpp | 26 ++++++++++++++++++++++---- LibGUI/GWidget.h | 4 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp index 4b4cc35a52..fedecc8b74 100644 --- a/LibGUI/GWidget.cpp +++ b/LibGUI/GWidget.cpp @@ -283,6 +283,8 @@ void GWidget::leave_event(CEvent&) void GWidget::update() { + if (rect().is_empty()) + return; update(rect()); } @@ -290,10 +292,17 @@ void GWidget::update(const Rect& rect) { if (!is_visible()) return; - auto* w = window(); - if (!w) - return; - w->update(rect.translated(window_relative_rect().location())); + + GWindow* window = m_window; + GWidget* parent = parent_widget(); + while (parent) { + if (!parent->updates_enabled()) + return; + window = parent->m_window; + parent = parent->parent_widget(); + } + if (window) + window->update(rect.translated(window_relative_rect().location())); } Rect GWidget::window_relative_rect() const @@ -516,3 +525,12 @@ void GWidget::unregister_local_shortcut_action(Badge, GAction& action) { m_local_shortcut_actions.remove(action.shortcut()); } + +void GWidget::set_updates_enabled(bool enabled) +{ + if (m_updates_enabled == enabled) + return; + m_updates_enabled = enabled; + if (enabled) + update(); +} diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h index 1cb7104fa1..9be5d9b02e 100644 --- a/LibGUI/GWidget.h +++ b/LibGUI/GWidget.h @@ -45,6 +45,9 @@ public: bool is_enabled() const { return m_enabled; } void set_enabled(bool); + bool updates_enabled() const { return m_updates_enabled; } + void set_updates_enabled(bool); + virtual void event(CEvent&) override; virtual void paint_event(GPaintEvent&); virtual void resize_event(GResizeEvent&); @@ -211,6 +214,7 @@ private: bool m_greedy_for_hits { false }; bool m_enabled { true }; bool m_layout_dirty { false }; + bool m_updates_enabled { true }; CElapsedTimer m_left_click_clock; CElapsedTimer m_right_click_clock;