LibGUI: Add FontsChanged event and deliver it to windows and widgets

This commit is contained in:
LuK1337 2021-07-12 09:57:34 +02:00 committed by Andreas Kling
parent 9318d9f284
commit b40d771512
Notes: sideshowbarker 2024-07-18 09:12:36 +09:00
7 changed files with 39 additions and 0 deletions

View file

@ -52,6 +52,7 @@ public:
DragMove,
Drop,
ThemeChange,
FontsChange,
ScreenRectsChange,
ActionEnter,
ActionLeave,
@ -425,6 +426,14 @@ public:
}
};
class FontsChangeEvent final : public Event {
public:
FontsChangeEvent()
: Event(Type::FontsChange)
{
}
};
class ScreenRectsChangeEvent final : public Event {
public:
explicit ScreenRectsChangeEvent(const Vector<Gfx::IntRect, 4>& rects, size_t main_screen_index)

View file

@ -70,6 +70,7 @@ struct TextDocumentSpan;
class TextDocumentUndoCommand;
class TextEditor;
class ThemeChangeEvent;
class FontsChangeEvent;
class Toolbar;
class ToolbarContainer;
class TreeView;

View file

@ -295,6 +295,8 @@ void Widget::event(Core::Event& event)
return drop_event(static_cast<DropEvent&>(event));
case Event::ThemeChange:
return theme_change_event(static_cast<ThemeChangeEvent&>(event));
case Event::FontsChange:
return fonts_change_event(static_cast<FontsChangeEvent&>(event));
case Event::Enter:
return handle_enter_event(event);
case Event::Leave:
@ -558,6 +560,10 @@ void Widget::theme_change_event(ThemeChangeEvent&)
{
}
void Widget::fonts_change_event(FontsChangeEvent&)
{
}
void Widget::screen_rects_change_event(ScreenRectsChangeEvent&)
{
}

View file

@ -314,6 +314,7 @@ protected:
virtual void drag_leave_event(Event&);
virtual void drop_event(DropEvent&);
virtual void theme_change_event(ThemeChangeEvent&);
virtual void fonts_change_event(FontsChangeEvent&);
virtual void screen_rects_change_event(ScreenRectsChangeEvent&);
virtual void did_begin_inspection() override;

View file

@ -511,6 +511,21 @@ void Window::handle_theme_change_event(ThemeChangeEvent& event)
dispatch_theme_change(*m_main_widget.ptr(), dispatch_theme_change);
}
void Window::handle_fonts_change_event(FontsChangeEvent& event)
{
if (!m_main_widget)
return;
auto dispatch_fonts_change = [&](auto& widget, auto recursive) {
widget.dispatch_event(event, this);
widget.for_each_child_widget([&](auto& widget) -> IterationDecision {
widget.dispatch_event(event, this);
recursive(widget, recursive);
return IterationDecision::Continue;
});
};
dispatch_fonts_change(*m_main_widget.ptr(), dispatch_fonts_change);
}
void Window::handle_screen_rects_change_event(ScreenRectsChangeEvent& event)
{
if (!m_main_widget)
@ -594,6 +609,9 @@ void Window::event(Core::Event& event)
if (event.type() == Event::ThemeChange)
return handle_theme_change_event(static_cast<ThemeChangeEvent&>(event));
if (event.type() == Event::FontsChange)
return handle_fonts_change_event(static_cast<FontsChangeEvent&>(event));
if (event.type() == Event::ScreenRectsChange)
return handle_screen_rects_change_event(static_cast<ScreenRectsChangeEvent&>(event));

View file

@ -220,6 +220,7 @@ private:
void handle_became_active_or_inactive_event(Core::Event&);
void handle_close_request();
void handle_theme_change_event(ThemeChangeEvent&);
void handle_fonts_change_event(FontsChangeEvent&);
void handle_screen_rects_change_event(ScreenRectsChangeEvent&);
void handle_drag_move_event(DragEvent&);
void handle_left_event();

View file

@ -72,6 +72,9 @@ void WindowServerConnection::update_system_fonts(const String& default_font_quer
Gfx::FontDatabase::set_default_font_query(default_font_query);
Gfx::FontDatabase::set_fixed_width_font_query(fixed_width_font_query);
Window::update_all_windows({});
Window::for_each_window({}, [](auto& window) {
Core::EventLoop::current().post_event(window, make<FontsChangeEvent>());
});
}
void WindowServerConnection::paint(i32 window_id, Gfx::IntSize const& window_size, Vector<Gfx::IntRect> const& rects)