diff --git a/LibGUI/GAbstractButton.cpp b/LibGUI/GAbstractButton.cpp index d9f2b21c601..03f95e0e1dc 100644 --- a/LibGUI/GAbstractButton.cpp +++ b/LibGUI/GAbstractButton.cpp @@ -124,3 +124,16 @@ void GAbstractButton::paint_text(GPainter& painter, const Rect& rect, const Font if (is_focused()) painter.draw_rect(clipped_rect.inflated(6, 4), Color(140, 140, 140)); } + +void GAbstractButton::change_event(GEvent& event) +{ + if (event.type() == GEvent::Type::EnabledChange) { + if (!is_enabled()) { + bool was_being_pressed = m_being_pressed; + m_being_pressed = false; + if (was_being_pressed) + update(); + } + } + GWidget::change_event(event); +} diff --git a/LibGUI/GAbstractButton.h b/LibGUI/GAbstractButton.h index 75627e5e0e9..fdbb6a7a8c0 100644 --- a/LibGUI/GAbstractButton.h +++ b/LibGUI/GAbstractButton.h @@ -37,6 +37,7 @@ protected: virtual void keydown_event(GKeyEvent&) override; virtual void enter_event(CEvent&) override; virtual void leave_event(CEvent&) override; + virtual void change_event(GEvent&) override; void paint_text(GPainter&, const Rect&, const Font&, TextAlignment); diff --git a/LibGUI/GEvent.h b/LibGUI/GEvent.h index 9a308f10721..bdb4c0e5d5a 100644 --- a/LibGUI/GEvent.h +++ b/LibGUI/GEvent.h @@ -33,6 +33,7 @@ public: FocusOut, WindowCloseRequest, ContextMenu, + EnabledChange, __Begin_WM_Events, WM_WindowRemoved, diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp index acad0ecdb9f..bc932dd2421 100644 --- a/LibGUI/GScrollBar.cpp +++ b/LibGUI/GScrollBar.cpp @@ -300,3 +300,12 @@ void GScrollBar::leave_event(CEvent&) update(); } } + +void GScrollBar::change_event(GEvent& event) +{ + if (event.type() == GEvent::Type::EnabledChange) { + if (!is_enabled()) + m_scrubbing = false; + } + return GWidget::change_event(event); +} diff --git a/LibGUI/GScrollBar.h b/LibGUI/GScrollBar.h index 659a2b09d28..cfc9fbc7a28 100644 --- a/LibGUI/GScrollBar.h +++ b/LibGUI/GScrollBar.h @@ -42,6 +42,7 @@ private: virtual void mouseup_event(GMouseEvent&) override; virtual void mousemove_event(GMouseEvent&) override; virtual void leave_event(CEvent&) override; + virtual void change_event(GEvent&) override; int button_size() const { return 16; } int button_width() const { return orientation() == Orientation::Vertical ? width() : button_size(); } diff --git a/LibGUI/GSlider.cpp b/LibGUI/GSlider.cpp index 28591c29427..ca532bf4568 100644 --- a/LibGUI/GSlider.cpp +++ b/LibGUI/GSlider.cpp @@ -120,6 +120,15 @@ void GSlider::leave_event(CEvent& event) GWidget::leave_event(event); } +void GSlider::change_event(GEvent& event) +{ + if (event.type() == GEvent::Type::EnabledChange) { + if (!is_enabled())) + m_dragging = false; + } + GWidget::change_event(event); +} + void GSlider::set_knob_hovered(bool hovered) { if (m_knob_hovered == hovered) diff --git a/LibGUI/GSlider.h b/LibGUI/GSlider.h index ed93910cd52..fb0582d49ea 100644 --- a/LibGUI/GSlider.h +++ b/LibGUI/GSlider.h @@ -32,6 +32,7 @@ protected: virtual void mousemove_event(GMouseEvent&) override; virtual void mouseup_event(GMouseEvent&) override; virtual void leave_event(CEvent&) override; + virtual void change_event(GEvent&) override; private: void set_knob_hovered(bool); diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp index 55e31b7adf9..506108ca028 100644 --- a/LibGUI/GWidget.cpp +++ b/LibGUI/GWidget.cpp @@ -94,6 +94,8 @@ void GWidget::event(CEvent& event) return handle_enter_event(event); case GEvent::Leave: return handle_leave_event(event); + case GEvent::EnabledChange: + return change_event(static_cast(event)); default: return CObject::event(event); } @@ -271,6 +273,10 @@ void GWidget::leave_event(CEvent&) { } +void GWidget::change_event(GEvent&) +{ +} + void GWidget::update() { if (rect().is_empty()) @@ -454,6 +460,8 @@ void GWidget::set_enabled(bool enabled) if (m_enabled == enabled) return; m_enabled = enabled; + GEvent e(GEvent::EnabledChange); + event(e); update(); } diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h index 1d61cf28dfa..781e91a0793 100644 --- a/LibGUI/GWidget.h +++ b/LibGUI/GWidget.h @@ -67,6 +67,7 @@ public: virtual void enter_event(CEvent&); virtual void leave_event(CEvent&); virtual void child_event(CChildEvent&) override; + virtual void change_event(GEvent&); // This is called after children have been painted. virtual void second_paint_event(GPaintEvent&);