1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:48:13 +00:00

LibGUI: Let GWindow::set_main_widget() take ownership of the widget

We were already doing this anyway, with ~GWindow() calling delete on
the main widget.
This commit is contained in:
Andreas Kling 2019-08-18 12:17:09 +02:00
parent fc6bd52e0d
commit dc572e31fa

View file

@ -36,10 +36,7 @@ GWindow::GWindow(CObject* parent)
GWindow::~GWindow()
{
all_windows.remove(this);
if (m_main_widget)
delete m_main_widget;
hide();
if (all_windows.is_empty()) {
GApplication::the().did_delete_last_window({});
}
@ -465,8 +462,11 @@ void GWindow::set_main_widget(GWidget* widget)
{
if (m_main_widget == widget)
return;
if (m_main_widget)
remove_child(*m_main_widget);
m_main_widget = widget;
if (m_main_widget) {
add_child(*widget);
auto new_window_rect = rect();
if (m_main_widget->horizontal_size_policy() == SizePolicy::Fixed)
new_window_rect.set_width(m_main_widget->preferred_size().width());