1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

LibGUI: Convert GWidget to ObjectPtr

This commit is contained in:
Andreas Kling 2019-09-21 17:05:35 +02:00
parent e4e92980a1
commit ff6ce422dd
41 changed files with 115 additions and 107 deletions

View file

@ -55,7 +55,7 @@ VBPropertiesWindow::VBPropertiesWindow()
set_title("Properties");
set_rect(780, 200, 240, 280);
auto* widget = new GWidget;
auto widget = GWidget::construct();
widget->set_fill_with_background_color(true);
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
widget->layout()->set_margins({ 2, 2, 2, 2 });

View file

@ -30,7 +30,7 @@ VBWidget::~VBWidget()
{
m_form.m_gwidget_map.remove(m_gwidget);
m_form.m_selected_widgets.remove(this);
delete m_gwidget;
m_gwidget->parent()->remove_child(*m_gwidget);
}
Rect VBWidget::rect() const

View file

@ -8,10 +8,10 @@
#include <AK/RefCounted.h>
#include <AK/Weakable.h>
#include <LibDraw/Rect.h>
#include <LibGUI/GWidget.h>
class GPainter;
class GVariant;
class GWidget;
class VBForm;
class VBProperty;
class VBWidgetPropertyModel;
@ -81,7 +81,7 @@ private:
VBWidgetType m_type { VBWidgetType::None };
VBForm& m_form;
GWidget* m_gwidget { nullptr };
ObjectPtr<GWidget> m_gwidget;
NonnullOwnPtrVector<VBProperty> m_properties;
NonnullRefPtr<VBWidgetPropertyModel> m_property_model;
Rect m_transform_origin_rect;

View file

@ -68,11 +68,11 @@ VBWidgetType widget_type_from_class_name(const StringView& name)
ASSERT_NOT_REACHED();
}
static GWidget* build_gwidget(VBWidgetType type, GWidget* parent)
static ObjectPtr<GWidget> build_gwidget(VBWidgetType type, GWidget* parent)
{
switch (type) {
case VBWidgetType::GWidget:
return new GWidget(parent);
return GWidget::construct(parent);
case VBWidgetType::GScrollBar:
return GScrollBar::construct(Orientation::Vertical, parent);
case VBWidgetType::GGroupBox:
@ -113,21 +113,21 @@ static GWidget* build_gwidget(VBWidgetType type, GWidget* parent)
return slider;
}
case VBWidgetType::GCheckBox: {
auto* box = new GCheckBox(parent);
auto box = GCheckBox::construct(parent);
box->set_text("checkbox_1");
return box;
}
case VBWidgetType::GRadioButton:
return new GRadioButton("radio_1", parent);
return GRadioButton::construct("radio_1", parent);
default:
ASSERT_NOT_REACHED();
return nullptr;
}
}
GWidget* VBWidgetRegistry::build_gwidget(VBWidget& widget, VBWidgetType type, GWidget* parent, NonnullOwnPtrVector<VBProperty>& properties)
ObjectPtr<GWidget> VBWidgetRegistry::build_gwidget(VBWidget& widget, VBWidgetType type, GWidget* parent, NonnullOwnPtrVector<VBProperty>& properties)
{
auto* gwidget = ::build_gwidget(type, parent);
auto gwidget = ::build_gwidget(type, parent);
auto add_readonly_property = [&](const String& name, const GVariant& value) {
auto property = make<VBProperty>(widget, name, value);
property->set_readonly(true);

View file

@ -1,12 +1,12 @@
#pragma once
#include "VBWidgetType.h"
#include <AK/String.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/OwnPtr.h>
#include <AK/String.h>
#include <LibGUI/GWidget.h>
class GWidget;
class VBProperty;
class VBWidget;
@ -19,7 +19,7 @@ public:
callback((VBWidgetType)i);
}
static GWidget* build_gwidget(VBWidget&, VBWidgetType, GWidget* parent, NonnullOwnPtrVector<VBProperty>&);
static ObjectPtr<GWidget> build_gwidget(VBWidget&, VBWidgetType, GWidget* parent, NonnullOwnPtrVector<VBProperty>&);
};
String to_class_name(VBWidgetType);

View file

@ -80,7 +80,7 @@ GWindow* make_toolbox_window()
window->set_title("Widgets");
window->set_rect(20, 200, 80, 300);
auto* widget = new GWidget;
auto widget = GWidget::construct();
widget->set_fill_with_background_color(true);
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
widget->layout()->set_spacing(0);