mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:08:12 +00:00
LibGUI: Add a ThemeChange event
This commit is contained in:
parent
2b162ef794
commit
2a32330257
8 changed files with 53 additions and 1 deletions
|
@ -28,9 +28,9 @@
|
||||||
|
|
||||||
#include <Kernel/KeyCode.h>
|
#include <Kernel/KeyCode.h>
|
||||||
#include <LibCore/Event.h>
|
#include <LibCore/Event.h>
|
||||||
|
#include <LibGUI/WindowType.h>
|
||||||
#include <LibGfx/Point.h>
|
#include <LibGfx/Point.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <LibGUI/WindowType.h>
|
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ public:
|
||||||
EnabledChange,
|
EnabledChange,
|
||||||
DragMove,
|
DragMove,
|
||||||
Drop,
|
Drop,
|
||||||
|
ThemeChange,
|
||||||
|
|
||||||
__Begin_WM_Events,
|
__Begin_WM_Events,
|
||||||
WM_WindowRemoved,
|
WM_WindowRemoved,
|
||||||
|
@ -340,4 +341,12 @@ private:
|
||||||
NonnullRefPtr<Core::MimeData> m_mime_data;
|
NonnullRefPtr<Core::MimeData> m_mime_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ThemeChangeEvent final : public Event {
|
||||||
|
public:
|
||||||
|
ThemeChangeEvent()
|
||||||
|
: Event(Type::ThemeChange)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1279,6 +1279,13 @@ void TextEditor::resize_event(ResizeEvent& event)
|
||||||
recompute_all_visual_lines();
|
recompute_all_visual_lines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditor::theme_change_event(ThemeChangeEvent& event)
|
||||||
|
{
|
||||||
|
ScrollableWidget::theme_change_event(event);
|
||||||
|
if (m_highlighter)
|
||||||
|
m_highlighter->rehighlight(palette());
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditor::set_selection(const TextRange& selection)
|
void TextEditor::set_selection(const TextRange& selection)
|
||||||
{
|
{
|
||||||
if (m_selection == selection)
|
if (m_selection == selection)
|
||||||
|
|
|
@ -148,6 +148,7 @@ protected:
|
||||||
virtual void leave_event(Core::Event&) override;
|
virtual void leave_event(Core::Event&) override;
|
||||||
virtual void context_menu_event(ContextMenuEvent&) override;
|
virtual void context_menu_event(ContextMenuEvent&) override;
|
||||||
virtual void resize_event(ResizeEvent&) override;
|
virtual void resize_event(ResizeEvent&) override;
|
||||||
|
virtual void theme_change_event(ThemeChangeEvent&) override;
|
||||||
virtual void cursor_did_change() {}
|
virtual void cursor_did_change() {}
|
||||||
|
|
||||||
TextPosition text_position_at(const Gfx::Point&) const;
|
TextPosition text_position_at(const Gfx::Point&) const;
|
||||||
|
|
|
@ -206,6 +206,8 @@ void Widget::event(Core::Event& event)
|
||||||
return drag_move_event(static_cast<DragEvent&>(event));
|
return drag_move_event(static_cast<DragEvent&>(event));
|
||||||
case Event::Drop:
|
case Event::Drop:
|
||||||
return drop_event(static_cast<DropEvent&>(event));
|
return drop_event(static_cast<DropEvent&>(event));
|
||||||
|
case Event::ThemeChange:
|
||||||
|
return theme_change_event(static_cast<ThemeChangeEvent&>(event));
|
||||||
case Event::Enter:
|
case Event::Enter:
|
||||||
return handle_enter_event(event);
|
return handle_enter_event(event);
|
||||||
case Event::Leave:
|
case Event::Leave:
|
||||||
|
@ -417,6 +419,10 @@ void Widget::drop_event(DropEvent& event)
|
||||||
event.ignore();
|
event.ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::theme_change_event(ThemeChangeEvent&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::update()
|
void Widget::update()
|
||||||
{
|
{
|
||||||
if (rect().is_empty())
|
if (rect().is_empty())
|
||||||
|
|
|
@ -292,6 +292,7 @@ protected:
|
||||||
virtual void change_event(Event&);
|
virtual void change_event(Event&);
|
||||||
virtual void drag_move_event(DragEvent&);
|
virtual void drag_move_event(DragEvent&);
|
||||||
virtual void drop_event(DropEvent&);
|
virtual void drop_event(DropEvent&);
|
||||||
|
virtual void theme_change_event(ThemeChangeEvent&);
|
||||||
|
|
||||||
virtual void did_begin_inspection() override;
|
virtual void did_begin_inspection() override;
|
||||||
virtual void did_end_inspection() override;
|
virtual void did_end_inspection() override;
|
||||||
|
|
|
@ -334,6 +334,22 @@ void Window::event(Core::Event& event)
|
||||||
return result.widget->dispatch_event(*local_event, this);
|
return result.widget->dispatch_event(*local_event, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.type() == Event::ThemeChange) {
|
||||||
|
if (!m_main_widget)
|
||||||
|
return;
|
||||||
|
auto theme_event = static_cast<ThemeChangeEvent&>(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);
|
Core::Object::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,6 +651,14 @@ void Window::schedule_relayout()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::for_each_window(Badge<WindowServerConnection>, Function<void(Window&)> callback)
|
||||||
|
{
|
||||||
|
for (auto& e : *reified_windows) {
|
||||||
|
ASSERT(e.value);
|
||||||
|
callback(*e.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Window::update_all_windows(Badge<WindowServerConnection>)
|
void Window::update_all_windows(Badge<WindowServerConnection>)
|
||||||
{
|
{
|
||||||
for (auto& e : *reified_windows) {
|
for (auto& e : *reified_windows) {
|
||||||
|
|
|
@ -172,6 +172,7 @@ public:
|
||||||
|
|
||||||
void schedule_relayout();
|
void schedule_relayout();
|
||||||
|
|
||||||
|
static void for_each_window(Badge<WindowServerConnection>, Function<void(Window&)>);
|
||||||
static void update_all_windows(Badge<WindowServerConnection>);
|
static void update_all_windows(Badge<WindowServerConnection>);
|
||||||
void notify_state_changed(Badge<WindowServerConnection>, bool minimized, bool occluded);
|
void notify_state_changed(Badge<WindowServerConnection>, bool minimized, bool occluded);
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,9 @@ void WindowServerConnection::handle(const Messages::WindowClient::UpdateSystemTh
|
||||||
{
|
{
|
||||||
set_system_theme_from_shbuf_id(message.system_theme_buffer_id());
|
set_system_theme_from_shbuf_id(message.system_theme_buffer_id());
|
||||||
Window::update_all_windows({});
|
Window::update_all_windows({});
|
||||||
|
Window::for_each_window({}, [](auto& window) {
|
||||||
|
Core::EventLoop::current().post_event(window, make<ThemeChangeEvent>());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowServerConnection::handle(const Messages::WindowClient::Paint& message)
|
void WindowServerConnection::handle(const Messages::WindowClient::Paint& message)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue