diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-15 01:27:37 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-15 01:27:37 +0100 |
commit | 10ccc9e11c10a9e0d0250613110340f1b11300ab (patch) | |
tree | e6a960f5ce3e37386d36579737149f4928489b9f /Libraries/LibGUI | |
parent | dcb0766d3fdfd68bfe9c18638fa3fb4e7f90ffa4 (diff) | |
download | serenity-10ccc9e11c10a9e0d0250613110340f1b11300ab.zip |
LibGUI: Don't leak every tooltip window ever :^)
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/Application.cpp | 21 | ||||
-rw-r--r-- | Libraries/LibGUI/Application.h | 2 |
2 files changed, 13 insertions, 10 deletions
diff --git a/Libraries/LibGUI/Application.cpp b/Libraries/LibGUI/Application.cpp index 49dacb513a..3f1ef5c5cb 100644 --- a/Libraries/LibGUI/Application.cpp +++ b/Libraries/LibGUI/Application.cpp @@ -106,7 +106,18 @@ Action* Application::action_for_key_event(const KeyEvent& event) } class Application::TooltipWindow final : public Window { + C_OBJECT(TooltipWindow); + public: + void set_tooltip(const StringView& tooltip) + { + // FIXME: Add some kind of GLabel auto-sizing feature. + int text_width = m_label->font().width(tooltip); + set_rect(100, 100, text_width + 10, m_label->font().glyph_height() + 8); + m_label->set_text(tooltip); + } + +private: TooltipWindow() { set_window_type(WindowType::Tooltip); @@ -119,21 +130,13 @@ public: set_main_widget(m_label); } - void set_tooltip(const StringView& tooltip) - { - // FIXME: Add some kind of GLabel auto-sizing feature. - int text_width = m_label->font().width(tooltip); - set_rect(100, 100, text_width + 10, m_label->font().glyph_height() + 8); - m_label->set_text(tooltip); - } - RefPtr<Label> m_label; }; void Application::show_tooltip(const StringView& tooltip, const Gfx::Point& screen_location) { if (!m_tooltip_window) { - m_tooltip_window = new TooltipWindow; + m_tooltip_window = TooltipWindow::construct(); m_tooltip_window->set_double_buffering_enabled(false); } m_tooltip_window->set_tooltip(tooltip); diff --git a/Libraries/LibGUI/Application.h b/Libraries/LibGUI/Application.h index b2f7c0de86..f19a3dc551 100644 --- a/Libraries/LibGUI/Application.h +++ b/Libraries/LibGUI/Application.h @@ -77,7 +77,7 @@ private: RefPtr<Gfx::PaletteImpl> m_system_palette; HashMap<Shortcut, Action*> m_global_shortcut_actions; class TooltipWindow; - TooltipWindow* m_tooltip_window { nullptr }; + RefPtr<TooltipWindow> m_tooltip_window; bool m_quit_when_last_window_deleted { true }; String m_invoked_as; Vector<String> m_args; |